diff --git a/Docs/Bindings.md b/Docs/Bindings.md index 81f4663..0fb6867 100644 --- a/Docs/Bindings.md +++ b/Docs/Bindings.md @@ -1,6 +1,8 @@ # Language Bindings [Language bindings](https://en.wikipedia.org/wiki/Language_binding) refers to wrappers to bridge 2 programming languages. This is used in P2PRC to extend calling P2PRC functions in other programming languages. Currently this is done by generating ```.so``` and ```.h``` from the Go compiler. +
+ ## How to build shared object files The easier way ```bash @@ -21,6 +23,7 @@ ls # Find files p2prc.h p2prc.so ``` +
## Workings under the hood Below are a sample set of commands to @@ -67,6 +70,15 @@ it is pretty trivial to notice a common structure). ```go // --------- Example ------------ +//export StartContainer +func StartContainer(IP string) (output *C.char) { + container, err := client.StartContainer(IP, 0, false, "", "") + if err != nil { + return C.CString(err.Error()) + } + return ConvertStructToJSONString(container) +} + //export ViewPlugin func ViewPlugin() (output *C.char) { plugins, err := plugin.DetectPlugins() @@ -76,17 +88,25 @@ func ViewPlugin() (output *C.char) { return ConvertStructToJSONString(plugins) } -//export PullPlugin -func PullPlugin(pluginUrl string) (output *C.char) { - err := plugin.DownloadPlugin(pluginUrl) - if err != nil { - return C.CString(err.Error()) - } - return C.CString("Success") +``` +It is easy to notice that: +- ```ConvertStructToJSONString()```: This is a helper function that convert + a go object to JSON string initially and converts it to ```CString```. +- ```(output *C.char)```: This is the return type for most of the functions. + +#### A Pseudo code to refer to the common function implementation shape could be represented as: +``` +func (output *C.char) { + , := () + if != nil { + return C.CString(.Error()) + } + return ConvertStructToJSONString() } ``` +
## Current languages supported