예제 #1
0
파일: object.go 프로젝트: MogeiWang/py
// CallObject calls obj with the given args.  args may be nil.  Returns the
// result of the call, or an Error on failure.  This is equivalent to
// "obj(*args)" in Python.
//
// Return value: New Reference.
func (obj *Base) CallObject(args *Tuple) (*Base, error) {
	var a *C.PyObject = nil
	if args != nil {
		a = args.c()
	}
	ret := C.PyObject_CallObject(obj.c(), a)
	return obj2ObjErr(ret)
}
예제 #2
0
파일: base.go 프로젝트: xushiwei/gopy
// CallObject calls obj with the given args.  args may be nil.  Returns the
// result of the call, or an Error on failure.  This is equivalent to
// "obj(*args)" in Python.
//
// Return value: New Reference.
func (obj *BaseObject) CallObject(args *Tuple) (Object, error) {
	var a *C.PyObject = nil
	if args != nil {
		a = c(args)
	}
	ret := C.PyObject_CallObject(c(obj), a)
	return obj2ObjErr(ret)
}
예제 #3
0
파일: object.go 프로젝트: MogeiWang/py
func (obj *Base) CallMethodObject(name string, args *Tuple) (*Base, error) {
	cname := C.CString(name)
	defer C.free(unsafe.Pointer(cname))

	f := C.PyObject_GetAttrString(obj.c(), cname)
	if f == nil {
		return nil, AttributeError.Err(name)
	}
	defer C.decref(f)

	if C.PyCallable_Check(f) == 0 {
		return nil, TypeError.Err("attribute of type '%s' is not callable", name)
	}

	ret := C.PyObject_CallObject(f, args.c())
	return obj2ObjErr(ret)
}
예제 #4
0
파일: base.go 프로젝트: xushiwei/gopy
func (obj *BaseObject) CallMethodObjArgs(name string, args ...Object) (Object, error) {
	cname := C.CString(name)
	defer C.free(unsafe.Pointer(cname))

	f := C.PyObject_GetAttrString(c(obj), cname)
	if f == nil {
		return nil, AttributeError.Err(name)
	}
	defer C.decref(f)

	if C.PyCallable_Check(f) == 0 {
		return nil, TypeError.Err("attribute of type '%s' is not callable", name)
	}

	t, err := PackTuple(args...)
	if err != nil {
		return nil, err
	}

	ret := C.PyObject_CallObject(f, c(t))
	return obj2ObjErr(ret)
}
예제 #5
0
파일: object.go 프로젝트: z0mbie42/py3
// PyObject* PyObject_CallObject(PyObject *callable_object, PyObject *args)
// Return value: New reference.
// Call a callable Python object callable_object, with arguments given by the
// tuple args. If no arguments are needed, then args may be NULL. Returns the
// result of the call on success, or NULL on failure. This is the equivalent of
// the Python expression apply(callable_object, args) or callable_object(*args).
func (self *PyObject) CallObject(args *PyObject) *PyObject {
	return PyObjectToGO(C.PyObject_CallObject(self.ptr, args.ptr))
}