diff --git a/builtin/core.wren b/builtin/core.wren index 0bc2fb51..33e753c4 100644 --- a/builtin/core.wren +++ b/builtin/core.wren @@ -60,9 +60,7 @@ class Sequence { class String is Sequence { import_(variable) { - var result = loadModule_ - if (result != null) result.call - + loadModule_ return lookUpVariable_(variable) } } diff --git a/src/wren_core.c b/src/wren_core.c index e304cb18..fdbd2e6b 100644 --- a/src/wren_core.c +++ b/src/wren_core.c @@ -103,9 +103,7 @@ static const char* libSource = "\n" "class String is Sequence {\n" " import_(variable) {\n" -" var result = loadModule_\n" -" if (result != null) result.call\n" -"\n" +" loadModule_\n" " return lookUpVariable_(variable)\n" " }\n" "}\n" @@ -1308,6 +1306,13 @@ DEF_NATIVE(string_loadModule) // If it returned a string, it was an error message. if (IS_STRING(args[0])) return PRIM_ERROR; + // If it returned a fiber, we want to call it. + if (IS_FIBER(args[0])) + { + AS_FIBER(args[0])->caller = fiber; + return PRIM_RUN_FIBER; + } + return PRIM_VALUE; } diff --git a/src/wren_value.h b/src/wren_value.h index 34a6bd2e..eb8e0ee9 100644 --- a/src/wren_value.h +++ b/src/wren_value.h @@ -455,6 +455,9 @@ typedef struct // Returns true if [value] is a closure. #define IS_CLOSURE(value) (wrenIsObjType(value, OBJ_CLOSURE)) +// Returns true if [value] is a fiber. +#define IS_FIBER(value) (wrenIsObjType(value, OBJ_FIBER)) + // Returns true if [value] is a function object. #define IS_FN(value) (wrenIsObjType(value, OBJ_FN))