plugins: python-renderer: Implement first gds_render built-in module with a get_number function
This commit is contained in:
parent
71b500e030
commit
aa7f5b4745
@ -31,7 +31,13 @@
|
|||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <Python.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set up the gds_render python module
|
||||||
|
* @return New module reference
|
||||||
|
*/
|
||||||
|
PyObject *init_gds_render_module();
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
|
@ -24,3 +24,30 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <python-renderer/gds-render-module.h>
|
#include <python-renderer/gds-render-module.h>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
@ -88,12 +88,20 @@ int FUNC_DECL(EXTERNAL_LIBRARY_INIT_FUNCTION)(const char *params, const char *ve
|
|||||||
PyObject *p_name;
|
PyObject *p_name;
|
||||||
PyObject *p_sys_path;
|
PyObject *p_sys_path;
|
||||||
PyObject *p_cwd_string;
|
PyObject *p_cwd_string;
|
||||||
|
PyObject *gds_render_module;
|
||||||
char cwd[256];
|
char cwd[256];
|
||||||
|
|
||||||
if (!params || !version)
|
if (!params || !version)
|
||||||
return -1000;
|
return -1000;
|
||||||
|
|
||||||
printf("Init with params: %s\ngds-render version: %s\n", params, version);
|
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();
|
Py_Initialize();
|
||||||
|
|
||||||
if (!getcwd(cwd, sizeof(cwd))) {
|
if (!getcwd(cwd, sizeof(cwd))) {
|
||||||
|
Loading…
Reference in New Issue
Block a user