/[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 864 by johnpye, Thu Sep 28 13:39:16 2006 UTC revision 865 by johnpye, Thu Sep 28 14:19:17 2006 UTC
# Line 26  Line 26 
26    
27  #include <compiler/importhandler.h>  #include <compiler/importhandler.h>
28    
29    #include <Python.h>
30    
31  ImportHandlerCreateFilenameFn extpy_filename;  ImportHandlerCreateFilenameFn extpy_filename;
32  ImportHandlerImportFn extpy_import;  ImportHandlerImportFn extpy_import;
33    
# Line 77  char *extpy_filename(const char *partial Line 79  char *extpy_filename(const char *partial
79      name = ASC_NEW_ARRAY_CLEAR(char,len+4);      name = ASC_NEW_ARRAY_CLEAR(char,len+4);
80      strcpy(name,partialname);      strcpy(name,partialname);
81      strcat(name,".py");      strcat(name,".py");
82      CONSOLE_DEBUG("New filename is %s",name);      CONSOLE_DEBUG("New filename is '%s'",name);
83      return name;      return name;
84  }  }
85    
# Line 89  char *extpy_filename(const char *partial Line 91  char *extpy_filename(const char *partial
91  int extpy_import(const struct FilePath *fp, const char *initfunc, const char *partialpath){  int extpy_import(const struct FilePath *fp, const char *initfunc, const char *partialpath){
92      char *name;      char *name;
93      name = ospath_str(fp);      name = ospath_str(fp);
94        FILE *f;
95    
96      CONSOLE_DEBUG("IMPORTING PYTHON SCRIPT %s",name);      CONSOLE_DEBUG("IMPORTING PYTHON SCRIPT %s",name);
97        if(Py_IsInitialized()){
98            CONSOLE_DEBUG("PYTHON IS ALREADY INITIALISED");
99        }else{
100            CONSOLE_DEBUG("INITIALISING PYTHON");
101            Py_Initialize();
102        }
103    
104        PyRun_SimpleString("import ascpy");
105        f = fopen(name,"r");
106        PyRun_AnyFile(f,name);
107        fclose(f);
108    
109      ASC_FREE(name);      ASC_FREE(name);
110      return 0;      return 1;
111  }  }
112    

Legend:
Removed from v.864  
changed lines
  Added in v.865

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