Mercurial > pytave
comparison __py_struct_from_dict__.cc @ 368:4d54fb68de71
__py_is_none__: new compiled function to test whether an object is None
* __py_struct_from_dict__.cc (F__py_is_none__): New function.
* @py/subsref.m, @pyobject/subsref.m, pycall.cc: Use __py_is_none__ instead
of ad hoc lambda expression.
author | Mike Miller <mtmiller@octave.org> |
---|---|
date | Thu, 25 Aug 2016 16:27:46 -0700 |
parents | 087e7bc3697f |
children | 0e4097c66788 |
comparison
equal
deleted
inserted
replaced
367:9d7188514f2c | 368:4d54fb68de71 |
---|---|
76 } | 76 } |
77 | 77 |
78 return retval; | 78 return retval; |
79 } | 79 } |
80 | 80 |
81 DEFUN_DLD (__py_is_none__, args, nargout, | |
82 "-*- texinfo -*-\n\ | |
83 @deftypefn {} {} __py_is_none__ (@var{x})\n\ | |
84 Check whether the Python object @var{obj} is the @code{None} object.\n\ | |
85 \n\ | |
86 This is a private internal function not intended for direct use.\n\ | |
87 @end deftypefn") | |
88 { | |
89 if (args.length () != 1) | |
90 print_usage (); | |
91 | |
92 Py_Initialize (); | |
93 | |
94 PyObject *obj = pytave::pyobject_unwrap_object (args(0)); | |
95 | |
96 bool retval = (obj && (obj == Py_None)); | |
97 Py_XDECREF (obj); | |
98 | |
99 return ovl (retval); | |
100 } | |
101 | |
102 /* | |
103 %!assert (__py_is_none__ (pyobject ())) | |
104 %!assert (__py_is_none__ (pyeval ("None"))) | |
105 %!assert (! __py_is_none__ (1)) | |
106 %!assert (! __py_is_none__ ("None")) | |
107 %!assert (! __py_is_none__ (pyobject (1))) | |
108 %!assert (! __py_is_none__ (pyobject ("None"))) | |
109 | |
110 %!error __py_is_none__ () | |
111 %!error __py_is_none__ (1, 2) | |
112 */ | |
113 | |
81 DEFUN_DLD (__py_isinstance__, args, nargout, | 114 DEFUN_DLD (__py_isinstance__, args, nargout, |
82 "-*- texinfo -*-\n\ | 115 "-*- texinfo -*-\n\ |
83 @deftypefn {} {} __py_isinstance__ (@var{x})\n\ | 116 @deftypefn {} {} __py_isinstance__ (@var{x})\n\ |
84 Check whether the Python object @var{obj} is an instance of a Python type\n\ | 117 Check whether the Python object @var{obj} is an instance of a Python type\n\ |
85 specified by the string @var{type}.\n\ | 118 specified by the string @var{type}.\n\ |