-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpyobj.go
More file actions
57 lines (45 loc) · 1010 Bytes
/
pyobj.go
File metadata and controls
57 lines (45 loc) · 1010 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"fmt"
"github.com/sbinet/go-python"
)
type PO *python.PyObject
type Py struct {
obj *python.PyObject
}
type Fn struct {
Py
}
type Class struct {
Py
}
type Object struct {
Py
}
type Module struct {
Py
}
func (m *Module) Attr(attr string) *python.PyObject {
return m.Py.obj.GetAttrString(attr)
}
func (m *Module) Fn(attr string) *Fn {
return &Fn{Py{m.Attr(attr)}}
}
func (p *Py) makeArgs(args []*python.PyObject, kwargs map[string]*python.PyObject) *python.PyObject {
/* py_all := python.PyTuple_New(2)
py_args := python.PyTuple_New(len(args))
for i, a := range args {
python.PyTuple_SET_ITEM(py_args, i , a)
}
python.PyTuple_SET_ITEM(py_all, 0, py_args)
python.PyTuple_SET_ITEM(py_all, 1, python.PyDict_New())
return py_args
*/
return (&List{topy(args)}).ToTuple()
}
func (p *Py) Call(args ...*python.PyObject) *python.PyObject {
py_args := p.makeArgs(args, nil)
result := p.obj.CallObject(py_args)
fmt.Println("Call Res:", togo(result))
return result
}