pylib.h

Go to the documentation of this file.
00001 #ifndef GAME_PYTHON_LIB_H
00002 #define GAME_PYTHON_LIB_H
00003 
00009 /* Copyright, 2000 Nevrax Ltd.
00010  *
00011  * This file is part of NEVRAX NEL.
00012  * NEVRAX NEL is free software; you can redistribute it and/or modify
00013  * it under the terms of the GNU General Public License as published by
00014  * the Free Software Foundation; either version 2, or (at your option)
00015  * any later version.
00016 
00017  * NEVRAX NEL is distributed in the hope that it will be useful, but
00018  * WITHOUT ANY WARRANTY; without even the implied warranty of
00019  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00020  * General Public License for more details.
00021 
00022  * You should have received a copy of the GNU General Public License
00023  * along with NEVRAX NEL; see the file COPYING. If not, write to the
00024  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00025  * MA 02111-1307, USA.
00026  */
00027 
00028 #include <Python.h>
00029 #include "nel/ai/pyserver/pythonsupport.h"
00030 #include "nel/ai/c/abstract_interface.h"
00031 
00032 
00033 namespace NLAIPYSERVER
00034 {               
00035 
00036 #define PyCastMethod    struct _object *(__cdecl *)(struct _object *,struct _object *)
00037 
00038         class CPyExport
00039         {
00040         private:
00041                 bool _DebugMode;
00042                 
00043                 const char *getNameSpace(const char *Name) const
00044                 {
00045                         return Name == NULL ? "__main__" : Name;
00046                 }
00047                                 
00048                 PyObject *loadAttruibut(char  *,char  *);
00049                 PyObject *loadModule(char  *);
00050                 sint32  convertResult(PyObject *Result,char *Format, void *Target);
00051                 PyObject *debugFunction(PyObject *Func,PyObject *Arg);
00052                 PyObject *debugCode(sint32 RunMode,const char *code,PyObject *ModDict);
00053                 void printLastError();
00054 
00055         public: 
00056 
00057                 CPyExport()
00058                 {
00059                         _DebugMode = false;
00060                         //Py_Initialize();              
00061                         _DebugMode = false;                     
00062                 }
00063 
00065                 bool    setDebug()
00066                 {
00067                         return (_DebugMode = true); 
00068                 }
00069 
00071                 sint32  getDebugStat()
00072                 {
00073                         return _DebugMode;
00074                 }
00075 
00077                 bool    unSetDebug()
00078                 {
00079                         return (_DebugMode = false);
00080                 }
00081 
00082 
00084                 bool isDebug()
00085                 {
00086                         return (_DebugMode == true);
00087                 }
00088 
00118                 sint32 runCode(const char  *Code,char  *NameSpace = NULL,sint32 ModeExec = Py_file_input,char *Format = NULL,void *ResultTarget = NULL,sint32 Error = true );   
00119         
00143                 sint32 runMethod(PyObject *Obj,char  *MethodName,char *ResFormat, void *ResTarget,char *Format,...);
00144                 
00160                 sint32 runFunction(char *ModuleName,char  *MethodName,char *ResFormat, void *ResTarget,char *Format,...);
00161 
00162         
00185                 sint32  getMembreValue(PyObject *Obj,char  *AttribName,char *ResFormat, void *ResTarget);       
00186                 
00187                 
00206                 sint32  setMembreValue(PyObject *Obj,char  *AttribName,char *ResFormat, ...);   
00207                 
00208 
00210                 char  *getCodeFromFile(const char *FileName);
00211 
00212                 
00213                 sint32 getGlobal(char  *NameSpace,char  *VarName,char *Format,void *VarValue); // la meme chose que GetMembreValue mais sur un module
00214                 sint32 setGlobal(char  *NameSpace,char  *VarName,char  *Format, ...); // la meme chose que SetMembreValue mais sur un module
00215                 PyObject *addModule(char  *,PyMethodDef *);
00216                 PyObject *getRefVar(char  *VarName);            
00217                 
00218                 ~CPyExport()
00219                 {
00220 
00221                 }
00222 
00223                 public:
00224                         static const char *getPathSeparator();
00225         };
00226 
00227 
00228         CPyExport *initPythonLib(NLAIC::IIO *Interface,char *pathWay);
00229         void endPythonInterface(CPyExport *Interface);
00230 }
00231 #endif

Generated on Tue Mar 16 06:35:04 2004 for NeL by doxygen 1.3.6