summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2016-08-31 23:38:27 +0800
committerruki <[email protected]>2016-08-31 23:38:39 +0800
commit097988a6e4485ce42d11e8c120aebb3b2fa8f4b0 (patch)
tree937d31e95e75a2c47491daff930d9a7e5ae31734
parent6a934421f56731fa03cd283a2ec8b58e1d81cd98 (diff)
modify interpreter builtin-modules
-rw-r--r--xmake/core/base/interpreter.lua37
-rw-r--r--xmake/core/project/deprecated/project.lua18
-rw-r--r--xmake/core/sandbox/modules/interpreter/format.lua26
-rw-r--r--xmake/core/sandbox/modules/interpreter/getenv.lua26
-rw-r--r--xmake/core/sandbox/modules/interpreter/ifelse.lua25
-rw-r--r--xmake/core/sandbox/modules/interpreter/ipairs.lua26
-rw-r--r--xmake/core/sandbox/modules/interpreter/os.lua57
-rw-r--r--xmake/core/sandbox/modules/interpreter/pairs.lua25
-rw-r--r--xmake/core/sandbox/modules/interpreter/path.lua25
-rw-r--r--xmake/core/sandbox/modules/interpreter/print.lua32
-rw-r--r--xmake/core/sandbox/modules/interpreter/printf.lua32
-rw-r--r--xmake/core/sandbox/modules/interpreter/string.lua26
-rw-r--r--xmake/core/sandbox/modules/interpreter/table.lua25
-rw-r--r--xmake/core/sandbox/modules/interpreter/tonumber.lua25
-rw-r--r--xmake/core/sandbox/modules/interpreter/tostring.lua25
-rw-r--r--xmake/core/sandbox/modules/interpreter/type.lua25
-rw-r--r--xmake/core/sandbox/modules/os.lua10
17 files changed, 437 insertions, 28 deletions
diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua
index f8f17ddf9..8fb1d8afd 100644
--- a/xmake/core/base/interpreter.lua
+++ b/xmake/core/base/interpreter.lua
@@ -482,18 +482,33 @@ function interpreter.new()
instance:api_register(nil, "add_subdirs", interpreter.api_builtin_add_subdirs)
instance:api_register(nil, "add_subfiles", interpreter.api_builtin_add_subfiles)
- -- register the builtin interfaces for lua
- instance:api_register_builtin("print", print)
- instance:api_register_builtin("pairs", pairs)
- instance:api_register_builtin("ipairs", ipairs)
- instance:api_register_builtin("format", string.format)
- instance:api_register_builtin("printf", utils.print)
- instance:api_register_builtin("getenv", os.getenv)
+ -- load builtin module files
+ local builtin_module_files = os.match(path.join(xmake._CORE_DIR, "sandbox/modules/interpreter/*.lua"))
+ if builtin_module_files then
+ for _, builtin_module_file in ipairs(builtin_module_files) do
- -- register the builtin modules for lua
- instance:api_register_builtin("path", path)
- instance:api_register_builtin("table", table)
- instance:api_register_builtin("string", string)
+ -- 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 = xpcall(script, debug.traceback)
+ if not ok then
+ os.raise(results)
+ end
+
+ -- register module
+ instance:api_register_builtin(module_name, results)
+ else
+ -- error
+ os.raise(errors)
+ end
+ end
+ end
-- ok?
return instance
diff --git a/xmake/core/project/deprecated/project.lua b/xmake/core/project/deprecated/project.lua
index 197244761..8e7a2e448 100644
--- a/xmake/core/project/deprecated/project.lua
+++ b/xmake/core/project/deprecated/project.lua
@@ -34,21 +34,6 @@ local platform = require("platform/platform")
local deprecated = require("base/deprecated")
local deprecated_interpreter = require("base/deprecated/interpreter")
--- the current os is belong to the given os?
-function deprecated_project._api_is_os(interp, ...)
-
- -- get the current os
- local os = platform.os()
- if not os then return false end
-
- -- exists this os?
- for _, o in ipairs(table.join(...)) do
- if o and type(o) == "string" and o == os then
- return true
- end
- end
-end
-
-- the current mode is belong to the given modes?
function deprecated_project._api_is_mode(interp, ...)
@@ -345,8 +330,7 @@ function deprecated_project.api_register(interp)
-- register api: set_runscript() and set_installscript() and set_packagescript()
deprecated_interpreter.api_register_set_script(interp, "target", "runscript", "installscript", "packagescript")
- -- register api: os(), kinds(), modes(), plats(), archs(), options()
- interp:api_register(nil, "os", deprecated_project._api_os)
+ -- register api: kinds(), modes(), plats(), archs(), options()
interp:api_register(nil, "kinds", deprecated_project._api_kinds)
interp:api_register(nil, "modes", deprecated_project._api_modes)
interp:api_register(nil, "plats", deprecated_project._api_plats)
diff --git a/xmake/core/sandbox/modules/interpreter/format.lua b/xmake/core/sandbox/modules/interpreter/format.lua
new file mode 100644
index 000000000..b2f744b1f
--- /dev/null
+++ b/xmake/core/sandbox/modules/interpreter/format.lua
@@ -0,0 +1,26 @@
+--!The Make-like Build Utility based on Lua
+--
+-- 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) 2015 - 2016, ruki All rights reserved.
+--
+-- @author ruki
+-- @file format.lua
+--
+
+-- return module
+return string.format
+
+
diff --git a/xmake/core/sandbox/modules/interpreter/getenv.lua b/xmake/core/sandbox/modules/interpreter/getenv.lua
new file mode 100644
index 000000000..d426bb33a
--- /dev/null
+++ b/xmake/core/sandbox/modules/interpreter/getenv.lua
@@ -0,0 +1,26 @@
+--!The Make-like Build Utility based on Lua
+--
+-- 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) 2015 - 2016, ruki All rights reserved.
+--
+-- @author ruki
+-- @file getenv.lua
+--
+
+-- return module
+return require("sandbox/modules/os").getenv
+
+
diff --git a/xmake/core/sandbox/modules/interpreter/ifelse.lua b/xmake/core/sandbox/modules/interpreter/ifelse.lua
new file mode 100644
index 000000000..b6609fdfe
--- /dev/null
+++ b/xmake/core/sandbox/modules/interpreter/ifelse.lua
@@ -0,0 +1,25 @@
+--!The Make-like Build Utility based on Lua
+--
+-- 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) 2015 - 2016, ruki All rights reserved.
+--
+-- @author ruki
+-- @file ifelse.lua
+--
+
+-- load module
+return require("sandbox/modules/ifelse")
+
diff --git a/xmake/core/sandbox/modules/interpreter/ipairs.lua b/xmake/core/sandbox/modules/interpreter/ipairs.lua
new file mode 100644
index 000000000..194c9d862
--- /dev/null
+++ b/xmake/core/sandbox/modules/interpreter/ipairs.lua
@@ -0,0 +1,26 @@
+--!The Make-like Build Utility based on Lua
+--
+-- 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) 2015 - 2016, ruki All rights reserved.
+--
+-- @author ruki
+-- @file ipairs.lua
+--
+
+-- load modules
+return require("sandbox/modules/ipairs")
+
+
diff --git a/xmake/core/sandbox/modules/interpreter/os.lua b/xmake/core/sandbox/modules/interpreter/os.lua
new file mode 100644
index 000000000..bf8bf7698
--- /dev/null
+++ b/xmake/core/sandbox/modules/interpreter/os.lua
@@ -0,0 +1,57 @@
+--!The Make-like Build Utility based on Lua
+--
+-- 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) 2015 - 2016, ruki All rights reserved.
+--
+-- @author ruki
+-- @file os.lua
+--
+
+-- load modules
+local os = require("base/os")
+local string = require("base/string")
+
+-- define module
+local sandbox_os = sandbox_os or {}
+
+-- export some readonly interfaces
+sandbox_os.date = os.date
+sandbox_os.time = os.time
+sandbox_os.mtime = os.mtime
+sandbox_os.mclock = os.mclock
+sandbox_os.getenv = os.getenv
+sandbox_os.dirs = os.dirs
+sandbox_os.host = os.host
+sandbox_os.arch = os.arch
+sandbox_os.isfile = os.isfile
+sandbox_os.exists = os.exists
+sandbox_os.curdir = os.curdir
+sandbox_os.tmpdir = os.tmpdir
+sandbox_os.uuid = os.uuid
+
+-- match files
+function sandbox_os.files(pattern, ...)
+ return os.match(string.format(pattern, ...))
+end
+
+-- match directories
+function sandbox_os.dirs(pattern, ...)
+ return os.match(string.format(pattern, ...), true)
+end
+
+-- return module
+return sandbox_os
+
diff --git a/xmake/core/sandbox/modules/interpreter/pairs.lua b/xmake/core/sandbox/modules/interpreter/pairs.lua
new file mode 100644
index 000000000..952431f0c
--- /dev/null
+++ b/xmake/core/sandbox/modules/interpreter/pairs.lua
@@ -0,0 +1,25 @@
+--!The Make-like Build Utility based on Lua
+--
+-- 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) 2015 - 2016, ruki All rights reserved.
+--
+-- @author ruki
+-- @file pairs.lua
+--
+
+-- load modules
+return require("sandbox/modules/pairs")
+
diff --git a/xmake/core/sandbox/modules/interpreter/path.lua b/xmake/core/sandbox/modules/interpreter/path.lua
new file mode 100644
index 000000000..0ac9ac02d
--- /dev/null
+++ b/xmake/core/sandbox/modules/interpreter/path.lua
@@ -0,0 +1,25 @@
+--!The Make-like Build Utility based on Lua
+--
+-- 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) 2015 - 2016, ruki All rights reserved.
+--
+-- @author ruki
+-- @file path.lua
+--
+
+-- load module
+return require("sandbox/modules/path")
+
diff --git a/xmake/core/sandbox/modules/interpreter/print.lua b/xmake/core/sandbox/modules/interpreter/print.lua
new file mode 100644
index 000000000..05f9271ad
--- /dev/null
+++ b/xmake/core/sandbox/modules/interpreter/print.lua
@@ -0,0 +1,32 @@
+--!The Make-like Build Utility based on Lua
+--
+-- 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) 2015 - 2016, ruki All rights reserved.
+--
+-- @author ruki
+-- @file print.lua
+--
+
+-- print format string
+function _print(format, ...)
+
+ -- done
+ io.write(string.format(format, ...) .. "\n")
+end
+
+-- load module
+return _print
+
diff --git a/xmake/core/sandbox/modules/interpreter/printf.lua b/xmake/core/sandbox/modules/interpreter/printf.lua
new file mode 100644
index 000000000..4abf2fd53
--- /dev/null
+++ b/xmake/core/sandbox/modules/interpreter/printf.lua
@@ -0,0 +1,32 @@
+--!The Make-like Build Utility based on Lua
+--
+-- 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) 2015 - 2016, ruki All rights reserved.
+--
+-- @author ruki
+-- @file printf.lua
+--
+
+-- printf format string without newline
+function _printf(format, ...)
+
+ -- done
+ io.write(string.format(format, ...))
+end
+
+-- load module
+return _printf
+
diff --git a/xmake/core/sandbox/modules/interpreter/string.lua b/xmake/core/sandbox/modules/interpreter/string.lua
new file mode 100644
index 000000000..848b2f412
--- /dev/null
+++ b/xmake/core/sandbox/modules/interpreter/string.lua
@@ -0,0 +1,26 @@
+--!The Make-like Build Utility based on Lua
+--
+-- 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) 2015 - 2016, ruki All rights reserved.
+--
+-- @author ruki
+-- @file string.lua
+--
+
+-- load module
+return require("sandbox/modules/string")
+
+
diff --git a/xmake/core/sandbox/modules/interpreter/table.lua b/xmake/core/sandbox/modules/interpreter/table.lua
new file mode 100644
index 000000000..eb86bc01c
--- /dev/null
+++ b/xmake/core/sandbox/modules/interpreter/table.lua
@@ -0,0 +1,25 @@
+--!The Make-like Build Utility based on Lua
+--
+-- 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) 2015 - 2016, ruki All rights reserved.
+--
+-- @author ruki
+-- @file table.lua
+--
+
+-- load module
+return require("sandbox/modules/table")
+
diff --git a/xmake/core/sandbox/modules/interpreter/tonumber.lua b/xmake/core/sandbox/modules/interpreter/tonumber.lua
new file mode 100644
index 000000000..7135b29dc
--- /dev/null
+++ b/xmake/core/sandbox/modules/interpreter/tonumber.lua
@@ -0,0 +1,25 @@
+--!The Make-like Build Utility based on Lua
+--
+-- 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) 2015 - 2016, ruki All rights reserved.
+--
+-- @author ruki
+-- @file tonumber.lua
+--
+
+-- load module
+return tonumber
+
diff --git a/xmake/core/sandbox/modules/interpreter/tostring.lua b/xmake/core/sandbox/modules/interpreter/tostring.lua
new file mode 100644
index 000000000..339471bff
--- /dev/null
+++ b/xmake/core/sandbox/modules/interpreter/tostring.lua
@@ -0,0 +1,25 @@
+--!The Make-like Build Utility based on Lua
+--
+-- 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) 2015 - 2016, ruki All rights reserved.
+--
+-- @author ruki
+-- @file tostring.lua
+--
+
+-- load module
+return tostring
+
diff --git a/xmake/core/sandbox/modules/interpreter/type.lua b/xmake/core/sandbox/modules/interpreter/type.lua
new file mode 100644
index 000000000..8f076140e
--- /dev/null
+++ b/xmake/core/sandbox/modules/interpreter/type.lua
@@ -0,0 +1,25 @@
+--!The Make-like Build Utility based on Lua
+--
+-- 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) 2015 - 2016, ruki All rights reserved.
+--
+-- @author ruki
+-- @file type.lua
+--
+
+-- load module
+return type
+
diff --git a/xmake/core/sandbox/modules/os.lua b/xmake/core/sandbox/modules/os.lua
index e0b6e28a9..56f006f31 100644
--- a/xmake/core/sandbox/modules/os.lua
+++ b/xmake/core/sandbox/modules/os.lua
@@ -304,6 +304,16 @@ function sandbox_os.match(pattern, findir, ...)
return os.match(pattern, findir)
end
+-- match files
+function sandbox_os.files(pattern, ...)
+ return sandbox_os.match(pattern, false, ...)
+end
+
+-- match directories
+function sandbox_os.dirs(pattern, ...)
+ return sandbox_os.match(pattern, true, ...)
+end
+
-- is directory?
function sandbox_os.isdir(dirpath)