From aa7f5b47453131339440a2970de6665316a67b5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Sun, 17 Nov 2019 15:42:17 +0100 Subject: [PATCH] plugins: python-renderer: Implement first gds_render built-in module with a get_number function --- .../python-renderer/gds-render-module.h | 6 +++++ .../python-renderer/src/gds-render-module.c | 27 +++++++++++++++++++ plugins/python-renderer/src/plugin-main.c | 8 ++++++ 3 files changed, 41 insertions(+) diff --git a/plugins/python-renderer/include/python-renderer/gds-render-module.h b/plugins/python-renderer/include/python-renderer/gds-render-module.h index efd8707..dd37a5b 100644 --- a/plugins/python-renderer/include/python-renderer/gds-render-module.h +++ b/plugins/python-renderer/include/python-renderer/gds-render-module.h @@ -31,7 +31,13 @@ * @{ */ +#include +/** + * @brief Set up the gds_render python module + * @return New module reference + */ +PyObject *init_gds_render_module(); /** @} */ diff --git a/plugins/python-renderer/src/gds-render-module.c b/plugins/python-renderer/src/gds-render-module.c index 4749bc4..9f1cf33 100644 --- a/plugins/python-renderer/src/gds-render-module.c +++ b/plugins/python-renderer/src/gds-render-module.c @@ -24,3 +24,30 @@ */ #include + +static PyObject *test(PyObject *self, PyObject *args) +{ + if(!PyArg_ParseTuple(args, ":numargs")) + return NULL; + + return PyLong_FromLong(20UL); +} + +static PyMethodDef gds_render_methods[] = { + {"get_number", test, METH_VARARGS, + "Return the number of arguments received by the process."}, + {NULL, NULL, 0, NULL} +}; + +static PyModuleDef gds_render_module = { + PyModuleDef_HEAD_INIT, "gds_render", NULL, -1, gds_render_methods, + NULL, NULL, NULL, NULL +}; + +PyObject *init_gds_render_module(void) +{ + PyObject *this_module; + + this_module = PyModule_Create(&gds_render_module); + return this_module; +} diff --git a/plugins/python-renderer/src/plugin-main.c b/plugins/python-renderer/src/plugin-main.c index 5dc7bf1..8c6afcd 100644 --- a/plugins/python-renderer/src/plugin-main.c +++ b/plugins/python-renderer/src/plugin-main.c @@ -88,12 +88,20 @@ int FUNC_DECL(EXTERNAL_LIBRARY_INIT_FUNCTION)(const char *params, const char *ve PyObject *p_name; PyObject *p_sys_path; PyObject *p_cwd_string; + PyObject *gds_render_module; char cwd[256]; if (!params || !version) return -1000; printf("Init with params: %s\ngds-render version: %s\n", params, version); + + ret = PyImport_AppendInittab("gds_render", &init_gds_render_module); + if (ret) { + fprintf(stderr, "Registration of gds_render python module failed\n"); + goto return_value; + } + Py_Initialize(); if (!getcwd(cwd, sizeof(cwd))) {