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
20
meson.build
20
meson.build
|
@ -4,6 +4,8 @@ project('wrenpp', 'cpp',
|
|||
default_options: ['buildtype=release', 'cpp_std=c++17', 'b_ndebug=if-release'],
|
||||
)
|
||||
|
||||
pymod = import('python')
|
||||
|
||||
wren_dep = dependency('wren', version: '>=0.2.0',
|
||||
fallback: ['wren', 'wren_dep'],
|
||||
default_options: [
|
||||
|
@ -14,6 +16,10 @@ wren_dep = dependency('wren', version: '>=0.2.0',
|
|||
],
|
||||
static: true,
|
||||
)
|
||||
python = pymod.find_installation('python3',
|
||||
required: get_option('wrenpp_with_python'),
|
||||
disabler: true
|
||||
)
|
||||
public_incl = include_directories('include')
|
||||
|
||||
os = host_machine.system()
|
||||
|
@ -65,6 +71,20 @@ wrenpp_dep = declare_dependency(
|
|||
include_directories: public_incl,
|
||||
)
|
||||
|
||||
python.extension_module('py' + meson.project_name(),
|
||||
sources: [
|
||||
'src/pywrenppmodule.cpp',
|
||||
],
|
||||
dependencies: [
|
||||
python.dependency(
|
||||
version: '>=3.6.0',
|
||||
required: get_option('wrenpp_with_python'),
|
||||
),
|
||||
wrenpp_dep,
|
||||
],
|
||||
install: true,
|
||||
)
|
||||
|
||||
if get_option('build_examples')
|
||||
subdir('examples')
|
||||
endif
|
||||
|
|
|
@ -2,3 +2,4 @@ option('build_testing', type: 'boolean', value: false)
|
|||
option('build_examples', type: 'boolean', value: false)
|
||||
option('wren_with_rand', type: 'boolean', value: false, yield: true)
|
||||
option('wren_with_meta', type: 'boolean', value: false, yield: true)
|
||||
option('wrenpp_with_python', type: 'feature', value: 'disabled')
|
||||
|
|
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…
Reference in a new issue