File tree Expand file tree Collapse file tree 2 files changed +14
-12
lines changed Expand file tree Collapse file tree 2 files changed +14
-12
lines changed Original file line number Diff line number Diff 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- }
2215func 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```
Original file line number Diff line number Diff line change @@ -15,16 +15,21 @@ func (v *K) Test(self *PyObject, args *PyObject) *PyObject {
1515 fmt .Println ("test" )
1616 return nil
1717}
18+
1819func 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 (`
2631print("aaa")
2732#import _test
28- #print(_test.Call('Test' ))
33+ #print(_test.Call('add',1,2 ))
2934` )
3035}
You can’t perform that action at this time.
0 commit comments