File tree Expand file tree Collapse file tree 2 files changed +39
-19
lines changed Expand file tree Collapse file tree 2 files changed +39
-19
lines changed Original file line number Diff line number Diff line change 55
66```
77go get github.com/aadog/py3-go
8+ ```
9+
10+
11+ ### test
12+
13+ ```
14+ type K struct {
15+ Doc string
16+ }
17+
18+ func (v *K) Test(self *PyObject, args *PyObject) *PyObject {
19+ fmt.Println("test")
20+ return nil
21+ }
22+ func main(){
23+ PyImport_AppendInittab("_test", func() *PyObject {
24+ return RegPyModule("_test", &K{})
25+ })
26+ cpy3.Py_SetProgramName(os.Args[0])
27+ cpy3.Py_SetPythonHome("./")
28+ cpy3.Py_Initialize()
29+ cpy3.PyRun_SimpleString(`
30+ import _test
31+ print(_test.Call('Test'))
32+ `)
33+ }
834```
Original file line number Diff line number Diff line change @@ -2,35 +2,29 @@ package py3
22
33import (
44 "fmt"
5+ "github.com/aadog/py3-go/cpy3"
6+ "os"
57 "testing"
68)
79
8- func TestCreateModule (t * testing.T ) {
9-
10- // moduleName := "test"
11- // Import_AppendInittab(moduleName, func() *PyObject {
12- // def := NewModuleDef(moduleName, "")
13- // def.AddMethodDef(NewMethodDef("aa", func() {
14- // fmt.Println("aa")
15- // }, "", 1))
16- // return CreateModule(def)
17- // })
18- // cpy3.Py_Initialize()
19- // cpy3.PyRun_SimpleString(`
20- //import test
21- //`)
22- }
23-
2410type K struct {
2511 Doc string
2612}
2713
2814func (v * K ) Test (self * PyObject , args * PyObject ) * PyObject {
15+ fmt .Println ("test" )
2916 return nil
3017}
3118func TestRegModule (t * testing.T ) {
32- PyImport_AppendInittab ("test " , func () * PyObject {
33- return RegPyModule ("test " , & K {})
19+ PyImport_AppendInittab ("_test " , func () * PyObject {
20+ return RegPyModule ("_test " , & K {})
3421 })
35- fmt .Println ()
22+ cpy3 .Py_SetProgramName (os .Args [0 ])
23+ cpy3 .Py_SetPythonHome ("./" )
24+ cpy3 .Py_Initialize ()
25+ cpy3 .PyRun_SimpleString (`
26+ print("aaa")
27+ #import _test
28+ #print(_test.Call('Test'))
29+ ` )
3630}
You can’t perform that action at this time.
0 commit comments