|
Atrinik Server 2.5
|
#include <plugin_python.h>Go to the source code of this file.
Functions | |
| static void * | attr_list_len_ptr (Atrinik_AttrList *al) |
| static unsigned PY_LONG_LONG | attr_list_len (Atrinik_AttrList *al) |
| static PyObject * | attr_list_get (Atrinik_AttrList *al, void *idx) |
| static int | attr_list_contains (Atrinik_AttrList *al, PyObject *value) |
| static int | attr_list_set (Atrinik_AttrList *al, void *idx, PyObject *value) |
| static PyObject * | __getitem__ (Atrinik_AttrList *al, PyObject *key) |
| static PyObject * | append (Atrinik_AttrList *al, PyObject *value) |
| static int | InternalCompare (Atrinik_AttrList *left, Atrinik_AttrList *right) |
| static PyObject * | RichCompare (Atrinik_AttrList *left, Atrinik_AttrList *right, int op) |
| static PyObject * | iter (PyObject *seq) |
| static PyObject * | iternext (Atrinik_AttrList *al) |
| static Py_ssize_t | __len__ (Atrinik_AttrList *al) |
| static int | __setitem__ (Atrinik_AttrList *al, PyObject *key, PyObject *value) |
| static int | __contains__ (Atrinik_AttrList *al, PyObject *value) |
| int | Atrinik_AttrList_init (PyObject *module) |
| PyObject * | wrap_attr_list (void *ptr, size_t offset, field_type field) |
Variables | |
| static PyMethodDef | methods [] |
| static PySequenceMethods | SequenceMethods |
| static PyMappingMethods | MappingMethods |
| PyTypeObject | Atrinik_AttrListType |
Implements AttrList Python object; this is a class similar to Python lists, but with more limited functionality (it does not implement many methods normal lists do; however, the AttrList object can be converted to a list).
These objects are used to wrap an array of data, for example, player::known_spells array, which holds the spell IDs the player knows. When Python requests to get player.known_spells, the code generates an AttrList object, which "wraps" the actual array of known spells - it holds a pointer to the structure, the offset in the structure, etc. Thus, it is possible for Python to use __setitem__() and __getitem__() methods on this AttrList object to change/extract the array data in the most efficient way possible; all of the data of the array is never held in memory (unless you implicitly convert it to a list, of course).
The code uses many, many castings and does extensive error checking of passed arguments, as the smallest imperfection could cause a memory corruption, most likely resulting in a crash.
If you are adding more field types to handle your array, you will need to modify the following functions:
Definition in file attr_list.c.
| static int __contains__ | ( | Atrinik_AttrList * | al, |
| PyObject * | value | ||
| ) | [static] |
Wrapper for attr_list_contains(), used by the __contains__() method.
| al | AttrList pointer __contains__() is being called on. |
Definition at line 517 of file attr_list.c.
| static PyObject* __getitem__ | ( | Atrinik_AttrList * | al, |
| PyObject * | key | ||
| ) | [static] |
Implements the __getitem__() method.
| al | The AttrList object. |
| key | Index to try and find. |
Definition at line 332 of file attr_list.c.
| static Py_ssize_t __len__ | ( | Atrinik_AttrList * | al | ) | [static] |
Wrapper for attr_list_len(), using Py_ssize_t return value.
Used by the len() method.
| al | AttrList pointer len() is being called on. |
Definition at line 487 of file attr_list.c.
| static int __setitem__ | ( | Atrinik_AttrList * | al, |
| PyObject * | key, | ||
| PyObject * | value | ||
| ) | [static] |
Wrapper for attr_list_set(), used by the __setitem__() method.
| al | AttrList pointer __setitem__() is being called on. |
Definition at line 496 of file attr_list.c.
| static PyObject* append | ( | Atrinik_AttrList * | al, |
| PyObject * | value | ||
| ) | [static] |
Implements the append() method; this is equivalent to the following:
attr_list[len(attr_list)] = xyz
| al | The AttrList object. |
| value | Value to append. |
Definition at line 390 of file attr_list.c.
| int Atrinik_AttrList_init | ( | PyObject * | module | ) |
Initializes the AttrList module.
| module | The main Atrinik module. |
Definition at line 589 of file attr_list.c.
| static int attr_list_contains | ( | Atrinik_AttrList * | al, |
| PyObject * | value | ||
| ) | [static] |
Check if the provided AttrList contains 'value'.
| al | The AttrList object. |
| value | The value to try and find. |
Definition at line 158 of file attr_list.c.
| static PyObject* attr_list_get | ( | Atrinik_AttrList * | al, |
| void * | idx | ||
| ) | [static] |
Get value from an AttrList object.
| al | The AttrList object. |
| idx | Pointer to the index value/key. |
Definition at line 112 of file attr_list.c.
| static unsigned PY_LONG_LONG attr_list_len | ( | Atrinik_AttrList * | al | ) | [static] |
Similar to attr_list_len_ptr(), but does not return a pointer.
| al | AttrList being used. |
Definition at line 93 of file attr_list.c.
| static void* attr_list_len_ptr | ( | Atrinik_AttrList * | al | ) | [static] |
Get a pointer to integer that holds the maximum length depending on the AttrList's field type.
| al | The AttrList pointer. |
Definition at line 70 of file attr_list.c.
| static int attr_list_set | ( | Atrinik_AttrList * | al, |
| void * | idx, | ||
| PyObject * | value | ||
| ) | [static] |
Set new value for an array member that AttrList object is wrapping.
| al | The AttrList object. |
| idx | Pointer to the index value/key. |
| value | New value to set. |
Definition at line 196 of file attr_list.c.
| static PyObject* iter | ( | PyObject * | seq | ) | [static] |
Start iterating.
| seq | What to iterate through. |
Definition at line 435 of file attr_list.c.
| static PyObject* iternext | ( | Atrinik_AttrList * | al | ) | [static] |
Keep iterating over an iteration object.
| al | The iteration object. |
Definition at line 452 of file attr_list.c.
| PyObject* wrap_attr_list | ( | void * | ptr, |
| size_t | offset, | ||
| field_type | field | ||
| ) |
Creates a new AttrList wrapping an array.
| ptr | Pointer to the structure the array is in. |
| offset | Where the array is in the structure. |
| field | Type of the array being handled; for example, FIELDTYPE_KNOWN_SPELLS. |
Definition at line 611 of file attr_list.c.
| PyTypeObject Atrinik_AttrListType |
AttrListType definition.
Definition at line 542 of file attr_list.c.
PyMappingMethods MappingMethods [static] |
{
(lenfunc) __len__,
(binaryfunc) __getitem__,
(objobjargproc) __setitem__,
}
Defines what to map some common methods (len(), __setitem__() and __getitem__()) to.
Definition at line 534 of file attr_list.c.
PyMethodDef methods[] [static] |
{
{"__getitem__", (PyCFunction) __getitem__, METH_O | METH_COEXIST, 0},
{"append", (PyCFunction) append, METH_O, 0},
{NULL, NULL, 0, 0}
}
Available Python methods for the AtrinikPlayer type.
Definition at line 408 of file attr_list.c.
PySequenceMethods SequenceMethods [static] |
{
(lenfunc) __len__,
NULL, NULL, NULL, NULL, NULL, NULL,
(objobjproc) __contains__,
NULL, NULL
}
Common sequence methods.
Definition at line 523 of file attr_list.c.
1.7.4