Fred Drake | 2ab0a10 | 2002-03-28 23:32:53 +0000 | [diff] [blame^] | 1 | #include <Python.h> |
| 2 | |
| 3 | staticforward PyTypeObject noddy_NoddyType; |
| 4 | |
| 5 | typedef struct { |
| 6 | PyObject_HEAD |
| 7 | } noddy_NoddyObject; |
| 8 | |
| 9 | static PyObject* |
| 10 | noddy_new_noddy(PyObject* self, PyObject* args) |
| 11 | { |
| 12 | noddy_NoddyObject* noddy; |
| 13 | |
| 14 | if (!PyArg_ParseTuple(args,":new_noddy")) |
| 15 | return NULL; |
| 16 | |
| 17 | noddy = PyObject_New(noddy_NoddyObject, &noddy_NoddyType); |
| 18 | |
| 19 | return (PyObject*)noddy; |
| 20 | } |
| 21 | |
| 22 | static void |
| 23 | noddy_noddy_dealloc(PyObject* self) |
| 24 | { |
| 25 | PyObject_Del(self); |
| 26 | } |
| 27 | |
| 28 | static PyTypeObject noddy_NoddyType = { |
| 29 | PyObject_HEAD_INIT(NULL) |
| 30 | 0, |
| 31 | "Noddy", |
| 32 | sizeof(noddy_NoddyObject), |
| 33 | 0, |
| 34 | noddy_noddy_dealloc, /*tp_dealloc*/ |
| 35 | 0, /*tp_print*/ |
| 36 | 0, /*tp_getattr*/ |
| 37 | 0, /*tp_setattr*/ |
| 38 | 0, /*tp_compare*/ |
| 39 | 0, /*tp_repr*/ |
| 40 | 0, /*tp_as_number*/ |
| 41 | 0, /*tp_as_sequence*/ |
| 42 | 0, /*tp_as_mapping*/ |
| 43 | 0, /*tp_hash */ |
| 44 | }; |
| 45 | |
| 46 | static PyMethodDef noddy_methods[] = { |
| 47 | {"new_noddy", noddy_new_noddy, METH_VARARGS, |
| 48 | "Create a new Noddy object."}, |
| 49 | {NULL, NULL, 0, NULL} |
| 50 | }; |
| 51 | |
| 52 | DL_EXPORT(void) |
| 53 | initnoddy(void) |
| 54 | { |
| 55 | noddy_NoddyType.ob_type = &PyType_Type; |
| 56 | |
| 57 | Py_InitModule("noddy", noddy_methods); |
| 58 | } |