From 43114165fb5e59c4267991f4922970c897fe2d88 Mon Sep 17 00:00:00 2001 From: manojgudi Date: Tue, 23 Jul 2013 07:54:12 +0530 Subject: initial commit --- callpython/callpython.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 callpython/callpython.c (limited to 'callpython/callpython.c') 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 + +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 -- cgit