/[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 867 by johnpye, Fri Sep 29 11:25:47 2006 UTC revision 869 by johnpye, Wed Oct 4 14:03:46 2006 UTC
# Line 15  Line 15 
15      along with this program; if not, write to the Free Software      along with this program; if not, write to the Free Software
16      Foundation, Inc., 59 Temple Place - Suite 330,      Foundation, Inc., 59 Temple Place - Suite 330,
17      Boston, MA 02111-1307, USA.      Boston, MA 02111-1307, USA.
18    *//**
19        @file
20        Import handler to provide external python script functionality for ASCEND.
21  */  */
22    
23  #include <stdio.h>  #include <stdio.h>
# Line 60  extern ASC_EXPORT(int) extpy_register(){ Line 63  extern ASC_EXPORT(int) extpy_register(){
63      return result;      return result;
64  }  }
65    
66    /*------------------------------------------------------------------------------
67      METHODS TO EXPOSE DATA TO THE EXTERNAL SCRIPT
68    */
69    
70    /* Return the number of arguments of the application command line */
71    static PyObject *extpy_getbrowser(PyObject *self, PyObject *args){
72        PyObject *browser;
73        if(args!=NULL){
74            ERROR_REPORTER_HERE(ASC_PROG_ERR,"args is not NULL?!");
75        }
76        browser = (PyObject *)importhandler_getsharedpointer("browser");
77        return Py_BuildValue("O",browser);
78    }
79    
80    static PyMethodDef extpymethods[] = {
81        {"getbrowser", extpy_getbrowser, METH_NOARGS,"Retrieve browser pointer"}
82        ,{NULL,NULL,0,NULL}
83    };
84    
85    PyMODINIT_FUNC initextpy(void){
86        PyObject *obj;
87        CONSOLE_DEBUG("registering 'extpy' module...");
88        obj = Py_InitModule3("extpy", extpymethods,"Module for accessing shared ASCEND pointers from python");
89        CONSOLE_DEBUG("returned %p",obj);
90        CONSOLE_DEBUG("name %s",PyModule_GetName(obj));
91    }
92    
93    /*------------------------------------------------------------------------------
94      STANDARD IMPORT HANDLER ROUTINES
95    */
96    
97  /**  /**
98      Create a filename base on a partial filename. In that case of python, this      Create a filename base on a partial filename. In that case of python, this
99      just means adding '.py' to the end.      just means adding '.py' to the end.
# Line 107  int extpy_import(const struct FilePath * Line 141  int extpy_import(const struct FilePath *
141          return 1;          return 1;
142      }      }
143      PyRun_SimpleString("print \"HELLO FROM PYTHON IN C\"");      PyRun_SimpleString("print \"HELLO FROM PYTHON IN C\"");
   
144      PyRun_SimpleString("import ascpy");      PyRun_SimpleString("import ascpy");
145        PyRun_SimpleString("L = ascpy.Library()");
146        PyRun_SimpleString("print \"IMPORTED ASCPY\"");
147        PyRun_SimpleString("print L");
148    
149        initextpy();
150    
151      f = fopen(name,"r");      f = fopen(name,"r");
152      PyRun_AnyFile(f,name);      PyRun_AnyFile(f,name);
153      fclose(f);      fclose(f);

Legend:
Removed from v.867  
changed lines
  Added in v.869

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