comparison 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
comparison
equal deleted inserted replaced
56:72e84bd75905 57:a2b617731398
34 * 34 *
35 * ***** END LICENSE BLOCK ***** */ 35 * ***** END LICENSE BLOCK ***** */
36 36
37 #include "undefined.h" 37 #include "undefined.h"
38 38
39 static Py_ssize_t PYM_undefinedLength(PyObject *o) {
40 return 0;
41 };
42
43 static PyMappingMethods PYM_undefinedAsMapping = {
44 PYM_undefinedLength, /*mp_length*/
45 0, /*mp_subscript*/
46 0 /*mp_ass_subscript*/
47 };
48
49 static PyObject *PYM_undefinedRepr(PyObject *o) {
50 return PyString_FromString("pymonkey.undefined");
51 }
52
39 // TODO: We should make this behave as much like JavaScript's 53 // TODO: We should make this behave as much like JavaScript's
40 // "undefined" value as possible; e.g., its string value should 54 // "undefined" value as possible; e.g., its string value should
41 // be "undefined", the singleton should be falsy, etc. 55 // be "undefined", the singleton should be falsy, etc.
42 PyTypeObject PYM_undefinedType = { 56 PyTypeObject PYM_undefinedType = {
43 PyObject_HEAD_INIT(NULL) 57 PyObject_HEAD_INIT(NULL)
48 0, /*tp_dealloc*/ 62 0, /*tp_dealloc*/
49 0, /*tp_print*/ 63 0, /*tp_print*/
50 0, /*tp_getattr*/ 64 0, /*tp_getattr*/
51 0, /*tp_setattr*/ 65 0, /*tp_setattr*/
52 0, /*tp_compare*/ 66 0, /*tp_compare*/
53 0, /*tp_repr*/ 67 PYM_undefinedRepr, /*tp_repr*/
54 0, /*tp_as_number*/ 68 0, /*tp_as_number*/
55 0, /*tp_as_sequence*/ 69 0, /*tp_as_sequence*/
56 0, /*tp_as_mapping*/ 70 &PYM_undefinedAsMapping, /*tp_as_mapping*/
57 0, /*tp_hash */ 71 0, /*tp_hash */
58 0, /*tp_call*/ 72 0, /*tp_call*/
59 0, /*tp_str*/ 73 PYM_undefinedRepr, /*tp_str*/
60 0, /*tp_getattro*/ 74 0, /*tp_getattro*/
61 0, /*tp_setattro*/ 75 0, /*tp_setattro*/
62 0, /*tp_as_buffer*/ 76 0, /*tp_as_buffer*/
63 Py_TPFLAGS_DEFAULT, /*tp_flags*/ 77 Py_TPFLAGS_DEFAULT, /*tp_flags*/
64 /* tp_doc */ 78 /* tp_doc */
65 "Pythonic equivalent of JavaScript's 'undefined' value", 79 "Pythonic equivalent of JavaScript's 'undefined' value",
66 }; 80 };
67 81
68 PyObject *PYM_undefined = (PyObject *) &PYM_undefinedType; 82 PYM_undefinedObject *PYM_undefined;