Mercurial > pymonkey
comparison utils.c @ 20:abede8af8cf5
PYM_jsvalToPyObject() can now deal with JSObjects.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Sun, 28 Jun 2009 20:19:39 -0700 |
parents | 551ba05fe6ad |
children | fc04e5f1c675 |
comparison
equal
deleted
inserted
replaced
19:fbb9a61fa030 | 20:abede8af8cf5 |
---|---|
1 #include "utils.h" | 1 #include "utils.h" |
2 #include "undefined.h" | 2 #include "undefined.h" |
3 #include "object.h" | |
3 | 4 |
4 PyObject *PYM_error; | 5 PyObject *PYM_error; |
5 | 6 |
6 PyObject * | 7 PyObject * |
7 PYM_jsvalToPyObject(jsval value) { | 8 PYM_jsvalToPyObject(PYM_JSRuntimeObject *runtime, |
9 jsval value) { | |
8 if (JSVAL_IS_INT(value)) | 10 if (JSVAL_IS_INT(value)) |
9 return PyInt_FromLong(JSVAL_TO_INT(value)); | 11 return PyInt_FromLong(JSVAL_TO_INT(value)); |
10 | 12 |
11 if (JSVAL_IS_DOUBLE(value)) { | 13 if (JSVAL_IS_DOUBLE(value)) { |
12 jsdouble *doubleRef = JSVAL_TO_DOUBLE(value); | 14 jsdouble *doubleRef = JSVAL_TO_DOUBLE(value); |
36 const char *bytes = JS_GetStringBytes(str); | 38 const char *bytes = JS_GetStringBytes(str); |
37 const char *errors; | 39 const char *errors; |
38 return PyUnicode_DecodeUTF8(bytes, strlen(bytes), errors); | 40 return PyUnicode_DecodeUTF8(bytes, strlen(bytes), errors); |
39 } | 41 } |
40 | 42 |
43 if (JSVAL_IS_OBJECT(value)) | |
44 return (PyObject *) PYM_newJSObject(runtime, JSVAL_TO_OBJECT(value)); | |
45 | |
41 // TODO: Support more types. | 46 // TODO: Support more types. |
42 PyErr_SetString(PyExc_NotImplementedError, | 47 PyErr_SetString(PyExc_NotImplementedError, |
43 "Data type conversion not implemented."); | 48 "Data type conversion not implemented."); |
44 } | 49 } |