421684616343ffd9054a6b1a4770886f4468ad52
[blender.git] / source / gameengine / Expressions / PyObjectPlus.h
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21  * All rights reserved.
22  *
23  * The Original Code is: all of this file.
24  *
25  * Contributor(s): none yet.
26  *
27  * ***** END GPL LICENSE BLOCK *****
28  */
29
30 #ifndef NO_EXP_PYTHON_EMBEDDING
31
32 #ifndef _adr_py_lib_h_                          // only process once,
33 #define _adr_py_lib_h_                          // even if multiply included
34
35 #ifndef __cplusplus                             // c++ only
36 #error Must be compiled with C++
37 #endif
38
39 #include "KX_Python.h"
40 #include "STR_String.h"
41
42 /*------------------------------
43  * Python defines
44 ------------------------------*/
45
46 /*
47    Py_RETURN_NONE
48    Python 2.4 macro.
49    defined here until we switch to 2.4
50    also in api2_2x/gen_utils.h 
51 */
52 #ifndef Py_RETURN_NONE
53 #define Py_RETURN_NONE  return Py_BuildValue("O", Py_None)
54 #endif
55 #ifndef Py_RETURN_FALSE
56 #define Py_RETURN_FALSE  return PyBool_FromLong(0)
57 #endif
58 #ifndef Py_RETURN_TRUE
59 #define Py_RETURN_TRUE  return PyBool_FromLong(1)
60 #endif
61
62 /*  for pre Py 2.5 */
63 #if PY_VERSION_HEX < 0x02050000
64 typedef int Py_ssize_t;
65 typedef Py_ssize_t (*lenfunc)(PyObject *);
66 #define PY_SSIZE_T_MAX INT_MAX
67 #define PY_SSIZE_T_MIN INT_MIN
68 #define PY_METHODCHAR char *
69 #else
70 /* Py 2.5 and later */
71 #define  intargfunc  ssizeargfunc
72 #define intintargfunc  ssizessizeargfunc
73 #define PY_METHODCHAR const char *
74 #endif
75
76 #include "descrobject.h"
77
78
79 static inline void Py_Fatal(const char *M) {
80         fprintf(stderr, "%s\n", M);
81         exit(-1);
82 };
83
84                                                                 // This must be the first line of each 
85                                                                 // PyC++ class
86 #define Py_Header \
87  public: \
88   static PyTypeObject   Type; \
89   static PyMethodDef    Methods[]; \
90   static PyAttributeDef Attributes[]; \
91   static PyParentObject Parents[]; \
92   virtual PyTypeObject *GetType(void) {return &Type;}; \
93   virtual PyParentObject *GetParents(void) {return Parents;}
94
95
96
97                                                                 // This defines the py_getattro_up macro
98                                                                 // which allows attribute and method calls
99                                                                 // to be properly passed up the hierarchy.
100
101 #define py_getattro_up(Parent) \
102         \
103         PyObject *descr = PyDict_GetItem(Type.tp_dict, attr); \
104          \
105         if(descr) { \
106                 if (PyCObject_Check(descr)) { \
107                         return py_get_attrdef((void *)this, (const PyAttributeDef*)PyCObject_AsVoidPtr(descr)); \
108                 } else if (descr->ob_type->tp_descr_get) { \
109                         return PyCFunction_New(((PyMethodDescrObject *)descr)->d_method, (PyObject *)this); \
110                 } else { \
111                         fprintf(stderr, "unknown attribute type"); \
112                         return descr; \
113                 } \
114         } else { \
115                 PyErr_Clear(); \
116                 PyObject *rvalue= Parent::py_getattro(attr); \
117                  \
118                 if (strcmp(PyString_AsString(attr), "__dict__")==0) { \
119                         return py_getattr_dict(rvalue, Type.tp_dict); \
120                 } \
121                  \
122                 return rvalue; \
123         } \
124         return NULL;
125
126
127 #define py_setattro_up(Parent) \
128         PyObject *descr = PyDict_GetItem(Type.tp_dict, attr); \
129          \
130         if(descr) { \
131                 if (PyCObject_Check(descr)) { \
132                         const PyAttributeDef* attrdef= reinterpret_cast<const PyAttributeDef *>(PyCObject_AsVoidPtr(descr)); \
133                         if (attrdef->m_access == KX_PYATTRIBUTE_RO) { \
134                                 PyErr_Format(PyExc_AttributeError, "\"%s\" is read only", PyString_AsString(attr)); \
135                                 return -1; \
136                         } \
137                         else { \
138                                 return py_set_attrdef((void *)this, attrdef, value); \
139                         } \
140                 } else { \
141                         PyErr_Format(PyExc_AttributeError, "\"%s\" cannot be set", PyString_AsString(attr)); \
142                         return -1; \
143                 } \
144         } else { \
145                 PyErr_Clear(); \
146                 return Parent::py_setattro(attr, value); \
147         }
148
149
150 /**
151  * These macros are helpfull when embedding Python routines. The second
152  * macro is one that also requires a documentation string
153  */
154 #define KX_PYMETHOD(class_name, method_name)                    \
155         PyObject* Py##method_name(PyObject* self, PyObject* args, PyObject* kwds); \
156         static PyObject* sPy##method_name( PyObject* self, PyObject* args, PyObject* kwds) { \
157                 return ((class_name*) self)->Py##method_name(self, args, kwds);         \
158         }; \
159
160 #define KX_PYMETHOD_VARARGS(class_name, method_name)                    \
161         PyObject* Py##method_name(PyObject* self, PyObject* args); \
162         static PyObject* sPy##method_name( PyObject* self, PyObject* args) { \
163                 return ((class_name*) self)->Py##method_name(self, args);               \
164         }; \
165
166 #define KX_PYMETHOD_NOARGS(class_name, method_name)                     \
167         PyObject* Py##method_name(PyObject* self); \
168         static PyObject* sPy##method_name( PyObject* self) { \
169                 return ((class_name*) self)->Py##method_name(self);             \
170         }; \
171         
172 #define KX_PYMETHOD_O(class_name, method_name)                  \
173         PyObject* Py##method_name(PyObject* self, PyObject* value); \
174         static PyObject* sPy##method_name( PyObject* self, PyObject* value) { \
175                 return ((class_name*) self)->Py##method_name(self, value);              \
176         }; \
177
178 #define KX_PYMETHOD_DOC(class_name, method_name)                        \
179         PyObject* Py##method_name(PyObject* self, PyObject* args, PyObject* kwds); \
180         static PyObject* sPy##method_name( PyObject* self, PyObject* args, PyObject* kwds) { \
181                 return ((class_name*) self)->Py##method_name(self, args, kwds);         \
182         }; \
183     static const char method_name##_doc[]; \
184
185 #define KX_PYMETHOD_DOC_VARARGS(class_name, method_name)                        \
186         PyObject* Py##method_name(PyObject* self, PyObject* args); \
187         static PyObject* sPy##method_name( PyObject* self, PyObject* args) { \
188                 return ((class_name*) self)->Py##method_name(self, args);               \
189         }; \
190     static const char method_name##_doc[]; \
191
192 #define KX_PYMETHOD_DOC_O(class_name, method_name)                      \
193         PyObject* Py##method_name(PyObject* self, PyObject* value); \
194         static PyObject* sPy##method_name( PyObject* self, PyObject* value) { \
195                 return ((class_name*) self)->Py##method_name(self, value);              \
196         }; \
197     static const char method_name##_doc[]; \
198
199 #define KX_PYMETHOD_DOC_NOARGS(class_name, method_name)                 \
200         PyObject* Py##method_name(PyObject* self); \
201         static PyObject* sPy##method_name( PyObject* self) { \
202                 return ((class_name*) self)->Py##method_name(self);             \
203         }; \
204     static const char method_name##_doc[]; \
205
206
207 /* The line above should remain empty */
208 /**
209  * Method table macro (with doc)
210  */
211 #define KX_PYMETHODTABLE(class_name, method_name) \
212         {#method_name , (PyCFunction) class_name::sPy##method_name, METH_VARARGS, (PY_METHODCHAR)class_name::method_name##_doc}
213
214 #define KX_PYMETHODTABLE_O(class_name, method_name) \
215         {#method_name , (PyCFunction) class_name::sPy##method_name, METH_O, (PY_METHODCHAR)class_name::method_name##_doc}
216
217 #define KX_PYMETHODTABLE_NOARGS(class_name, method_name) \
218         {#method_name , (PyCFunction) class_name::sPy##method_name, METH_NOARGS, (PY_METHODCHAR)class_name::method_name##_doc}
219
220 /**
221  * Function implementation macro
222  */
223 #define KX_PYMETHODDEF_DOC(class_name, method_name, doc_string) \
224 const char class_name::method_name##_doc[] = doc_string; \
225 PyObject* class_name::Py##method_name(PyObject*, PyObject* args, PyObject*)
226
227 #define KX_PYMETHODDEF_DOC_VARARGS(class_name, method_name, doc_string) \
228 const char class_name::method_name##_doc[] = doc_string; \
229 PyObject* class_name::Py##method_name(PyObject*, PyObject* args)
230
231 #define KX_PYMETHODDEF_DOC_O(class_name, method_name, doc_string) \
232 const char class_name::method_name##_doc[] = doc_string; \
233 PyObject* class_name::Py##method_name(PyObject*, PyObject* value)
234
235 #define KX_PYMETHODDEF_DOC_NOARGS(class_name, method_name, doc_string) \
236 const char class_name::method_name##_doc[] = doc_string; \
237 PyObject* class_name::Py##method_name(PyObject*)
238
239 /**
240  * Attribute management
241  */
242 enum KX_PYATTRIBUTE_TYPE {
243         KX_PYATTRIBUTE_TYPE_BOOL,
244         KX_PYATTRIBUTE_TYPE_ENUM,
245         KX_PYATTRIBUTE_TYPE_SHORT,
246         KX_PYATTRIBUTE_TYPE_INT,
247         KX_PYATTRIBUTE_TYPE_FLOAT,
248         KX_PYATTRIBUTE_TYPE_STRING,
249         KX_PYATTRIBUTE_TYPE_DUMMY,
250         KX_PYATTRIBUTE_TYPE_FUNCTION,
251 };
252
253 enum KX_PYATTRIBUTE_ACCESS {
254         KX_PYATTRIBUTE_RW,
255         KX_PYATTRIBUTE_RO
256 };
257
258 struct KX_PYATTRIBUTE_DEF;
259 typedef int (*KX_PYATTRIBUTE_CHECK_FUNCTION)(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
260 typedef int (*KX_PYATTRIBUTE_SET_FUNCTION)(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
261 typedef PyObject* (*KX_PYATTRIBUTE_GET_FUNCTION)(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
262
263 typedef struct KX_PYATTRIBUTE_DEF {
264         const char *m_name;                             // name of the python attribute
265         KX_PYATTRIBUTE_TYPE m_type;             // type of value
266         KX_PYATTRIBUTE_ACCESS m_access; // read/write access or read-only
267         int m_imin;                                             // minimum value in case of integer attributes (for string: minimum string length)
268         int m_imax;                                             // maximum value in case of integer attributes (for string: maximum string length)
269         float m_fmin;                                   // minimum value in case of float attributes
270         float m_fmax;                                   // maximum value in case of float attributes
271         bool   m_clamp;                                 // enforce min/max value by clamping
272         size_t m_offset;                                // position of field in structure
273         size_t m_size;                                  // size of field for runtime verification (enum only)
274         size_t m_length;                                // length of array, 1=simple attribute
275         KX_PYATTRIBUTE_CHECK_FUNCTION m_checkFunction;  // static function to check the assignment, returns 0 if no error
276         KX_PYATTRIBUTE_SET_FUNCTION m_setFunction;      // static function to check the assignment, returns 0 if no error
277         KX_PYATTRIBUTE_GET_FUNCTION m_getFunction;      // static function to check the assignment, returns 0 if no error
278
279         // The following pointers are just used to have compile time check for attribute type.
280         // It would have been good to use a union but that would require C99 compatibility
281         // to initialize specific union fields through designated initializers.
282         struct {
283                 bool *m_boolPtr;
284                 short int *m_shortPtr;
285                 int *m_intPtr;
286                 float *m_floatPtr;
287                 STR_String *m_stringPtr;
288         } m_typeCheck;
289 } PyAttributeDef;
290
291 #define KX_PYATTRIBUTE_DUMMY(name) \
292         { name, KX_PYATTRIBUTE_TYPE_DUMMY, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, 0, 0, 1, NULL, NULL, NULL, {NULL, NULL, NULL, NULL, NULL} }
293
294 #define KX_PYATTRIBUTE_BOOL_RW(name,object,field) \
295         { name, KX_PYATTRIBUTE_TYPE_BOOL, KX_PYATTRIBUTE_RW, 0, 1, 0.f, 0.f, false, offsetof(object,field), 0, 1, NULL, NULL, NULL, {&((object *)0)->field, NULL, NULL, NULL, NULL} }
296 #define KX_PYATTRIBUTE_BOOL_RW_CHECK(name,object,field,function) \
297         { name, KX_PYATTRIBUTE_TYPE_BOOL, KX_PYATTRIBUTE_RW, 0, 1, 0.f, 0.f, false, offsetof(object,field), 0, 1, &object::function, NULL, NULL, {&((object *)0)->field, NULL, NULL, NULL, NULL} }
298 #define KX_PYATTRIBUTE_BOOL_RO(name,object,field) \
299         { name, KX_PYATTRIBUTE_TYPE_BOOL, KX_PYATTRIBUTE_RO, 0, 1, 0.f, 0.f, false, offsetof(object,field), 0, 1, NULL, NULL, NULL, {&((object *)0)->field, NULL, NULL, NULL, NULL} }
300
301 // enum field cannot be mapped to pointer (because we would need a pointer for each enum)
302 // use field size to verify mapping at runtime only, assuming enum size is equal to int size.
303 #define KX_PYATTRIBUTE_ENUM_RW(name,min,max,clamp,object,field) \
304         { name, KX_PYATTRIBUTE_TYPE_ENUM, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, offsetof(object,field), sizeof(((object *)0)->field), 1, NULL, NULL, NULL, {NULL, NULL, NULL, NULL, NULL} }
305 #define KX_PYATTRIBUTE_ENUM_RW_CHECK(name,min,max,clamp,object,field,function) \
306         { name, KX_PYATTRIBUTE_TYPE_ENUM, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, offsetof(object,field), sizeof(((object *)0)->field), 1, &object::function, NULL, NULL, {NULL, NULL, NULL, NULL, NULL} }
307 #define KX_PYATTRIBUTE_ENUM_RO(name,object,field) \
308         { name, KX_PYATTRIBUTE_TYPE_ENUM, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, offsetof(object,field), sizeof(((object *)0)->field), 1, NULL, NULL, NULL, {NULL, NULL, NULL, NULL, NULL} }
309
310 #define KX_PYATTRIBUTE_SHORT_RW(name,min,max,clamp,object,field) \
311         { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, offsetof(object,field), 0, 1, NULL, NULL, NULL, {NULL, &((object *)0)->field, NULL, NULL, NULL} }
312 #define KX_PYATTRIBUTE_SHORT_RW_CHECK(name,min,max,clamp,object,field,function) \
313         { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, offsetof(object,field), 0, 1, &object::function, NULL, NULL, {NULL, &((object *)0)->field, NULL, NULL, NULL} }
314 #define KX_PYATTRIBUTE_SHORT_RO(name,object,field) \
315         { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, offsetof(object,field), 0, 1, NULL, NULL, NULL, {NULL, &((object *)0)->field, NULL, NULL, NULL} }
316 #define KX_PYATTRIBUTE_SHORT_ARRAY_RW(name,min,max,clamp,object,field,length) \
317         { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, offsetof(object,field), 0, length, NULL, NULL, NULL, {NULL, ((object *)0)->field, NULL, NULL, NULL} }
318 #define KX_PYATTRIBUTE_SHORT_ARRAY_RW_CHECK(name,min,max,clamp,object,field,length,function) \
319         { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, offsetof(object,field), 0, length, &object::function, NULL, NULL, {NULL, ((object *)0)->field, NULL, NULL, NULL} }
320 #define KX_PYATTRIBUTE_SHORT_ARRAY_RO(name,object,field,length) \
321         { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, offsetof(object,field), 0, length, NULL, NULL, NULL, {NULL, ((object *)0)->field, NULL, NULL, NULL} }
322 // SHORT_LIST
323 #define KX_PYATTRIBUTE_SHORT_LIST_RW(name,min,max,clamp,object,field,length) \
324         { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, offsetof(object,field), 0, length, NULL, NULL, NULL, {NULL, &((object *)0)->field, NULL, NULL, NULL} }
325 #define KX_PYATTRIBUTE_SHORT_LIST_RW_CHECK(name,min,max,clamp,object,field,length,function) \
326         { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, offsetof(object,field), 0, length, &object::function, NULL, NULL, {NULL, &((object *)0)->field, NULL, NULL, NULL} }
327 #define KX_PYATTRIBUTE_SHORT_LIST_RO(name,object,field,length) \
328         { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, offsetof(object,field), 0, length, NULL, NULL, NULL, {NULL, &((object *)0)->field, NULL, NULL, NULL} }
329
330 #define KX_PYATTRIBUTE_INT_RW(name,min,max,clamp,object,field) \
331         { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, offsetof(object,field), 0, 1, NULL, NULL, NULL, {NULL, NULL, &((object *)0)->field, NULL, NULL} }
332 #define KX_PYATTRIBUTE_INT_RW_CHECK(name,min,max,clamp,object,field,function) \
333         { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, offsetof(object,field), 0, 1, &object::function, NULL, NULL, {NULL, NULL, &((object *)0)->field, NULL, NULL} }
334 #define KX_PYATTRIBUTE_INT_RO(name,object,field) \
335         { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, offsetof(object,field), 0, 1, NULL, NULL, NULL, {NULL, NULL, &((object *)0)->field, NULL, NULL} }
336 #define KX_PYATTRIBUTE_INT_ARRAY_RW(name,min,max,clamp,object,field,length) \
337         { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, offsetof(object,field), 0, length, NULL, NULL, NULL, {NULL, NULL, ((object *)0)->field, NULL, NULL} }
338 #define KX_PYATTRIBUTE_INT_ARRAY_RW_CHECK(name,min,max,clamp,object,field,length,function) \
339         { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, offsetof(object,field), 0, length, &object::function, NULL, NULL, {NULL, NULL, ((object *)0)->field, NULL, NULL} }
340 #define KX_PYATTRIBUTE_INT_ARRAY_RO(name,object,field,length) \
341         { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, offsetof(object,field), 0, length, NULL, NULL, NULL, {NULL, NULL, ((object *)0)->field, NULL, NULL} }
342 // INT_LIST
343 #define KX_PYATTRIBUTE_INT_LIST_RW(name,min,max,clamp,object,field,length) \
344         { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, offsetof(object,field), 0, length, NULL, NULL, NULL, {NULL, NULL, &((object *)0)->field, NULL, NULL} }
345 #define KX_PYATTRIBUTE_INT_LIST_RW_CHECK(name,min,max,clamp,object,field,length,function) \
346         { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, offsetof(object,field), 0, length, &object::function, NULL, NULL, {NULL, NULL, &((object *)0)->field, NULL, NULL} }
347 #define KX_PYATTRIBUTE_INT_LIST_RO(name,object,field,length) \
348         { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, offsetof(object,field), 0, length, NULL, NULL, NULL, {NULL, NULL, &((object *)0)->field, NULL, NULL} }
349
350 // always clamp for float
351 #define KX_PYATTRIBUTE_FLOAT_RW(name,min,max,object,field) \
352         { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RW, 0, 0, min, max, true, offsetof(object,field), 0, 1, NULL, NULL, NULL, {NULL, NULL, NULL, &((object *)0)->field, NULL} }
353 #define KX_PYATTRIBUTE_FLOAT_RW_CHECK(name,min,max,object,field,function) \
354         { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RW, 0, 0, min, max, true, offsetof(object,field), 0, 1, &object::function, NULL, NULL, {NULL, NULL, NULL, &((object *)0)->field, NULL} }
355 #define KX_PYATTRIBUTE_FLOAT_RO(name,object,field) \
356         { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, offsetof(object,field), 0, 1, NULL, NULL, NULL, {NULL, NULL, NULL, &((object *)0)->field, NULL} }
357 #define KX_PYATTRIBUTE_FLOAT_ARRAY_RW(name,min,max,object,field,length) \
358         { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RW, 0, 0, min, max, true, offsetof(object,field), 0, length, NULL, NULL, NULL, {NULL, NULL, NULL, ((object *)0)->field, NULL} }
359 #define KX_PYATTRIBUTE_FLOAT_ARRAY_RW_CHECK(name,min,max,object,field,length,function) \
360         { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RW, 0, 0, min, max, true, offsetof(object,field), 0, length, &object::function, NULL, NULL, {NULL, NULL, NULL, ((object *)0)->field, NULL} }
361 #define KX_PYATTRIBUTE_FLOAT_ARRAY_RO(name,object,field,length) \
362         { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, offsetof(object,field), 0, length, NULL, NULL, NULL, {NULL, NULL, NULL, ((object *)0)->field, NULL} }
363
364 #define KX_PYATTRIBUTE_STRING_RW(name,min,max,clamp,object,field) \
365         { name, KX_PYATTRIBUTE_TYPE_STRING, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, offsetof(object,field), 0, 1, NULL, NULL, NULL, {NULL, NULL, NULL, NULL, &((object *)0)->field} }
366 #define KX_PYATTRIBUTE_STRING_RW_CHECK(name,min,max,clamp,object,field,function) \
367         { name, KX_PYATTRIBUTE_TYPE_STRING, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, offsetof(object,field), 0, 1, &object::function, NULL, NULL, {NULL, NULL, NULL, NULL, &((object *)0)->field} }
368 #define KX_PYATTRIBUTE_STRING_RO(name,object,field) \
369         { name, KX_PYATTRIBUTE_TYPE_STRING, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, offsetof(object,field), 0, 1 , NULL, NULL, NULL, {NULL, NULL, NULL, NULL, &((object *)0)->field} }
370
371 #define KX_PYATTRIBUTE_RW_FUNCTION(name,object,getfunction,setfunction) \
372         { name, KX_PYATTRIBUTE_TYPE_FUNCTION, KX_PYATTRIBUTE_RW, 0, 0, 0.f, 0.f, false, 0, 0, 1, NULL, &object::setfunction, &object::getfunction, {NULL, NULL, NULL, NULL, NULL} }
373 #define KX_PYATTRIBUTE_RO_FUNCTION(name,object,getfunction) \
374         { name, KX_PYATTRIBUTE_TYPE_FUNCTION, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, 0, 0, 1, NULL, NULL, &object::getfunction, {NULL, NULL, NULL, NULL, NULL} }
375 #define KX_PYATTRIBUTE_ARRAY_RW_FUNCTION(name,object,length,getfunction,setfunction) \
376         { name, KX_PYATTRIBUTE_TYPE_FUNCTION, KX_PYATTRIBUTE_RW, 0, 0, 0.f, 0,f, false, 0, 0, length, NULL, &object::setfunction, &object::getfunction, {NULL, NULL, NULL, NULL, NULL} }
377 #define KX_PYATTRIBUTE_ARRAY_RO_FUNCTION(name,object,length,getfunction) \
378         { name, KX_PYATTRIBUTE_TYPE_FUNCTION, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0,f, false, 0, 0, length, NULL, NULL, &object::getfunction, {NULL, NULL, NULL, NULL, NULL} }
379
380
381 /*------------------------------
382  * PyObjectPlus
383 ------------------------------*/
384 typedef PyTypeObject * PyParentObject;                          // Define the PyParent Object
385
386 class PyObjectPlus : public PyObject 
387 {                               // The PyObjectPlus abstract class
388         Py_Header;                                                      // Always start with Py_Header
389         
390 public:
391         PyObjectPlus(PyTypeObject *T);
392         
393         virtual ~PyObjectPlus();                                        // destructor
394         static void PyDestructor(PyObject *P)                           // python wrapper
395         {  
396                 delete ((PyObjectPlus *) P);  
397         };
398         
399 //      void INCREF(void) {
400 //                Py_INCREF(this);
401 //        };                            // incref method
402 //      void DECREF(void) {
403 //                Py_DECREF(this);
404 //        };                            // decref method
405         
406         virtual PyObject *py_getattro(PyObject *attr);                  // py_getattro method
407         static  PyObject *py_base_getattro(PyObject * self, PyObject *attr)     // This should be the entry in Type. 
408         {
409                 return ((PyObjectPlus*) self)->py_getattro(attr); 
410         }
411         
412         static PyObject*        py_get_attrdef(void *self, const PyAttributeDef *attrdef);
413         static int                      py_set_attrdef(void *self, const PyAttributeDef *attrdef, PyObject *value);
414         
415 #if 0
416         static PyObject *py_getattro_self(const PyAttributeDef attrlist[], void *self, PyObject *attr);
417         static int py_setattro_self(const PyAttributeDef attrlist[], void *self, PyObject *attr, PyObject *value);
418 #endif
419         
420         virtual int py_delattro(PyObject *attr);
421         virtual int py_setattro(PyObject *attr, PyObject *value);               // py_setattro method
422         static  int py_base_setattro(PyObject *self, PyObject *attr, PyObject *value) // the PyType should reference this
423         {
424                 if (value==NULL)
425                         return ((PyObjectPlus*) self)->py_delattro(attr);
426                 
427                 return ((PyObjectPlus*) self)->py_setattro(attr, value); 
428         }
429         
430         virtual PyObject *py_repr(void);                                // py_repr method
431         static  PyObject *py_base_repr(PyObject *PyObj)                 // This should be the entry in Type.
432         {
433                 return ((PyObjectPlus*) PyObj)->py_repr();  
434         }
435         
436                                                                         // isA methods
437         bool isA(PyTypeObject *T);
438         bool isA(const char *mytypename);
439         PyObject *Py_isA(PyObject *value);
440         static PyObject *sPy_isA(PyObject *self, PyObject *value)
441         {
442                 return ((PyObjectPlus*)self)->Py_isA(value);
443         }
444 };
445
446 PyObject *py_getattr_dict(PyObject *pydict, PyObject *tp_dict);
447
448 #endif //  _adr_py_lib_h_
449
450 #endif //NO_EXP_PYTHON_EMBEDDING
451