From 594b2498e80bea2a755b8f6b74890b35a70939d6 Mon Sep 17 00:00:00 2001 From: scawful Date: Wed, 7 Aug 2024 17:00:57 -0400 Subject: [PATCH] move CPython code into yaze_c_py.cc --- src/py/yaze_c_py.cc | 34 ++++++++++++++++++++++++++++++++++ src/py/yaze_py.cc | 36 ------------------------------------ 2 files changed, 34 insertions(+), 36 deletions(-) create mode 100644 src/py/yaze_c_py.cc diff --git a/src/py/yaze_c_py.cc b/src/py/yaze_c_py.cc new file mode 100644 index 00000000..f4bf64fc --- /dev/null +++ b/src/py/yaze_c_py.cc @@ -0,0 +1,34 @@ +#include + +static PyObject *yaze_init(PyObject *self, PyObject *args); + +/** + * Python C API Example, in case I need more functionality than Boost.Python + */ +static PyMethodDef YazeMethods[] = { + {"system", yaze_init, METH_VARARGS, "Initialize the yaze lib."}, + {NULL, NULL, 0, NULL} /* Sentinel */ +}; + +static struct PyModuleDef yaze_module = {PyModuleDef_HEAD_INIT, + "yaze", // Module title + NULL, // Documentation + -1, // Interpreter state size + YazeMethods}; + +// PyMODINIT_FUNC PyInit_yaze(void) { return PyModule_Create(&yaze_module); } + +static PyObject *YazeError; + +static PyObject *yaze_init(PyObject *self, PyObject *args) { + const char *command; + int sts; + + if (!PyArg_ParseTuple(args, "s", &command)) return NULL; + sts = system(command); + if (sts < 0) { + PyErr_SetString(YazeError, "System command failed"); + return NULL; + } + return PyLong_FromLong(sts); +} \ No newline at end of file diff --git a/src/py/yaze_py.cc b/src/py/yaze_py.cc index 4372c1d3..24aa1744 100644 --- a/src/py/yaze_py.cc +++ b/src/py/yaze_py.cc @@ -1,16 +1,11 @@ -#include - #include #include "base/snes_color.h" #include "base/sprite.h" #include "yaze.h" -static PyObject *yaze_init(PyObject *self, PyObject *args); - BOOST_PYTHON_MODULE(yaze) { using namespace boost::python; - def("yaze_init", yaze_init); class_("rom") .def_readonly("filename", &rom::filename) @@ -37,34 +32,3 @@ BOOST_PYTHON_MODULE(yaze) { .def_readonly("id", &sprite::id) .def_readonly("actions", &sprite::actions); } - -/** - * Python C API Example, in case I need more functionality than Boost.Python - */ -static PyMethodDef YazeMethods[] = { - {"system", yaze_init, METH_VARARGS, "Initialize the yaze lib."}, - {NULL, NULL, 0, NULL} /* Sentinel */ -}; - -static struct PyModuleDef yaze_module = {PyModuleDef_HEAD_INIT, - "yaze", // Module title - NULL, // Documentation - -1, // Interpreter state size - YazeMethods}; - -// PyMODINIT_FUNC PyInit_yaze(void) { return PyModule_Create(&yaze_module); } - -static PyObject *YazeError; - -static PyObject *yaze_init(PyObject *self, PyObject *args) { - const char *command; - int sts; - - if (!PyArg_ParseTuple(args, "s", &command)) return NULL; - sts = system(command); - if (sts < 0) { - PyErr_SetString(YazeError, "System command failed"); - return NULL; - } - return PyLong_FromLong(sts); -} \ No newline at end of file