diff options
| author | ruki <[email protected]> | 2016-01-28 20:33:54 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2016-02-15 19:10:26 +0800 |
| commit | 80a87ab432cbe72ab772f02d13daa75bc1010085 (patch) | |
| tree | edece4e5a3066589401b2c6ebf0f5e32e0ec45f7 /xmake/core/base | |
| parent | 780a88f1b2e7cb90be32cd20216bd94460824c20 (diff) | |
register some builtin api for sandbox
Diffstat (limited to 'xmake/core/base')
| -rw-r--r-- | xmake/core/base/interpreter.lua | 1 | ||||
| -rw-r--r-- | xmake/core/base/project.lua | 20 | ||||
| -rw-r--r-- | xmake/core/base/sandbox.lua | 47 |
3 files changed, 50 insertions, 18 deletions
diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua index eae94ee9c..855480ebd 100644 --- a/xmake/core/base/interpreter.lua +++ b/xmake/core/base/interpreter.lua @@ -444,7 +444,6 @@ function interpreter.init() interp:api_register("add_subfiles", interpreter.api_builtin_add_subfiles) -- register the builtin interfaces for lua - interp:api_register_builtin("print", print) interp:api_register_builtin("pairs", pairs) interp:api_register_builtin("ipairs", ipairs) diff --git a/xmake/core/base/project.lua b/xmake/core/base/project.lua index 13876a2ac..ff022d9fa 100644 --- a/xmake/core/base/project.lua +++ b/xmake/core/base/project.lua @@ -36,13 +36,6 @@ local compiler = require("base/compiler") local platform = require("base/platform") local interpreter = require("base/interpreter") --- import module -function project._api_import(interp, module) - - -- import - return require("module/" .. module) -end - -- the current os is belong to the given os? function project._api_os(interp, ...) @@ -337,6 +330,11 @@ function project._interpreter() -- register api: add_target() and add_option() interp:api_register_add_scope("target", "option") + + -- register api: set_script() for target + interp:api_register_set_script("target", nil, "runscript" + , "installscript" + , "packagescript") -- register api: set_values() for target interp:api_register_set_values("target", nil, "kind" @@ -347,10 +345,7 @@ function project._interpreter() , "symbols" , "warnings" , "optimize" - , "languages" - , "runscript" - , "installscript" - , "packagescript") + , "languages") -- register api: add_values() for target interp:api_register_add_values("target", nil, "deps" @@ -418,9 +413,6 @@ function project._interpreter() , "includedirs") - -- register api: import() - interp:api_register("import", project._api_import) - -- register api: os() interp:api_register("os", project._api_os) diff --git a/xmake/core/base/sandbox.lua b/xmake/core/base/sandbox.lua index b6d9f29a3..96057aca8 100644 --- a/xmake/core/base/sandbox.lua +++ b/xmake/core/base/sandbox.lua @@ -72,22 +72,42 @@ function sandbox._traceback(errors) return results end +-- import module +function sandbox._api_builtin_import(self, module) + + -- import + return require("module/" .. module) +end + -- init sandbox function sandbox.init() -- init an sandbox instance - local box = { _PUBLIC = {} + local sbox = { _PUBLIC = {} , _PRIVATE = {}} -- inherit the interfaces of sandbox for k, v in pairs(sandbox) do if type(v) == "function" then - box[k] = v + sbox[k] = v end end + -- register the builtin interfaces + sbox:api_register("import", sandbox._api_builtin_import) + + -- register the builtin interfaces for lua + sbox:api_register_builtin("print", print) +-- sbox:api_register_builtin("pairs", pairs) +-- sbox:api_register_builtin("ipairs", ipairs) + + -- register the builtin modules for lua + sbox:api_register_builtin("path", path) +-- sbox:api_register_builtin("table", table) + sbox:api_register_builtin("string", string) + -- ok? - return box + return sbox end -- bind sandbox to script @@ -133,5 +153,26 @@ function sandbox.bind(self, script) return true end +-- register api +function sandbox.api_register(self, name, func) + + -- check + assert(self and self._PUBLIC) + assert(name and func) + + -- register it + self._PUBLIC[name] = function (...) return func(self, ...) end +end + +-- register api for builtin +function sandbox.api_register_builtin(self, name, func) + + -- check + assert(self and self._PUBLIC and func) + + -- register it + self._PUBLIC[name] = func +end + -- return module: sandbox return sandbox |
