summaryrefslogtreecommitdiff
path: root/xmake/core/base/interpreter.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2016-01-28 19:00:21 +0800
committerruki <[email protected]>2016-02-15 19:10:26 +0800
commit780a88f1b2e7cb90be32cd20216bd94460824c20 (patch)
treef0d9f8b6189b6cbbc9bffc91eaddf74052387482 /xmake/core/base/interpreter.lua
parent7639a57c700146b1d70f3b19c395956312e25fd7 (diff)
check xmake.lua syntax errors
Diffstat (limited to 'xmake/core/base/interpreter.lua')
-rw-r--r--xmake/core/base/interpreter.lua36
1 files changed, 33 insertions, 3 deletions
diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua
index acca229dd..eae94ee9c 100644
--- a/xmake/core/base/interpreter.lua
+++ b/xmake/core/base/interpreter.lua
@@ -29,6 +29,7 @@ local path = require("base/path")
local table = require("base/table")
local utils = require("base/utils")
local string = require("base/string")
+local sandbox = require("base/sandbox")
-- traceback
function interpreter._traceback(errors)
@@ -216,7 +217,7 @@ function interpreter._api_builtin_add_subdirfiles(self, isdirs, ...)
self._PRIVATE._CURFILE = file
-- load the file script
- local script = loadfile(file)
+ local script, errors = loadfile(file)
if script then
-- bind public scope
@@ -231,6 +232,9 @@ function interpreter._api_builtin_add_subdirfiles(self, isdirs, ...)
-- get mtime of the file
self._PRIVATE._MTIMES[path.relative(file, self._PRIVATE._ROOTDIR)] = os.mtime(file)
+ else
+ utils.error(errors)
+ utils.abort()
end
end
end
@@ -460,9 +464,9 @@ function interpreter.load(self, file, scope_kind, remove_repeat, enable_filter)
assert(self and self._PUBLIC and self._PRIVATE and file)
-- load the script
- local script = loadfile(file)
+ local script, errors = loadfile(file)
if not script then
- return nil, string.format("load %s failed!", file)
+ return nil, errors
end
-- clear first
@@ -762,6 +766,32 @@ function interpreter.api_register_add_array(self, scope_kind, prefix, ...)
self:_api_register_xxx_values(scope_kind, "add", prefix, implementation, ...)
end
+-- register api for set_script
+function interpreter.api_register_set_script(self, scope_kind, prefix, ...)
+
+ -- check
+ assert(self)
+
+ -- define implementation
+ local implementation = function (self, scope, name, script)
+
+ -- bind sandbox to script
+ local ok, errors = sandbox.init():bind(script)
+ if not ok then
+ utils.error("set_%s(\"%s\"): %s", scope, name, errors)
+ utils.abort()
+ end
+
+ -- update script?
+ scope[name] = {}
+ table.insert(scope[name], script)
+
+ end
+
+ -- register implementation
+ self:_api_register_xxx_values(scope_kind, "set", prefix, implementation, ...)
+end
+
-- register api for set_keyvalues
function interpreter.api_register_set_keyvalues(self, scope_kind, prefix, ...)