diff options
author | John Wiegley <johnw@newartisans.com> | 2009-11-11 02:58:06 -0500 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2009-11-11 02:58:06 -0500 |
commit | 4a4ff9d4b21e7ed94524314ca496bd17c84fc4ed (patch) | |
tree | 9771c98709cd0d644eeb5a455df0ddd7fe40d5e2 /src/py_value.cc | |
parent | ed9209cc2794eeef2a363947ab9b89be83aefe6b (diff) | |
download | fork-ledger-4a4ff9d4b21e7ed94524314ca496bd17c84fc4ed.tar.gz fork-ledger-4a4ff9d4b21e7ed94524314ca496bd17c84fc4ed.tar.bz2 fork-ledger-4a4ff9d4b21e7ed94524314ca496bd17c84fc4ed.zip |
Value.basetype in Python returns a Value's base type
Diffstat (limited to 'src/py_value.cc')
-rw-r--r-- | src/py_value.cc | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/py_value.cc b/src/py_value.cc index 9653b0e1..c8e4de72 100644 --- a/src/py_value.cc +++ b/src/py_value.cc @@ -47,6 +47,22 @@ BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(set_string_overloads, set_string, 0, 2) namespace { + PyObject * py_base_type(value_t& value) { + if (value.is_boolean()) { + return (PyObject *)&PyBool_Type; + } + else if (value.is_long()) { + return (PyObject *)&PyInt_Type; + } + else if (value.is_string()) { + return (PyObject *)&PyUnicode_Type; + } + else { + object typeobj(object(value).attr("__class__")); + return typeobj.ptr(); + } + } + expr_t py_value_getattr(const value_t& value, const string& name) { if (value.is_scope()) { @@ -305,6 +321,8 @@ void export_value() .def("label", &value_t::label) .def("valid", &value_t::valid) + + .def("basetype", py_base_type) ; scope().attr("NULL_VALUE") = NULL_VALUE; |