Adding the module but it's not working yet
This commit is contained in:
parent
719a57d3e8
commit
33b74fc7e4
3 changed files with 102 additions and 0 deletions
81
src/pywrenppmodule.cpp
Normal file
81
src/pywrenppmodule.cpp
Normal file
|
@ -0,0 +1,81 @@
|
|||
#define PY_SSIZE_T_CLEAN
|
||||
#include <Python.h>
|
||||
#include "wrenpp/vm.hpp"
|
||||
#include "wrenpp/def_configuration.hpp"
|
||||
#include "config.h"
|
||||
|
||||
#define CURR_MODULE_NAME WRENPP_NAME
|
||||
|
||||
namespace {
|
||||
struct VMObject;
|
||||
int vm_init (VMObject* self, PyObject*, PyObject*);
|
||||
|
||||
class VMConfig : public wren::DefConfiguration {
|
||||
public:
|
||||
wren::foreign_method_t foreign_method_fn (
|
||||
wren::VM* vm,
|
||||
const char* module_ptr,
|
||||
const char* class_name_ptr,
|
||||
bool is_static,
|
||||
const char* signature_ptr
|
||||
) {
|
||||
return nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
PyMethodDef WrenppMethods[] = {
|
||||
//{"eval_script", &eval_script, METH_VARARGS, "Evaluate a Wren script"},
|
||||
{nullptr, nullptr, 0, nullptr}
|
||||
};
|
||||
|
||||
struct PyModuleDef WrenppModule = {
|
||||
PyModuleDef_HEAD_INIT,
|
||||
CURR_MODULE_NAME, //module name
|
||||
"Python bindings for Wrenpp", //module documentation
|
||||
-1, //size of per-interpreter state of the module, or -1 if the module keeps state in global variables
|
||||
WrenppMethods
|
||||
};
|
||||
|
||||
struct VMObject {
|
||||
PyObject_HEAD
|
||||
wren::VM vm;
|
||||
};
|
||||
|
||||
PyTypeObject VMType = {
|
||||
PyVarObject_HEAD_INIT(NULL, 0)
|
||||
.tp_name = CURR_MODULE_NAME ".VM",
|
||||
.tp_basicsize = sizeof(VMObject),
|
||||
.tp_itemsize = 0,
|
||||
.tp_flags = Py_TPFLAGS_DEFAULT,
|
||||
.tp_doc = "Wrenpp VM",
|
||||
.tp_init = reinterpret_cast<initproc>(vm_init),
|
||||
.tp_new = PyType_GenericNew,
|
||||
};
|
||||
|
||||
int vm_init (VMObject* self, PyObject* /*args*/, PyObject* /*kwds*/) {
|
||||
try {
|
||||
VMConfig config;
|
||||
new(&self->vm) wren::VM(&config, nullptr);
|
||||
}
|
||||
catch (...) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
} //unnamed namespace
|
||||
|
||||
PyMODINIT_FUNC PyInit_wrenpp(void) {
|
||||
if (PyType_Ready(&VMType) < 0)
|
||||
return nullptr;
|
||||
PyObject* const m = PyModule_Create(&WrenppModule);
|
||||
if (not m)
|
||||
return nullptr;
|
||||
|
||||
Py_INCREF(&VMType);
|
||||
if (PyModule_AddObject(m, "VM", reinterpret_cast<PyObject*>(&VMType)) < 0) {
|
||||
Py_DECREF(&VMType);
|
||||
Py_DECREF(m);
|
||||
return nullptr;
|
||||
}
|
||||
return m;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue