Write simple initialization function as well as a test function.
This commit is contained in:
36
src/pyliblexmodule.c
Normal file
36
src/pyliblexmodule.c
Normal file
@@ -0,0 +1,36 @@
|
||||
#include "pyliblexmodule.h"
|
||||
#include "liblex.h"
|
||||
#include "eval.h"
|
||||
|
||||
static void _pyliblex_free_eval(PyObject* object){
|
||||
eval_config* config = PyCapsule_GetPointer(object, NULL);
|
||||
if(config){
|
||||
liblex_result result = eval_config_free(config);
|
||||
if(result != LIBLEX_SUCCESS){
|
||||
PyErr_NoMemory();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static PyObject* pyliblex_init(PyObject* self, PyObject* args){
|
||||
PyObject* return_object = NULL;
|
||||
eval_config* config = malloc(sizeof(*config));
|
||||
|
||||
if(config){
|
||||
eval_config_init(config);
|
||||
return_object = PyCapsule_New(config, NULL, _pyliblex_free_eval);
|
||||
} else {
|
||||
return_object = PyErr_NoMemory();
|
||||
}
|
||||
|
||||
return return_object;
|
||||
}
|
||||
static PyObject* pyliblex_add_definitions(PyObject* self, PyObject* args);
|
||||
static PyObject* pyliblex_lex(PyObject* self, PyObject* args);
|
||||
static PyObject* pyliblex_test(PyObject* self, PyObject* args) {
|
||||
return PyUnicode_FromString("Test from liblex!");
|
||||
}
|
||||
|
||||
PyMODINIT_FUNC PyInit_pyliblex() {
|
||||
return PyModule_Create(&module_object);
|
||||
}
|
||||
Reference in New Issue
Block a user