Allow client code to provide their foreign_class_fn() implementation.
This commit is contained in:
parent
2c2d783730
commit
3d68124a60
2 changed files with 27 additions and 0 deletions
|
@ -55,6 +55,19 @@ namespace wren {
|
|||
auto retval = reinterpret_cast<WrenForeignMethodFn>(dfm->make(cb->owner, func));
|
||||
return retval;
|
||||
}
|
||||
|
||||
WrenForeignClassMethods foreign_class_fn (WrenVM* wvm, const char* module, const char* class_name) {
|
||||
auto cb = static_cast<detail::Callbacks*>(wrenGetUserData(wvm));
|
||||
assert(cb);
|
||||
assert(cb->foreign_class_fn and cb->config_obj and cb->owner);
|
||||
foreign_class_t funcs = cb->foreign_class_fn(*cb->config_obj, cb->owner, module, class_name);
|
||||
DynafuncMaker* const dfm = cb->dynafunc;
|
||||
assert(dfm);
|
||||
WrenForeignClassMethods retval;
|
||||
retval.allocate = reinterpret_cast<WrenForeignMethodFn>(dfm->make(cb->owner, funcs.allocate));
|
||||
retval.finalize = funcs.finalize;
|
||||
return retval;
|
||||
}
|
||||
} //unnamed namespace
|
||||
|
||||
struct VM::LocalData {
|
||||
|
@ -106,6 +119,9 @@ namespace wren {
|
|||
if (cb.foreign_method_fn)
|
||||
wconf.bindForeignMethodFn = &foreign_method_fn;
|
||||
|
||||
if (cb.foreign_class_fn)
|
||||
wconf.bindForeignClassFn = &foreign_class_fn;
|
||||
|
||||
m_local->wvm = wrenNewVM(&wconf);
|
||||
if (not m_local->wvm)
|
||||
throw std::runtime_error("Failed to initialize Wren VM");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue