diff options
| author | ruki <[email protected]> | 2016-02-01 11:36:44 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2016-02-15 19:10:26 +0800 |
| commit | 4d9ea35a4cc8e4a2ac0d7e2633f088ca0be7e7f1 (patch) | |
| tree | d9e03245368fce5bdf56fce6ef2a272c95a95913 | |
| parent | def096cfe9e22d363dffa29cd02c134778e62966 (diff) | |
load builtin modules for sandbox
| -rw-r--r-- | xmake/core/base/sandbox.lua | 38 | ||||
| -rw-r--r-- | xmake/core/sandbox/builtin/ipairs.lua | 25 | ||||
| -rw-r--r-- | xmake/core/sandbox/builtin/os.lua (renamed from xmake/core/modules/os.lua) | 0 | ||||
| -rw-r--r-- | xmake/core/sandbox/builtin/pairs.lua | 25 | ||||
| -rw-r--r-- | xmake/core/sandbox/builtin/path.lua | 25 | ||||
| -rw-r--r-- | xmake/core/sandbox/builtin/print.lua | 25 | ||||
| -rw-r--r-- | xmake/core/sandbox/builtin/project.lua (renamed from xmake/core/modules/project.lua) | 0 | ||||
| -rw-r--r-- | xmake/core/sandbox/builtin/string.lua | 25 | ||||
| -rw-r--r-- | xmake/core/sandbox/builtin/table.lua | 25 |
9 files changed, 177 insertions, 11 deletions
diff --git a/xmake/core/base/sandbox.lua b/xmake/core/base/sandbox.lua index 2689c9dc5..37c9edab7 100644 --- a/xmake/core/base/sandbox.lua +++ b/xmake/core/base/sandbox.lua @@ -76,7 +76,7 @@ end function sandbox._api_builtin_import(self, module) -- import - return require("modules/" .. module) + return require("sandbox/" .. module) end -- register api @@ -113,18 +113,34 @@ function sandbox._init() end end - -- register the builtin interfaces - self:_api_register("import", sandbox._api_builtin_import) + -- load builtin module files + local builtin_module_files = os.match(path.join(xmake._CORE_DIR, "sandbox/builtin/*.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 = loadfile(builtin_module_file) + if script then + + -- load module + local ok, results = xpcall(script, debug.traceback) + if not ok then + utils.error(results) + utils.abort() + end - -- register the builtin interfaces for lua - self:_api_register_builtin("print", print) - self:_api_register_builtin("pairs", pairs) - self:_api_register_builtin("ipairs", ipairs) + -- register module + self:_api_register_builtin(module_name, results) + end + end + end - -- register the builtin modules for lua - self:_api_register_builtin("path", path) - self:_api_register_builtin("table", table) - self:_api_register_builtin("string", string) + -- register import() for importing the extensional sandbox modules + self:_api_register("import", sandbox._api_builtin_import) -- ok? return self diff --git a/xmake/core/sandbox/builtin/ipairs.lua b/xmake/core/sandbox/builtin/ipairs.lua new file mode 100644 index 000000000..b3551f862 --- /dev/null +++ b/xmake/core/sandbox/builtin/ipairs.lua @@ -0,0 +1,25 @@ +--!The Automatic Cross-platform Build Tool +-- +-- XMake is free software; you can redistribute it and/or modify +-- it under the terms of the GNU Lesser General Public License as published by +-- the Free Software Foundation; either version 2.1 of the License, or +-- (at your option) any later version. +-- +-- XMake is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU Lesser General Public License for more details. +-- +-- You should have received a copy of the GNU Lesser General Public License +-- along with XMake; +-- If not, see <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a> +-- +-- Copyright (C) 2009 - 2015, ruki All rights reserved. +-- +-- @author ruki +-- @file ipairs.lua +-- + +-- load module +return ipairs + diff --git a/xmake/core/modules/os.lua b/xmake/core/sandbox/builtin/os.lua index 3689086f2..3689086f2 100644 --- a/xmake/core/modules/os.lua +++ b/xmake/core/sandbox/builtin/os.lua diff --git a/xmake/core/sandbox/builtin/pairs.lua b/xmake/core/sandbox/builtin/pairs.lua new file mode 100644 index 000000000..f4f74b7e4 --- /dev/null +++ b/xmake/core/sandbox/builtin/pairs.lua @@ -0,0 +1,25 @@ +--!The Automatic Cross-platform Build Tool +-- +-- XMake is free software; you can redistribute it and/or modify +-- it under the terms of the GNU Lesser General Public License as published by +-- the Free Software Foundation; either version 2.1 of the License, or +-- (at your option) any later version. +-- +-- XMake is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU Lesser General Public License for more details. +-- +-- You should have received a copy of the GNU Lesser General Public License +-- along with XMake; +-- If not, see <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a> +-- +-- Copyright (C) 2009 - 2015, ruki All rights reserved. +-- +-- @author ruki +-- @file pairs.lua +-- + +-- load module +return pairs + diff --git a/xmake/core/sandbox/builtin/path.lua b/xmake/core/sandbox/builtin/path.lua new file mode 100644 index 000000000..925ad7cf8 --- /dev/null +++ b/xmake/core/sandbox/builtin/path.lua @@ -0,0 +1,25 @@ +--!The Automatic Cross-platform Build Tool +-- +-- XMake is free software; you can redistribute it and/or modify +-- it under the terms of the GNU Lesser General Public License as published by +-- the Free Software Foundation; either version 2.1 of the License, or +-- (at your option) any later version. +-- +-- XMake is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU Lesser General Public License for more details. +-- +-- You should have received a copy of the GNU Lesser General Public License +-- along with XMake; +-- If not, see <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a> +-- +-- Copyright (C) 2009 - 2015, ruki All rights reserved. +-- +-- @author ruki +-- @file path.lua +-- + +-- load module +return require("base/path") + diff --git a/xmake/core/sandbox/builtin/print.lua b/xmake/core/sandbox/builtin/print.lua new file mode 100644 index 000000000..b9e9b9f86 --- /dev/null +++ b/xmake/core/sandbox/builtin/print.lua @@ -0,0 +1,25 @@ +--!The Automatic Cross-platform Build Tool +-- +-- XMake is free software; you can redistribute it and/or modify +-- it under the terms of the GNU Lesser General Public License as published by +-- the Free Software Foundation; either version 2.1 of the License, or +-- (at your option) any later version. +-- +-- XMake is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU Lesser General Public License for more details. +-- +-- You should have received a copy of the GNU Lesser General Public License +-- along with XMake; +-- If not, see <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a> +-- +-- Copyright (C) 2009 - 2015, ruki All rights reserved. +-- +-- @author ruki +-- @file print.lua +-- + +-- load module +return print + diff --git a/xmake/core/modules/project.lua b/xmake/core/sandbox/builtin/project.lua index f3f726c6f..f3f726c6f 100644 --- a/xmake/core/modules/project.lua +++ b/xmake/core/sandbox/builtin/project.lua diff --git a/xmake/core/sandbox/builtin/string.lua b/xmake/core/sandbox/builtin/string.lua new file mode 100644 index 000000000..e9e75acb9 --- /dev/null +++ b/xmake/core/sandbox/builtin/string.lua @@ -0,0 +1,25 @@ +--!The Automatic Cross-platform Build Tool +-- +-- XMake is free software; you can redistribute it and/or modify +-- it under the terms of the GNU Lesser General Public License as published by +-- the Free Software Foundation; either version 2.1 of the License, or +-- (at your option) any later version. +-- +-- XMake is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU Lesser General Public License for more details. +-- +-- You should have received a copy of the GNU Lesser General Public License +-- along with XMake; +-- If not, see <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a> +-- +-- Copyright (C) 2009 - 2015, ruki All rights reserved. +-- +-- @author ruki +-- @file string.lua +-- + +-- load module +return require("base/string") + diff --git a/xmake/core/sandbox/builtin/table.lua b/xmake/core/sandbox/builtin/table.lua new file mode 100644 index 000000000..a697504fd --- /dev/null +++ b/xmake/core/sandbox/builtin/table.lua @@ -0,0 +1,25 @@ +--!The Automatic Cross-platform Build Tool +-- +-- XMake is free software; you can redistribute it and/or modify +-- it under the terms of the GNU Lesser General Public License as published by +-- the Free Software Foundation; either version 2.1 of the License, or +-- (at your option) any later version. +-- +-- XMake is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU Lesser General Public License for more details. +-- +-- You should have received a copy of the GNU Lesser General Public License +-- along with XMake; +-- If not, see <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a> +-- +-- Copyright (C) 2009 - 2015, ruki All rights reserved. +-- +-- @author ruki +-- @file table.lua +-- + +-- load module +return require("base/table") + |
