Update wren to latest and fix build

This commit is contained in:
King_DuckZ 2022-04-22 22:02:59 +02:00
parent b4383e9449
commit 0255edb8be
3 changed files with 39 additions and 6 deletions

View file

@ -44,7 +44,7 @@ namespace wren {
};
enum class SlotType {
Bool, Num, Foreign, List, Null, String, Unknown
Bool, Num, Foreign, List, Null, String, Unknown, Map
};
namespace detail {
@ -56,6 +56,7 @@ namespace wren {
char* (*load_module_fn)(Configuration&, VM*, const char*) {nullptr};
foreign_method_t (*foreign_method_fn)(Configuration&, VM*, const char*, const char*, bool, const char*) {nullptr};
foreign_class_t (*foreign_class_fn)(Configuration&, VM*, const char*, const char*) {nullptr};
void (*load_module_complete_fn)(Configuration&, VM*, const char*);
Configuration* config_obj {nullptr};
VM* owner {nullptr};

View file

@ -34,6 +34,21 @@ namespace wren {
};
}
void load_module_complete_fn (WrenVM* wvm, const char* name, struct WrenLoadModuleResult result);
WrenLoadModuleResult to_wren_load_module_result (
const char* source,
const detail::Callbacks& cb,
void* user_data
) {
assert(cb.owner);
return ::WrenLoadModuleResult{
.source = source,
.onComplete = (cb.load_module_complete_fn ? &load_module_complete_fn : nullptr),
.userData = user_data
};
}
void write_fn (WrenVM* wvm, const char* text) {
auto cb = static_cast<detail::Callbacks*>(wrenGetUserData(wvm));
assert(cb);
@ -55,11 +70,19 @@ namespace wren {
return cb->resolve_module_fn(*cb->config_obj, cb->owner, importer, name);
}
char* load_module_fn (WrenVM* wvm, const char* name) {
auto cb = static_cast<detail::Callbacks*>(wrenGetUserData(wvm));
void* reallocate_fn (void* memory, size_t size, void* user_data) {
auto cb = static_cast<detail::Callbacks*>(user_data);
assert(cb);
assert(cb->reallocate_fn);
return cb->reallocate_fn(memory, size);
}
WrenLoadModuleResult load_module_fn (WrenVM* wvm, const char* name) {
const auto user_data = wrenGetUserData(wvm);
auto cb = static_cast<detail::Callbacks*>(user_data);
assert(cb);
assert(cb->load_module_fn and cb->config_obj and cb->owner);
return cb->load_module_fn(*cb->config_obj, cb->owner, name);
return to_wren_load_module_result(cb->load_module_fn(*cb->config_obj, cb->owner, name), *cb, user_data);
}
WrenForeignMethodFn foreign_method_fn (WrenVM* wvm, const char* module, const char* class_name, bool is_static, const char* signature) {
@ -78,6 +101,14 @@ namespace wren {
}
}
void load_module_complete_fn (WrenVM* wvm, const char* name, struct WrenLoadModuleResult result) {
auto cb = static_cast<detail::Callbacks*>(wrenGetUserData(wvm));
assert(cb);
assert(cb->load_module_complete_fn and cb->config_obj and cb->owner);
(*cb->load_module_complete_fn)(*cb->config_obj, cb->owner, name);
}
WrenForeignClassMethods foreign_class_fn (WrenVM* wvm, const char* module, const char* class_name) {
auto cb = static_cast<detail::Callbacks*>(wrenGetUserData(wvm));
assert(cb);
@ -260,7 +291,7 @@ namespace wren {
wconf.errorFn = &error_fn;
if (cb.reallocate_fn)
wconf.reallocateFn = cb.reallocate_fn;
wconf.reallocateFn = &reallocate_fn;
if (cb.resolve_module_fn)
wconf.resolveModuleFn = &resolve_module_fn;
@ -310,6 +341,7 @@ namespace wren {
case WREN_TYPE_STRING: return SlotType::String;
case WREN_TYPE_FOREIGN: return SlotType::Foreign;
case WREN_TYPE_UNKNOWN: return SlotType::Unknown;
case WREN_TYPE_MAP: return SlotType::Map;
};
assert(false);
return SlotType::Unknown;

@ -1 +1 @@
Subproject commit 4a18fc489f9ea3d253b20dd40f4cdad0d6bb40eb
Subproject commit 4ffe2ed38b238ff410e70654cbe38883f7533d3f