-
Notifications
You must be signed in to change notification settings - Fork 2
/
PyTuple.go
46 lines (41 loc) · 1.09 KB
/
PyTuple.go
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
package py3
import (
"github.com/aadog/py3-go/cpy3"
"unsafe"
)
type PyTuple struct {
PyObject
}
func (p *PyTuple) Size() int64 {
return cpy3.PyTuple_Size(p.instance)
}
func (p *PyTuple) Check() int64 {
return cpy3.PyTuple_Check(p.instance)
}
func (p *PyTuple) GetItem(pos int64) *PyObject {
return PyObjectFromInst(cpy3.PyTuple_GetItem(p.instance, pos))
}
func (p *PyTuple) SetItem(pos int64, o *PyObject) *PyObject {
return PyObjectFromInst(cpy3.PyTuple_SetItem(p.instance, pos, o.instance))
}
func (p *PyTuple) GetSlice(low int64, high int64) *PyObject {
return PyObjectFromInst(cpy3.PyTuple_GetSlice(p.instance, low, high))
}
// PyTupleFromInst
// 新建一个对象来自已经存在的对象实例指针。
//
// Create a new object from an existing object instance pointer.
func PyTupleFromInst(inst uintptr) *PyTuple {
dl := new(PyTuple)
dl.instance = inst
dl.ptr = unsafe.Pointer(dl.instance)
return dl
}
func PyTupleFromObj(obj *PyObject) *PyTuple {
dl := new(PyTuple)
dl.PyObject = *obj
return dl
}
func NewPyTuple(l int64) *PyTuple {
return PyTupleFromInst(cpy3.PyTuple_New(l))
}