Skip to content

Commit c652e46

Browse files
author
g.ph
committed
update
1 parent cb6f540 commit c652e46

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

README.MD

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,21 @@ go get github.com/aadog/py3-go
1111
### test
1212

1313
```
14-
type K struct {
15-
Doc string
16-
}
1714
18-
func (v *K) Test(self *PyObject, args *PyObject) *PyObject {
19-
fmt.Println("test")
20-
return nil
21-
}
2215
func main(){
2316
PyImport_AppendInittab("_test", func() *PyObject {
24-
return RegPyModule("_test", &K{})
17+
m := CreateModule("_test", "aa")
18+
m.AddFunction("add", func(a, b int) int {
19+
return a + b
20+
})
21+
return m.AsObj()
2522
})
2623
cpy3.Py_SetProgramName(os.Args[0])
2724
cpy3.Py_SetPythonHome("./")
2825
cpy3.Py_Initialize()
2926
cpy3.PyRun_SimpleString(`
30-
import _test
31-
print(_test.Call('Test'))
27+
import _test
28+
print(_test.Call('add',1,2))
3229
`)
3330
}
3431
```

module_test.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,21 @@ func (v *K) Test(self *PyObject, args *PyObject) *PyObject {
1515
fmt.Println("test")
1616
return nil
1717
}
18+
1819
func TestRegModule(t *testing.T) {
1920
PyImport_AppendInittab("_test", func() *PyObject {
20-
return CreateModule("_test", "aa").AsObj()
21+
m := CreateModule("_test", "aa")
22+
m.AddFunction("add", func(a, b int) int {
23+
return a + b
24+
})
25+
return m.AsObj()
2126
})
2227
cpy3.Py_SetProgramName(os.Args[0])
2328
cpy3.Py_SetPythonHome("./")
2429
cpy3.Py_Initialize()
2530
cpy3.PyRun_SimpleString(`
2631
print("aaa")
2732
#import _test
28-
#print(_test.Call('Test'))
33+
#print(_test.Call('add',1,2))
2934
`)
3035
}

0 commit comments

Comments
 (0)