Mercurial > pymonkey
diff undefined.c @ 57:a2b617731398
pymonkey.undefined now has a 'falsy' value.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Fri, 10 Jul 2009 18:41:14 -0700 |
parents | bc4263c6ae82 |
children |
line wrap: on
line diff
--- a/undefined.c Fri Jul 10 17:39:48 2009 -0700 +++ b/undefined.c Fri Jul 10 18:41:14 2009 -0700 @@ -36,6 +36,20 @@ #include "undefined.h" +static Py_ssize_t PYM_undefinedLength(PyObject *o) { + return 0; +}; + +static PyMappingMethods PYM_undefinedAsMapping = { + PYM_undefinedLength, /*mp_length*/ + 0, /*mp_subscript*/ + 0 /*mp_ass_subscript*/ +}; + +static PyObject *PYM_undefinedRepr(PyObject *o) { + return PyString_FromString("pymonkey.undefined"); +} + // TODO: We should make this behave as much like JavaScript's // "undefined" value as possible; e.g., its string value should // be "undefined", the singleton should be falsy, etc. @@ -50,13 +64,13 @@ 0, /*tp_getattr*/ 0, /*tp_setattr*/ 0, /*tp_compare*/ - 0, /*tp_repr*/ + PYM_undefinedRepr, /*tp_repr*/ 0, /*tp_as_number*/ 0, /*tp_as_sequence*/ - 0, /*tp_as_mapping*/ + &PYM_undefinedAsMapping, /*tp_as_mapping*/ 0, /*tp_hash */ 0, /*tp_call*/ - 0, /*tp_str*/ + PYM_undefinedRepr, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ @@ -65,4 +79,4 @@ "Pythonic equivalent of JavaScript's 'undefined' value", }; -PyObject *PYM_undefined = (PyObject *) &PYM_undefinedType; +PYM_undefinedObject *PYM_undefined;