Skip to content

Commit e017c73

Browse files
committed
update docs
1 parent dcbd3af commit e017c73

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

README.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ xcode-select --install
4646
```
4747
</details>
4848

49-
## Quick Start
49+
## Python calling Go
5050

51-
### 1. Write Go Code
51+
### 1. Export Go Functions/Types
5252

5353
Create a `lib.go` file:
5454

@@ -130,25 +130,22 @@ Run the python script:
130130
python main.py
131131
```
132132

133-
## Go Call Python
133+
## Go calling Python
134134

135-
### 1. Define Python Functions/Classes
135+
### 1. Export Python Functions/Classes
136136

137137
```python
138138
# main.py
139139
import gopylink
140140

141-
142141
@gopylink.export
143142
def greet(name: str) -> str:
144143
return f"Hi, {name}!"
145144

146-
147145
@gopylink.export
148146
def multiply(a, b):
149147
return a * b
150148

151-
152149
@gopylink.export
153150
class Counter:
154151
def __init__(self, initial=0):
@@ -158,9 +155,9 @@ class Counter:
158155
self.value += n
159156
return self.value
160157

161-
162-
lib = gopylink.load_go_lib("go.lib")
163-
lib.func_call("Start") # Start the Go logic
158+
if __name__ == "__main__":
159+
lib = gopylink.load_go_lib("go.lib")
160+
lib.func_call("Start") # Start the Go logic
164161
```
165162

166163
### 2. Call Python from Go
@@ -209,6 +206,8 @@ go build -buildmode=c-shared -o go.lib .
209206
python main.py
210207
```
211208

209+
Note that when calling Python from Go, the entry point remains the Python script. The Go shared library is loaded into the Python process, which then starts the Go logic.
210+
212211
## API Reference
213212

214213
### Python API
@@ -232,6 +231,8 @@ python main.py
232231
| `handle.MethodCall(name, args...)` | Call method on Python instance |
233232
| `handle.Close()` | Release Python instance |
234233

234+
See [Go API Reference](https://pkg.go.dev/github.com/ray4go/gopylink#pkg-index) for more details.
235+
235236
## Type Conversion
236237

237238
Types are automatically converted via msgpack:

go.mod

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ module github.com/ray4go/gopylink
22

33
go 1.21
44

5-
replace github.com/ray4go/go-ray/ray => ../go-ray/ray
6-
75
require github.com/ray4go/go-ray/ray v1.2.0
86

97
require (

0 commit comments

Comments
 (0)