diff --git a/src/wren/vm.cpp b/src/wren/vm.cpp index d0d01b7..3acd89a 100644 --- a/src/wren/vm.cpp +++ b/src/wren/vm.cpp @@ -67,10 +67,15 @@ namespace wren { assert(cb); assert(cb->foreign_method_fn and cb->config_obj and cb->owner); foreign_method_t func = cb->foreign_method_fn(*cb->config_obj, cb->owner, module, class_name, is_static, signature); - DynafuncMaker* const dfm = cb->dynafunc; - assert(dfm); - auto retval = reinterpret_cast(dfm->make(cb->owner, func)); - return retval; + if (func) { + DynafuncMaker* const dfm = cb->dynafunc; + assert(dfm); + auto retval = reinterpret_cast(dfm->make(cb->owner, func)); + return retval; + } + else { + return nullptr; + } } WrenForeignClassMethods foreign_class_fn (WrenVM* wvm, const char* module, const char* class_name) { @@ -78,10 +83,15 @@ namespace wren { 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(dfm->make(cb->owner, funcs.allocate)); + if (funcs.allocate) { + DynafuncMaker* const dfm = cb->dynafunc; + assert(dfm); + retval.allocate = reinterpret_cast(dfm->make(cb->owner, funcs.allocate)); + } + else { + retval.allocate = nullptr; + } retval.finalize = funcs.finalize; return retval; }