Mercurial > pytave
comparison oct-py-util.cc @ 333:96b78e78a235
pycall: add support for keyword arguments from pyargs (fixes issue #45)
* oct-py-util.cc, oct-py-util.h (pytave::py_object_class_name,
pytave::is_py_kwargs_argument, pytave::update_py_dict): New functions.
* pycall.cc (Fpycall): Check for and handle keyword arguments.
author | Mike Miller <mtmiller@octave.org> |
---|---|
date | Mon, 15 Aug 2016 13:20:15 -0700 |
parents | cee203ea6245 |
children | 7f039ffe501b |
comparison
equal
deleted
inserted
replaced
332:b8128a2e0e70 | 333:96b78e78a235 |
---|---|
25 #endif | 25 #endif |
26 | 26 |
27 #include <oct.h> | 27 #include <oct.h> |
28 #include <octave/parse.h> | 28 #include <octave/parse.h> |
29 | 29 |
30 #include "oct-py-types.h" | |
30 #include "oct-py-util.h" | 31 #include "oct-py-util.h" |
31 | 32 |
32 using namespace boost::python; | 33 using namespace boost::python; |
33 | 34 |
34 namespace pytave | 35 namespace pytave |
93 std::string hexid = tmp(0).string_value (); | 94 std::string hexid = tmp(0).string_value (); |
94 py_object = main_module.attr ("__InOct__")[hexid]; | 95 py_object = main_module.attr ("__InOct__")[hexid]; |
95 } | 96 } |
96 } | 97 } |
97 | 98 |
99 std::string | |
100 py_object_class_name (PyObject *obj) | |
101 { | |
102 PyObject *class_ = obj ? PyObject_GetAttrString (obj, "__class__") : 0; | |
103 PyObject *name_ = class_ ? PyObject_GetAttrString (class_, "__name__") : 0; | |
104 return name_ ? extract_py_str (name_): ""; | |
98 } | 105 } |
106 | |
107 bool | |
108 is_py_kwargs_argument (PyObject *obj) | |
109 { | |
110 if (obj && py_object_class_name (obj) == "_OctaveKwargs" | |
111 && PyObject_HasAttrString (obj, "is_kwargs_argument")) | |
112 { | |
113 PyObject *flag = PyObject_GetAttrString (obj, "is_kwargs_argument"); | |
114 if (flag && PyBool_Check (flag) && PyObject_IsTrue (flag)) | |
115 return true; | |
116 } | |
117 return false; | |
118 } | |
119 | |
120 PyObject * | |
121 update_py_dict (PyObject *dict_orig, PyObject *dict_new) | |
122 { | |
123 PyObject *dict = dict_orig ? dict_orig : PyDict_New (); | |
124 PyDict_Update (dict, dict_new); | |
125 return dict; | |
126 } | |
127 | |
128 } |