From bc29f43bbd0758ff258b79dda40e7f45c4574ea8 Mon Sep 17 00:00:00 2001 From: Bob Nystrom Date: Mon, 27 Jun 2016 07:08:08 -0700 Subject: [PATCH] Allow hosts with no module loader to still load optional modules. If the host doesn't set a loadModuleFn at all in the config, it should still be able to load random, meta, etc. --- src/vm/wren_vm.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/vm/wren_vm.c b/src/vm/wren_vm.c index 4163cf0f..6bad8bc1 100644 --- a/src/vm/wren_vm.c +++ b/src/vm/wren_vm.c @@ -1339,10 +1339,15 @@ Value wrenImportModule(WrenVM* vm, Value name) { // If the module is already loaded, we don't need to do anything. if (!IS_UNDEFINED(wrenMapGet(vm->modules, name))) return NULL_VAL; - - // Load the module's source code from the host. - const char* source = vm->config.loadModuleFn(vm, AS_CSTRING(name)); - + + const char* source = NULL; + + // Let the host try to provide the module. + if (vm->config.loadModuleFn != NULL) + { + source = vm->config.loadModuleFn(vm, AS_CSTRING(name)); + } + // If the host didn't provide it, see if it's a built in optional module. if (source == NULL) {