#include <Python.h>
#include <eggdrop/eggdrop.h>
#include "pythonscript.h"
Go to the source code of this file.
Defines | |
#define | MyDict_Check(op) PyObject_TypeCheck(op, &MyDict_Type) |
Functions | |
PyObject * | MyDict_New (PyTypeObject *Type, PyObject *args, PyObject *kwds) |
PyObject * | GetVar (script_linked_var_t *var) |
int | SetVar (script_linked_var_t *var, PyObject *Value) |
static PyObject * | GetItem (PyObject *self, PyObject *Key) |
static int | SetItem (PyObject *self, PyObject *Key, PyObject *Value) |
Variables | |
static const char | rcsid [] = "$Id: mydict.c,v 1.1 2005-12-15 15:26:12 sven Exp $" |
static PyMappingMethods | mapstr |
PyTypeObject | MyDict_Type |
#define MyDict_Check | ( | op | ) | PyObject_TypeCheck(op, &MyDict_Type) |
static PyObject* GetItem | ( | PyObject * | self, | |
PyObject * | Key | |||
) | [static] |
Definition at line 63 of file mydict.c.
References Callable_Type, CallableObject::client_data, GetVar(), PYTHON_FUNC, and CallableObject::type.
00063 { 00064 PyObject *Ret; 00065 CallableObject *Cal; 00066 00067 Ret = PyDict_GetItem(self, Key); /* Warning: Borrowed reference */ 00068 Cal = (CallableObject *) Ret; 00069 00070 if (!Ret || !Cal->client_data) { 00071 PyErr_Format(PyExc_KeyError, "'%s'", PyString_AS_STRING(Key)); 00072 return 0; 00073 } 00074 if (Ret->ob_type != &Callable_Type || Cal->type == PYTHON_FUNC) { 00075 Py_INCREF(Ret); 00076 return Ret; 00077 } 00078 return GetVar(Cal->client_data); 00079 }
PyObject* GetVar | ( | script_linked_var_t * | var | ) |
Definition at line 36 of file mydict.c.
References c_to_python_var(), script_linked_var_b::callbacks, script_var_b::len, script_linked_var_b::name, script_var_callbacks_b::on_read, SCRIPT_TYPE_MASK, script_linked_var_b::type, script_var_b::type, script_linked_var_b::value, and script_var_b::value.
Referenced by GetItem(), and Repr().
00036 { 00037 script_var_t newvalue = {0}; 00038 00039 newvalue.len = -1; 00040 if (var->callbacks && var->callbacks->on_read) { 00041 if (var->callbacks->on_read(var, &newvalue)) { 00042 PyErr_Format(PyExc_LookupError, "internal eggdrop error in 'on_read' function for '%s'", var->name); 00043 return 0; 00044 } 00045 } else { 00046 newvalue.type = var->type & SCRIPT_TYPE_MASK;; 00047 newvalue.value = *(void **)var->value; 00048 } 00049 return c_to_python_var(&newvalue); 00050 }
PyObject* MyDict_New | ( | PyTypeObject * | Type, | |
PyObject * | args, | |||
PyObject * | kwds | |||
) |
static int SetItem | ( | PyObject * | self, | |
PyObject * | Key, | |||
PyObject * | Value | |||
) | [static] |
Definition at line 86 of file mydict.c.
References Callable_Type, CallableObject::client_data, PYTHON_VAR, SCRIPT_READONLY, SetVar(), script_linked_var_b::type, and CallableObject::type.
00086 { 00087 PyObject *Ret; 00088 CallableObject *Call; 00089 script_linked_var_t *var; 00090 00091 Ret = PyDict_GetItem(self, Key); /* Warning: Borrowed reference */ 00092 if (!Ret || !Value) { 00093 PyErr_SetString(PyExc_TypeError, "object does not support item assignment"); 00094 return 1; 00095 } 00096 if (Ret->ob_type != &Callable_Type) return PyDict_SetItem(self, Key, Value); 00097 Call = (CallableObject *) Ret; 00098 var = Call->client_data; 00099 if (!var || Call->type != PYTHON_VAR || var->type & SCRIPT_READONLY) { 00100 PyErr_SetString(PyExc_TypeError, "object does not support item assignment"); 00101 return 1; 00102 } 00103 return SetVar(var, Value); 00104 }
int SetVar | ( | script_linked_var_t * | var, | |
PyObject * | Value | |||
) |
Definition at line 52 of file mydict.c.
References python_to_c_var(), script_linked_var_on_write(), and script_linked_var_b::type.
Referenced by SetAttr(), and SetItem().
00052 { 00053 script_var_t newvalue = {0}; 00054 00055 if (python_to_c_var(Value, &newvalue, var->type)) return 1; 00056 if (script_linked_var_on_write(var, &newvalue)) { 00057 PyErr_SetString(PyExc_RuntimeError, "set"); 00058 return 1; 00059 } 00060 return 0; 00061 }
PyMappingMethods mapstr [static] |
PyTypeObject MyDict_Type |
Definition at line 112 of file mydict.c.
Referenced by MyModule_New(), and pythonscript_LTX_start().
const char rcsid[] = "$Id: mydict.c,v 1.1 2005-12-15 15:26:12 sven Exp $" [static] |