Advertisement
Guest User

Untitled

a guest
Mar 14th, 2015
513
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.78 KB | None | 0 0
  1. #include "PythonrootlibManager.h"
  2. #include "Python.h"
  3. #ifdef _DEBUG
  4.     #pragma comment (lib, "rootlib_d.lib")
  5. #else
  6.     #pragma comment (lib, "rootlib.lib")
  7. #endif
  8.  
  9. struct SMethodDef
  10. {
  11.     char* func_name;
  12.     void (*func)();
  13. };
  14.  
  15. PyMODINIT_FUNC initPrototype();
  16. PyMODINIT_FUNC initserverInfo();
  17. PyMODINIT_FUNC initsystem();
  18.  
  19. SMethodDef rootlib_init_methods[] =
  20. {
  21.     { "Prototype", initPrototype },
  22.     { "serverInfo", initserverInfo },
  23.     { "system", initsystem },
  24.     { NULL, NULL },
  25. };
  26.  
  27. static PyObject* isExist(PyObject *self, PyObject *args)
  28. {
  29.     char* func_name;
  30.  
  31.     if(!PyArg_ParseTuple(args, "s", &func_name))
  32.         return NULL;
  33.  
  34.     for (int i = 0; NULL != rootlib_init_methods[i].func_name;i++)
  35.     {
  36.         if (0 == strcmp(rootlib_init_methods[i].func_name, func_name))
  37.         {
  38.             return Py_BuildValue("i", 1);
  39.         }
  40.     }
  41.     return Py_BuildValue("i", 0);
  42. }
  43.  
  44. static PyObject* import(PyObject *self, PyObject *args)
  45. {
  46.     char* func_name;
  47.  
  48.     if(!PyArg_ParseTuple(args, "s", &func_name))
  49.         return NULL;
  50.  
  51.     for (int i = 0; NULL != rootlib_init_methods[i].func_name;i++)
  52.     {
  53.         if (0 == strcmp(rootlib_init_methods[i].func_name, func_name))
  54.         {
  55.             rootlib_init_methods[i].func();
  56.             if (PyErr_Occurred())
  57.                 return NULL;
  58.             PyObject* m = PyDict_GetItemString(PyImport_GetModuleDict(), func_name);
  59.             if (m == NULL) {
  60.                 PyErr_SetString(PyExc_SystemError,
  61.                     "dynamic module not initialized properly");
  62.                 return NULL;
  63.             }
  64.             Py_INCREF(m);
  65.             return Py_BuildValue("S", m);
  66.         }
  67.     }
  68.     return NULL;
  69. }
  70.  
  71.  
  72. void initrootlibManager()
  73. {
  74.     static struct PyMethodDef methods[] =
  75.     {
  76.         {"isExist", isExist, METH_VARARGS},
  77.         {"moduleImport", import, METH_VARARGS}, // "import"¶ó´Â À̸§Àº keyword¶ó »ç¿ë ¸øÇÔ...
  78.         {NULL, NULL},
  79.     };
  80.  
  81.     PyObject* m;
  82.     m = Py_InitModule("rootlib", methods);
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement