diff options
author | manojgudi | 2013-07-23 07:54:12 +0530 |
---|---|---|
committer | manojgudi | 2013-07-23 07:54:12 +0530 |
commit | 43114165fb5e59c4267991f4922970c897fe2d88 (patch) | |
tree | c4cd97ed682dd75c0efa8991243b04b13633e270 /callpython/callpython.c | |
download | sciscipy-1.0.0-43114165fb5e59c4267991f4922970c897fe2d88.tar.gz sciscipy-1.0.0-43114165fb5e59c4267991f4922970c897fe2d88.tar.bz2 sciscipy-1.0.0-43114165fb5e59c4267991f4922970c897fe2d88.zip |
initial commit
Diffstat (limited to 'callpython/callpython.c')
-rw-r--r-- | callpython/callpython.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/callpython/callpython.c b/callpython/callpython.c new file mode 100644 index 0000000..5b1c101 --- /dev/null +++ b/callpython/callpython.c @@ -0,0 +1,39 @@ +#include <Python.h>
+
+void py_initialize_c()
+{
+ Py_Initialize() ;
+}
+
+void py_finalize_c()
+{
+ Py_Finalize() ;
+}
+
+void py_eval_c(char * exec_str)
+{
+ PyRun_SimpleString(exec_str) ;
+}
+
+// Read an integer value
+// @in py_var: the name of the python var to read
+// @out sci_var: the return variable
+void py_read_int_c(char * py_var, int * sci_var)
+{
+ PyObject* main_module = PyImport_AddModule("__main__") ;
+ PyObject* main_dict = PyModule_GetDict(main_module) ;
+
+ if (PyDict_Contains(main_dict, PyString_FromString(py_var)))
+ {
+ PyObject * py_int = PyDict_GetItem(main_dict, PyString_FromString(py_var)) ;
+ if (PyInt_Check(py_int)){
+
+ *sci_var = PyInt_AS_LONG(py_int) ;
+ return ;
+ }
+ // Handle not an int error
+ return ;
+ }
+ // Handle var not found error
+ *sci_var = 0 ;
+}
\ No newline at end of file |