PyCallable_Check() private method

private PyCallable_Check ( IntPtr pointer ) : int
pointer IntPtr
return int
示例#1
0
        /// <summary>
        /// DelegateObject __new__ implementation. The result of this is a new
        /// PyObject whose type is DelegateObject and whose ob_data is a handle
        /// to an actual delegate instance. The method wrapped by the actual
        /// delegate instance belongs to an object generated to relay the call
        /// to the Python callable passed in.
        /// </summary>
        public static IntPtr tp_new(IntPtr tp, IntPtr args, IntPtr kw)
        {
            var self = (DelegateObject)GetManagedObject(tp);

            if (!self.type.Valid)
            {
                return(Exceptions.RaiseTypeError(self.type.DeletedMessage));
            }
            Type type = self.type.Value;

            if (Runtime.PyTuple_Size(args) != 1)
            {
                return(Exceptions.RaiseTypeError("class takes exactly one argument"));
            }

            IntPtr method = Runtime.PyTuple_GetItem(args, 0);

            if (Runtime.PyCallable_Check(method) != 1)
            {
                return(Exceptions.RaiseTypeError("argument must be callable"));
            }

            Delegate d = PythonEngine.DelegateManager.GetDelegate(type, method);

            return(CLRObject.GetInstHandle(d, self.pyHandle));
        }
示例#2
0
        /// <summary>
        /// DelegateObject __new__ implementation. The result of this is a new
        /// PyObject whose type is DelegateObject and whose ob_data is a handle
        /// to an actual delegate instance. The method wrapped by the actual
        /// delegate instance belongs to an object generated to relay the call
        /// to the Python callable passed in.
        /// </summary>
        public static NewReference tp_new(BorrowedReference tp, BorrowedReference args, BorrowedReference kw)
        {
            var self = (DelegateObject)GetManagedObject(tp) !;

            if (!self.type.Valid)
            {
                return(Exceptions.RaiseTypeError(self.type.DeletedMessage));
            }
            Type type = self.type.Value;

            if (Runtime.PyTuple_Size(args) != 1)
            {
                return(Exceptions.RaiseTypeError("class takes exactly one argument"));
            }

            BorrowedReference method = Runtime.PyTuple_GetItem(args, 0);

            if (Runtime.PyCallable_Check(method) != 1)
            {
                return(Exceptions.RaiseTypeError("argument must be callable"));
            }

            Delegate d = PythonEngine.DelegateManager.GetDelegate(type, new PyObject(method));

            return(CLRObject.GetReference(d, ClassManager.GetClass(type)));
        }
示例#3
0
        /// <summary>
        /// EventBinding += operator implementation.
        /// </summary>
        public static NewReference nb_inplace_add(BorrowedReference ob, BorrowedReference arg)
        {
            var self = (EventBinding)GetManagedObject(ob) !;

            if (Runtime.PyCallable_Check(arg) < 1)
            {
                Exceptions.SetError(Exceptions.TypeError, "event handlers must be callable");
                return(default);
示例#4
0
        /// <summary>
        /// EventBinding -= operator implementation.
        /// </summary>
        public static IntPtr nb_inplace_subtract(IntPtr ob, IntPtr arg)
        {
            var self = (EventBinding)GetManagedObject(ob);

            if (Runtime.PyCallable_Check(arg) < 1)
            {
                Exceptions.SetError(Exceptions.TypeError, "invalid event handler");
                return(IntPtr.Zero);
            }

            if (!self.e.RemoveEventHandler(self.target, arg))
            {
                return(IntPtr.Zero);
            }

            Runtime.XIncref(self.pyHandle);
            return(self.pyHandle);
        }
示例#5
0
        public static IntPtr nb_inplace_add(IntPtr ob, IntPtr arg)
        {
            EventBinding self = (EventBinding)GetManagedObject(ob);

            if (Runtime.PyCallable_Check(arg) < 1)
            {
                Exceptions.SetError(Exceptions.TypeError,
                                    "event handlers must be callable"
                                    );
                return(IntPtr.Zero);
            }

            if (!self.e.AddEventHandler(self.target, arg))
            {
                return(IntPtr.Zero);
            }

            Runtime.Incref(self.pyHandle);
            return(self.pyHandle);
        }
示例#6
0
        public static IntPtr tp_new(IntPtr tp, IntPtr args, IntPtr kw)
        {
            DelegateObject self = (DelegateObject)GetManagedObject(tp);

            if (Runtime.PyTuple_Size(args) != 1)
            {
                string message = "class takes exactly one argument";
                return(Exceptions.RaiseTypeError(message));
            }

            IntPtr method = Runtime.PyTuple_GetItem(args, 0);

            if (Runtime.PyCallable_Check(method) != 1)
            {
                return(Exceptions.RaiseTypeError("argument must be callable"));
            }

            Delegate d = DelegateManager.GetDelegate(self.type, method);

            return(CLRObject.GetInstHandle(d, self.pyHandle));
        }
示例#7
0
 /// <summary>
 /// IsCallable Method
 /// </summary>
 /// <remarks>
 /// Returns true if the object is a callable object. This method
 /// always succeeds.
 /// </remarks>
 public bool IsCallable()
 {
     return(Runtime.PyCallable_Check(obj) != 0);
 }