/[ascend]/trunk/models/johnpye/extpy/extpy.c
ViewVC logotype

Diff of /trunk/models/johnpye/extpy/extpy.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 874 by johnpye, Thu Oct 5 15:13:22 2006 UTC revision 875 by johnpye, Sat Oct 7 06:26:34 2006 UTC
# Line 47  ImportHandlerImportFn extpy_import; Line 47  ImportHandlerImportFn extpy_import;
47  extern ASC_EXPORT(int) extpy_register(){  extern ASC_EXPORT(int) extpy_register(){
48      int result = 0;      int result = 0;
49    
     CONSOLE_DEBUG("Hello...");  
   
50      struct ImportHandler *handler;      struct ImportHandler *handler;
51      handler = ASC_NEW(struct ImportHandler);      handler = ASC_NEW(struct ImportHandler);
52    
# Line 80  ExtMethodRun extpy_invokemethod; Line 78  ExtMethodRun extpy_invokemethod;
78  */  */
79  int extpy_invokemethod(struct Instance *context, struct gl_list_t *args, void *user_data){  int extpy_invokemethod(struct Instance *context, struct gl_list_t *args, void *user_data){
80      PyObject *fn, *arglist, *result;      PyObject *fn, *arglist, *result;
81        PyObject *pycontext;
82      /* cast user data to PyObject pointer */      /* cast user data to PyObject pointer */
83    
84      CONSOLE_DEBUG("USER_DATA IS AT %p",user_data);      CONSOLE_DEBUG("USER_DATA IS AT %p",user_data);
# Line 96  int extpy_invokemethod(struct Instance * Line 95  int extpy_invokemethod(struct Instance *
95          return 1;          return 1;
96      }      }
97    
98        /*
99            We need to be able to convert C 'struct Instance' pointers to Python 'Instance' objects.
100            This functionality is implemented in 'ascpy' but we're not going to link to that here,
101            so we will use the importhandler 'getsharedpointer' trick to get hold of the
102            casting function, then run it here.
103        */
104        CONSOLE_DEBUG("ADDING 'context' AS SHARED POINTER");
105        importhandler_setsharedpointer("context",(void *)context);
106    
107      arglist = Py_BuildValue("(i)", 666);      arglist = Py_BuildValue("(i)", 666);
108        CONSOLE_DEBUG("BUILDING ARGLIST FOR PYTHON METHOD");
109    
110        CONSOLE_DEBUG("CALLING PYTHON");
111      result = PyEval_CallObject(fn, arglist);      result = PyEval_CallObject(fn, arglist);
112        CONSOLE_DEBUG("DONE CALLING PYTHON");
113      Py_DECREF(arglist);      Py_DECREF(arglist);
114    
115      if(PyErr_Occurred()){      if(PyErr_Occurred()){
116          ERROR_REPORTER_HERE(ASC_PROG_ERR,"Failed running python method");          PyErr_Print();
117            ERROR_REPORTER_HERE(ASC_PROG_ERR,"Failed running python method (see console)");
118          return 1;          return 1;
119      }      }
120    
# Line 238  int extpy_import(const struct FilePath * Line 252  int extpy_import(const struct FilePath *
252    
253      initextpy();      initextpy();
254    
255        if(PyRun_SimpleString("import ascpy")){
256            CONSOLE_DEBUG("Failed importing 'ascpy'");
257            return 1;
258        }
259    
260      pyfile = PyFile_FromString(name,"r");      pyfile = PyFile_FromString(name,"r");
261      if(pyfile==NULL){      if(pyfile==NULL){
262          CONSOLE_DEBUG("Failed opening script");          CONSOLE_DEBUG("Failed opening script");

Legend:
Removed from v.874  
changed lines
  Added in v.875

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22