plugins: python renderer: Add GdsPoint object type definition to gds_render module. This is still playing around as I don't really know what I'm doing at the moment.
This commit is contained in:
parent
dd2f21c5cd
commit
2420b80c9e
@ -33,6 +33,11 @@
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
/**
|
||||
* @brief The gds_render python module name as string
|
||||
*/
|
||||
#define GDS_RENDER_MOD_NAME "gds_render"
|
||||
|
||||
/**
|
||||
* @brief Set up the gds_render python module
|
||||
* @return New module reference
|
||||
|
@ -24,6 +24,22 @@
|
||||
*/
|
||||
|
||||
#include <python-renderer/gds-render-module.h>
|
||||
#include <gds-render/gds-utils/gds-types.h>
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
/* TODO: Fill in type specific fields */
|
||||
} GdsPointObject;
|
||||
|
||||
static PyTypeObject GdsPointType = {
|
||||
PyVarObject_HEAD_INIT(NULL, 0)
|
||||
.tp_name = GDS_RENDER_MOD_NAME ".GdsPoint",
|
||||
.tp_doc = "2D Gds Database Point",
|
||||
.tp_basicsize = sizeof(GdsPointObject),
|
||||
.tp_itemsize = 0,
|
||||
.tp_flags = Py_TPFLAGS_DEFAULT,
|
||||
.tp_new = PyType_GenericNew,
|
||||
};
|
||||
|
||||
static PyObject *test(PyObject *self, PyObject *args)
|
||||
{
|
||||
@ -32,7 +48,7 @@ static PyObject *test(PyObject *self, PyObject *args)
|
||||
if(!PyArg_ParseTuple(args, "l:get_number", &i))
|
||||
return NULL;
|
||||
|
||||
i *= 2;
|
||||
i *= i;
|
||||
|
||||
return PyLong_FromLong(i);
|
||||
}
|
||||
@ -42,15 +58,57 @@ static PyMethodDef gds_render_methods[] = {
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
static PyModuleDef gds_render_module = {
|
||||
PyModuleDef_HEAD_INIT, "gds_render", NULL, -1, gds_render_methods,
|
||||
static PyModuleDef gds_render_module_def = {
|
||||
PyModuleDef_HEAD_INIT,
|
||||
.m_name = GDS_RENDER_MOD_NAME,
|
||||
.m_doc = "GDS Render Base App Module",
|
||||
.m_size = -1,
|
||||
.m_methods = gds_render_methods,
|
||||
NULL, NULL, NULL, NULL
|
||||
};
|
||||
|
||||
static int gds_render_module_check_types_ready()
|
||||
{
|
||||
if (PyType_Ready(&GdsPointType) < 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int gds_render_module_add_types(PyObject *module)
|
||||
{
|
||||
int err;
|
||||
|
||||
Py_INCREF(&GdsPointType);
|
||||
err = PyModule_AddObject(module, "GdsPoint", (PyObject *)&GdsPointType);
|
||||
if (err < 0) {
|
||||
goto decref_gds_point;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
decref_gds_point:
|
||||
Py_DECREF(&GdsPointType);
|
||||
return -1;
|
||||
}
|
||||
|
||||
PyObject *init_gds_render_module(void)
|
||||
{
|
||||
PyObject *this_module;
|
||||
int err;
|
||||
PyObject *gds_render_module;
|
||||
|
||||
this_module = PyModule_Create(&gds_render_module);
|
||||
return this_module;
|
||||
if (gds_render_module_check_types_ready())
|
||||
return NULL;
|
||||
|
||||
gds_render_module = PyModule_Create(&gds_render_module_def);
|
||||
|
||||
err = gds_render_module_add_types(gds_render_module);
|
||||
if (err) {
|
||||
Py_DECREF(gds_render_module);
|
||||
gds_render_module = NULL;
|
||||
goto return_module;
|
||||
}
|
||||
|
||||
return_module:
|
||||
return gds_render_module;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user