Mercurial > pymonkey
changeset 34:5d3d3b25f23f
JS wrapped Python functions can now return booleans.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Tue, 30 Jun 2009 22:47:31 -0700 |
parents | 3f8a2db496f5 |
children | 3e66613d1d4d |
files | test_pymonkey.py utils.c |
diffstat | 2 files changed, 22 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/test_pymonkey.py Tue Jun 30 22:42:48 2009 -0700 +++ b/test_pymonkey.py Tue Jun 30 22:47:31 2009 -0700 @@ -22,6 +22,18 @@ self.assertEqual(self._evalJsWrappedPyFunc(hai2u, 'hai2u()'), u"o hai") + def testJsWrappedPythonFunctionReturnsTrue(self): + def hai2u(): + return True + self.assertEqual(self._evalJsWrappedPyFunc(hai2u, 'hai2u()'), + True) + + def testJsWrappedPythonFunctionReturnsFalse(self): + def hai2u(): + return False + self.assertEqual(self._evalJsWrappedPyFunc(hai2u, 'hai2u()'), + False) + def testJsWrappedPythonFunctionReturnsSmallInt(self): def hai2u(): return 5
--- a/utils.c Tue Jun 30 22:42:48 2009 -0700 +++ b/utils.c Tue Jun 30 22:47:31 2009 -0700 @@ -50,6 +50,16 @@ if (PyFloat_Check(object)) return PYM_doubleToJsval(cx, PyFloat_AS_DOUBLE(object), rval); + if (object == Py_True) { + *rval = JSVAL_TRUE; + return 0; + } + + if (object == Py_False) { + *rval = JSVAL_FALSE; + return 0; + } + // TODO: Support more types. PyErr_SetString(PyExc_NotImplementedError, "Data type conversion not implemented.");