add yaze_python module
This commit is contained in:
@@ -74,6 +74,7 @@ if(APPLE)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
include(app/CMakeLists.txt)
|
include(app/CMakeLists.txt)
|
||||||
|
include(py/CMakeLists.txt)
|
||||||
# include(cli/CMakeLists.txt) Excluded for now, macOS include breaks action build
|
# include(cli/CMakeLists.txt) Excluded for now, macOS include breaks action build
|
||||||
|
|
||||||
if (UNIX)
|
if (UNIX)
|
||||||
|
|||||||
20
src/py/CMakeLists.txt
Normal file
20
src/py/CMakeLists.txt
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
find_package(Python3 COMPONENTS Interpreter Development REQUIRED)
|
||||||
|
|
||||||
|
add_library(
|
||||||
|
yaze_python
|
||||||
|
py/yaze_python.cc
|
||||||
|
)
|
||||||
|
|
||||||
|
set(PYTHON_HEADERS /Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/Headers)
|
||||||
|
|
||||||
|
target_include_directories(
|
||||||
|
yaze_python PUBLIC
|
||||||
|
lib/
|
||||||
|
app/
|
||||||
|
${PYTHON_HEADERS}
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(
|
||||||
|
yaze_python PUBLIC
|
||||||
|
Python
|
||||||
|
)
|
||||||
18
src/py/yaze_python.cc
Normal file
18
src/py/yaze_python.cc
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
#include "yaze_python.h"
|
||||||
|
|
||||||
|
#include <Python.h>
|
||||||
|
|
||||||
|
static PyObject *SpamError;
|
||||||
|
|
||||||
|
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(SpamError, "System command failed");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
return PyLong_FromLong(sts);
|
||||||
|
}
|
||||||
21
src/py/yaze_python.h
Normal file
21
src/py/yaze_python.h
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
#ifndef YAZE_PYTHON_H
|
||||||
|
#define YAZE_PYTHON_H
|
||||||
|
|
||||||
|
#include <Python.h>
|
||||||
|
|
||||||
|
static PyObject *yaze_init(PyObject *self, PyObject *args);
|
||||||
|
|
||||||
|
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); }
|
||||||
|
|
||||||
|
#endif // YAZE_PYTHON_H
|
||||||
Reference in New Issue
Block a user