Update Bindings.md
This commit is contained in:
committed by
GitHub
parent
1c496d8be1
commit
ea08b5c3ea
@@ -4,17 +4,17 @@
|
|||||||
<br>
|
<br>
|
||||||
|
|
||||||
## How to build shared object files
|
## How to build shared object files
|
||||||
The easier way
|
#### The easier way
|
||||||
```bash
|
```bash
|
||||||
# Run
|
# Run
|
||||||
make sharedObjects
|
make sharedObjects
|
||||||
```
|
```
|
||||||
Or the direct way
|
#### Or the direct way
|
||||||
```bash
|
```bash
|
||||||
# Run
|
# Run
|
||||||
cd Bindings && go build -buildmode=c-shared -o p2prc.so
|
cd Bindings && go build -buildmode=c-shared -o p2prc.so
|
||||||
```
|
```
|
||||||
If successfully built:
|
#### If successfully built:
|
||||||
```bash
|
```bash
|
||||||
# Enter into the Bindings directory
|
# Enter into the Bindings directory
|
||||||
cd Bindings
|
cd Bindings
|
||||||
@@ -40,12 +40,11 @@ Client.go
|
|||||||
There a few things to notice which are different from
|
There a few things to notice which are different from
|
||||||
your standard Go programs:
|
your standard Go programs:
|
||||||
|
|
||||||
1. We import "C" which means [Cgo](https://pkg.go.dev/cmd/cgo) is required.
|
#### 1. We import "C" which means [Cgo](https://pkg.go.dev/cmd/cgo) is required.
|
||||||
```go
|
```go
|
||||||
import "C"
|
import "C"
|
||||||
```
|
```
|
||||||
2. All functions which are required to be called from other programming languages
|
#### 2. All functions which are required to be called from other programming languages have comment such as.
|
||||||
have comment such as.
|
|
||||||
```go
|
```go
|
||||||
//export <function name>
|
//export <function name>
|
||||||
|
|
||||||
@@ -65,8 +64,7 @@ func StartContainer(IP string) (output *C.char) {
|
|||||||
return ConvertStructToJSONString(container)
|
return ConvertStructToJSONString(container)
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
3. While looking through the file (If 2 files are compared
|
#### 3. While looking through the file (If 2 files are compared it is pretty trivial to notice a common structure).
|
||||||
it is pretty trivial to notice a common structure).
|
|
||||||
```go
|
```go
|
||||||
// --------- Example ------------
|
// --------- Example ------------
|
||||||
|
|
||||||
@@ -89,7 +87,7 @@ func ViewPlugin() (output *C.char) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
It is easy to notice that:
|
#### It is easy to notice that:
|
||||||
- ```ConvertStructToJSONString(<go object>)```: This is a helper function that convert
|
- ```ConvertStructToJSONString(<go object>)```: This is a helper function that convert
|
||||||
a go object to JSON string initially and converts it to ```CString```.
|
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.
|
- ```(output *C.char)```: This is the return type for most of the functions.
|
||||||
|
|||||||
Reference in New Issue
Block a user