Exemple #1
0
// 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)
}
Exemple #2
0
// 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)
}
Exemple #3
0
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)
}
Exemple #4
0
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)
}
Exemple #5
0
// 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))
}