summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2016-11-15 22:18:24 +0800
committerruki <[email protected]>2016-11-15 22:18:24 +0800
commit583c8523627493099839ef891dc3f887712f66e3 (patch)
tree31fb2eb7187409d8c78bcbcd040fcdbe7aa0693f
parent07ee355e9a9be761f33855b14658bcf0aaeb4d89 (diff)
add dictionary syntax style
-rw-r--r--CHANGELOG.md2
-rw-r--r--xmake/core/base/interpreter.lua50
2 files changed, 50 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e5b932bcb..9172999f7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,7 @@
* Add `--links`, `--linkdirs` and `--includedirs` configure arguments
* Add app2ipa plugin
+* Add dictionary syntax style for xmake.lua
### Bugs fixed
@@ -180,6 +181,7 @@
* ����`--links`, `--linkdirs` and `--includedirs` ����
* ����app2ipa���
+* Ϊxmake.lua������������dictionay�﷨���
### Bugs�޸�
diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua
index 3b8f930b2..2c7a23cf0 100644
--- a/xmake/core/base/interpreter.lua
+++ b/xmake/core/base/interpreter.lua
@@ -748,6 +748,29 @@ function interpreter:api_register_scope(...)
local scope_for_kind = scopes[scope_kind] or {}
scopes[scope_kind] = scope_for_kind
+ -- is dictionary mode?
+ --
+ -- .e.g
+ -- target
+ -- {
+ -- name = "tbox"
+ -- kind = "static",
+ -- files =
+ -- {
+ -- "src/*.c",
+ -- "*.cpp"
+ -- }
+ --}
+ local scope_info = nil
+ if type(scope_name) == "table" and scope_name["name"] ~= nil then
+
+ -- get the scope info
+ scope_info = scope_name
+
+ -- get the scope name from the dictionary
+ scope_name = scope_name["name"]
+ end
+
-- enter the given scope
if scope_name ~= nil then
@@ -768,6 +791,19 @@ function interpreter:api_register_scope(...)
-- update the current scope kind
scopes._CURRENT_KIND = scope_kind
+
+ -- translate scope info
+ if scope_info then
+ scope_info["name"] = nil
+ for name, values in pairs(scope_info) do
+ local apifunc = self:api_func("set_" .. name) or self:api_func("add_" .. name) or self:api_func("on_" .. name) or self:api_func(name)
+ if apifunc then
+ apifunc(values)
+ else
+ os.raise("unknown %s for %s(\"%s\")", name, scope_kind, scope_name)
+ end
+ end
+ end
end
-- register implementation
@@ -1072,14 +1108,24 @@ function interpreter:api_builtin_add_subfiles(...)
return self:_api_builtin_add_subdirfiles(false, ...)
end
+-- get api function
+function interpreter:api_func(apiname)
+
+ -- check
+ assert(self and self._PUBLIC and apiname)
+
+ -- get api function
+ return self._PUBLIC[apiname]
+end
+
-- call api
function interpreter:api_call(apiname, ...)
-- check
- assert(self and self._PUBLIC and apiname)
+ assert(self and apiname)
-- get api function
- local apifunc = self._PUBLIC[apiname]
+ local apifunc = self:api_func(apiname)
if not apifunc then
os.raise("call %s() failed, this api not found!", apiname)
end