diff options
| author | ruki <[email protected]> | 2024-04-24 22:40:46 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2024-04-24 22:40:46 +0800 |
| commit | d0e21bb8be22356b462aa1b266b43d1f2475535e (patch) | |
| tree | 6bcff67ecf65ba37a888c4e30f567fd8f40b0fec /xmake/core/base | |
| parent | b6d0f628731758b8e1a9bffbdf5f30d3ab4bc9a1 (diff) | |
improve apis
Diffstat (limited to 'xmake/core/base')
| -rw-r--r-- | xmake/core/base/interpreter.lua | 30 |
1 files changed, 2 insertions, 28 deletions
diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua index 1c85d870e..c8cdd9773 100644 --- a/xmake/core/base/interpreter.lua +++ b/xmake/core/base/interpreter.lua @@ -604,32 +604,24 @@ function interpreter:_script(script) end -- get builtin modules -function interpreter._builtin_modules() +function interpreter.builtin_modules() local builtin_modules = interpreter._BUILTIN_MODULES if builtin_modules == nil then builtin_modules = {} local builtin_module_files = os.match(path.join(os.programdir(), "core/sandbox/modules/interpreter/*.lua")) if builtin_module_files then for _, builtin_module_file in ipairs(builtin_module_files) do - - -- the module name local module_name = path.basename(builtin_module_file) assert(module_name) - -- load script local script, errors = loadfile(builtin_module_file) if script then - - -- load module local ok, results = utils.trycall(script) if not ok then os.raise(results) end - - -- save module builtin_modules[module_name] = results else - -- error os.raise(errors) end end @@ -697,7 +689,7 @@ function interpreter.new() instance:api_register(nil, "interp_add_scopeapis", interpreter.api_interp_add_scopeapis) -- register the builtin modules - for module_name, module in pairs(interpreter._builtin_modules()) do + for module_name, module in pairs(interpreter.builtin_modules()) do instance:api_register_builtin(module_name, module) end @@ -1949,14 +1941,8 @@ function interpreter.instance(script) if script then local scope = getfenv(script) if scope then - - -- enable to read _INTERPRETER rawset(scope, "_INTERPRETER_READABLE", true) - - -- attempt to get it instance = scope._INTERPRETER - - -- disable to read _INTERPRETER rawset(scope, "_INTERPRETER_READABLE", nil) end if instance then return instance end @@ -1965,27 +1951,15 @@ function interpreter.instance(script) -- find self instance for the current sandbox local level = 2 while level < 32 do - - -- get scope local scope = getfenv(level) if scope then - - -- enable to read _INTERPRETER rawset(scope, "_INTERPRETER_READABLE", true) - - -- attempt to get it instance = scope._INTERPRETER - - -- disable to read _INTERPRETER rawset(scope, "_INTERPRETER_READABLE", nil) end - - -- found? if instance then break end - - -- next level = level + 1 end return instance |
