#include <Python.h>
#include <structmember.h>
#include <eggdrop/eggdrop.h>
#include "pythonscript.h"
Go to the source code of this file.
Functions | |
static PyObject * | MyModule_New (char *name) |
PyObject * | MyModule_Add (char *name, char *doc) |
static PyObject * | GetAttr (PyObject *self, PyObject *Key) |
static int | SetAttr (PyObject *self, PyObject *Key, PyObject *Value) |
int | MyModule_Init () |
Variables | |
static const char | rcsid [] = "$Id: mymodule.c,v 1.1 2005-12-15 15:26:12 sven Exp $" |
static PyTypeObject | MyModule_Type |
static PyObject * | DictString |
static PyObject* GetAttr | ( | PyObject * | self, | |
PyObject * | Key | |||
) | [static] |
Definition at line 91 of file mymodule.c.
References DictString.
00091 { 00092 PyObject **DictPtr, *Ret; 00093 00094 DictPtr = _PyObject_GetDictPtr(self); 00095 if (!PyObject_Compare(DictString, Key)) { 00096 Py_INCREF(*DictPtr); 00097 return *DictPtr; 00098 } 00099 Ret = (*DictPtr)->ob_type->tp_as_mapping->mp_subscript(*DictPtr, Key); 00100 if (!Ret && PyErr_ExceptionMatches(PyExc_KeyError)) { 00101 PyErr_Format(PyExc_AttributeError, "'%.50s' object has no attribute '%.400s'", self->ob_type->tp_name, PyString_AS_STRING(Key)); 00102 } 00103 return Ret; 00104 }
PyObject* MyModule_Add | ( | char * | name, | |
char * | doc | |||
) |
Definition at line 63 of file mymodule.c.
References MyModule_New().
Referenced by pythonscript_LTX_start().
00063 { 00064 PyObject *Modules, *ModuleObj; 00065 00066 Modules = PyImport_GetModuleDict(); /* Warning: Borrowed reference */ 00067 if ((ModuleObj = PyDict_GetItemString(Modules, name)) && PyModule_Check(ModuleObj)) return ModuleObj; 00068 ModuleObj = MyModule_New(name); /* new reference */ 00069 if (!ModuleObj) return 0; 00070 if (PyDict_SetItemString(Modules, name, ModuleObj)) { 00071 Py_DECREF(ModuleObj); 00072 return 0; 00073 } 00074 00075 if (doc) { 00076 PyObject **DictPtr, *DocObj; 00077 00078 DictPtr = _PyObject_GetDictPtr(ModuleObj); 00079 DocObj = PyString_FromString(doc); /* new reference */ 00080 if (DocObj) PyDict_SetItemString(*DictPtr, "__doc__", DocObj); 00081 Py_XDECREF(DocObj); 00082 PyErr_Clear(); 00083 } 00084 00085 Py_DECREF(ModuleObj); /* Yes, it still exists, in modules! */ 00086 return ModuleObj; 00087 }
int MyModule_Init | ( | void | ) |
Definition at line 174 of file mymodule.c.
References DictString, and MyModule_Type.
Referenced by pythonscript_LTX_start().
00174 { 00175 MyModule_Type.tp_basicsize = PyModule_Type.tp_basicsize; 00176 MyModule_Type.tp_dictoffset = PyModule_Type.tp_dictoffset; 00177 DictString = PyString_FromString("__dict__"); 00178 return PyType_Ready(&MyModule_Type); 00179 }
static PyObject* MyModule_New | ( | char * | name | ) | [static] |
Definition at line 36 of file mymodule.c.
References MyDict_New(), MyDict_Type, and MyModule_Type.
Referenced by MyModule_Add().
00036 { 00037 int set1, set2; 00038 PyObject *NameObj, *ModuleObj, **DictPtr; 00039 00040 ModuleObj = PyObject_GC_New(PyObject, &MyModule_Type); /* new reference */ 00041 if (!ModuleObj) return 0; 00042 NameObj = PyString_FromString(name); /* new reference */ 00043 DictPtr = _PyObject_GetDictPtr(ModuleObj); 00044 *DictPtr = MyDict_New(&MyDict_Type, 0, 0); 00045 if (!*DictPtr || !NameObj) { 00046 Py_DECREF(ModuleObj); 00047 Py_XDECREF(NameObj); 00048 return 0; 00049 } 00050 set1 = PyDict_SetItemString(*DictPtr, "__name__", NameObj); 00051 Py_DECREF(NameObj); 00052 set2 = PyDict_SetItemString(*DictPtr, "__doc__", Py_None); 00053 if (set1 || set2) { 00054 Py_DECREF(ModuleObj); 00055 return 0; 00056 } 00057 PyObject_GC_Track(ModuleObj); 00058 return ModuleObj; 00059 }
static int SetAttr | ( | PyObject * | self, | |
PyObject * | Key, | |||
PyObject * | Value | |||
) | [static] |
Definition at line 111 of file mymodule.c.
References Callable_Type, CallableObject::client_data, PYTHON_VAR, SCRIPT_READONLY, SetVar(), script_linked_var_b::type, and CallableObject::type.
00111 { 00112 PyObject **DictPtr, *Cur; 00113 CallableObject *Call; 00114 script_linked_var_t *var; 00115 00116 DictPtr = _PyObject_GetDictPtr(self); 00117 Cur = PyDict_GetItem(*DictPtr, Key); /* Warning: borrowed reference */ 00118 if (!Cur) { 00119 PyErr_Format(PyExc_AttributeError, "'%s' object has no attribute '%s'", self->ob_type->tp_name, PyString_AsString(Key)); 00120 return 1; 00121 } 00122 if (Cur->ob_type != &Callable_Type) return PyDict_SetItem(*DictPtr, Key, Value); 00123 Call = (CallableObject *) Cur; 00124 var = Call->client_data; 00125 if (!Value || Call->type != PYTHON_VAR || var->type & SCRIPT_READONLY) { 00126 PyErr_SetString(PyExc_TypeError, "readonly attribute"); 00127 return 1; 00128 } 00129 return SetVar(var, Value); 00130 }
PyObject* DictString [static] |
static PyTypeObject MyModule_Type [static] |
const char rcsid[] = "$Id: mymodule.c,v 1.1 2005-12-15 15:26:12 sven Exp $" [static] |
Definition at line 25 of file mymodule.c.