summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2018-10-07 22:08:05 +0800
committerruki <[email protected]>2018-10-07 22:08:05 +0800
commit800cc0415eee4f97ee34874a2fb14c33f7c660b6 (patch)
treec6f58199b356890e1ee3ea4ac50e6991b2d5bf08
parent0809d1b2d92c37c8f67f5daccadb061ff933d877 (diff)
improve lua plugin
-rw-r--r--xmake/core/sandbox/modules/import/core/sandbox/module.lua16
-rw-r--r--xmake/plugins/lua/xmake.lua18
2 files changed, 32 insertions, 2 deletions
diff --git a/xmake/core/sandbox/modules/import/core/sandbox/module.lua b/xmake/core/sandbox/modules/import/core/sandbox/module.lua
index 0f4aef2e6..ad37ab0a9 100644
--- a/xmake/core/sandbox/modules/import/core/sandbox/module.lua
+++ b/xmake/core/sandbox/modules/import/core/sandbox/module.lua
@@ -507,6 +507,22 @@ function core_sandbox_module.inherit(name, opt)
return core_sandbox_module.import(name, opt)
end
+-- get the public object in the current module
+function core_sandbox_module.get(name)
+
+ -- is private object?
+ if name:startswith('_') then
+ return
+ end
+
+ -- get the parent scope
+ local scope_parent = getfenv(2)
+ assert(scope_parent)
+
+ -- get it
+ return scope_parent[name]
+end
+
-- load module
return core_sandbox_module
diff --git a/xmake/plugins/lua/xmake.lua b/xmake/plugins/lua/xmake.lua
index b5d80e9cd..b5043fad2 100644
--- a/xmake/plugins/lua/xmake.lua
+++ b/xmake/plugins/lua/xmake.lua
@@ -33,6 +33,7 @@ task("lua")
-- imports
import("core.base.option")
+ import("core.sandbox.module")
import("core.sandbox.sandbox")
-- list all lua scripts?
@@ -68,8 +69,21 @@ task("lua")
import("scripts." .. script, {anonymous = true})(unpack(option.get("arguments") or {}))
else
- -- run modules (xmake lua core.xxx.xxx)
- print(import(script, {anonymous = true})(unpack(option.get("arguments") or {})))
+ -- attempt to find the builtin module
+ local object = nil
+ for _, name in ipairs(script:split("%.")) do
+ object = object and object[name] or module.get(name)
+ if not object then
+ break
+ end
+ end
+ if object then
+ -- run builtin modules (xmake lua core.xxx.xxx)
+ print(object(unpack(option.get("arguments") or {})))
+ else
+ -- run imported modules (xmake lua core.xxx.xxx)
+ print(import(script, {anonymous = true})(unpack(option.get("arguments") or {})))
+ end
end
else
-- enter interactive mode