37 lines
996 B
C
37 lines
996 B
C
#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);
|
|
}
|