From 44c7d62676ce6763d013db0c031e6f651237f510 Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 18 Jan 2016 15:03:43 +0800 Subject: rename sandbox to interpreter --- tests/interpreter/scope.lua | 9 ++++ tests/interpreter/tests.lua | 47 +++++++++++++++++++ tests/sandbox/scope.lua | 9 ---- tests/sandbox/tests.lua | 47 ------------------- xmake/core/base/interpreter.lua | 101 ++++++++++++++++++++++++++++++++++++++++ xmake/core/sandbox/sandbox.lua | 101 ---------------------------------------- 6 files changed, 157 insertions(+), 157 deletions(-) create mode 100644 tests/interpreter/scope.lua create mode 100644 tests/interpreter/tests.lua delete mode 100644 tests/sandbox/scope.lua delete mode 100644 tests/sandbox/tests.lua create mode 100644 xmake/core/base/interpreter.lua delete mode 100644 xmake/core/sandbox/sandbox.lua diff --git a/tests/interpreter/scope.lua b/tests/interpreter/scope.lua new file mode 100644 index 000000000..438470d5c --- /dev/null +++ b/tests/interpreter/scope.lua @@ -0,0 +1,9 @@ + +print("hello") + +function test() + assert(false) +end +test() + +print("hello") diff --git a/tests/interpreter/tests.lua b/tests/interpreter/tests.lua new file mode 100644 index 000000000..d389f5345 --- /dev/null +++ b/tests/interpreter/tests.lua @@ -0,0 +1,47 @@ +--!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 http://www.gnu.org/licenses/ +-- +-- Copyright (C) 2009 - 2015, ruki All rights reserved. +-- +-- @author ruki +-- @file tests.lua +-- + +-- define module: tests +local tests = tests or {} + +-- load modules +local interpreter = require("base/interpreter") + +-- the main function +function tests.main(self, file) + + -- check + assert(file and #file == 1) + + -- load it + local ok, errors = interpreter.load(file[1]) + if not ok then + print(errors) + return false + end + + -- ok + return true +end + +-- return module: tests +return tests diff --git a/tests/sandbox/scope.lua b/tests/sandbox/scope.lua deleted file mode 100644 index 438470d5c..000000000 --- a/tests/sandbox/scope.lua +++ /dev/null @@ -1,9 +0,0 @@ - -print("hello") - -function test() - assert(false) -end -test() - -print("hello") diff --git a/tests/sandbox/tests.lua b/tests/sandbox/tests.lua deleted file mode 100644 index 860df4cee..000000000 --- a/tests/sandbox/tests.lua +++ /dev/null @@ -1,47 +0,0 @@ ---!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 http://www.gnu.org/licenses/ --- --- Copyright (C) 2009 - 2015, ruki All rights reserved. --- --- @author ruki --- @file tests.lua --- - --- define module: tests -local tests = tests or {} - --- load modules -local sandbox = require("sandbox/sandbox") - --- the main function -function tests.main(self, file) - - -- check - assert(file and #file == 1) - - -- load it - local ok, errors = sandbox.load(file[1]) - if not ok then - print(errors) - return false - end - - -- ok - return true -end - --- return module: tests -return tests diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua new file mode 100644 index 000000000..ced71b128 --- /dev/null +++ b/xmake/core/base/interpreter.lua @@ -0,0 +1,101 @@ +--!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 http://www.gnu.org/licenses/ +-- +-- Copyright (C) 2009 - 2015, ruki All rights reserved. +-- +-- @author ruki +-- @file interpreter.lua +-- + +-- define module: interpreter +local interpreter = interpreter or {} + +-- load modules +local os = require("base/os") +local utils = require("base/utils") + +-- traceback +function interpreter._traceback(errors) + + -- init results + local results = "" + if errors then + results = errors .. "\n" + end + results = results .. "stack traceback:\n" + + -- make results + local level = 2 + while true do + + -- get debug info + local info = debug.getinfo(level, "Sln") + + -- end? + if not info or (info.name and info.name == "xpcall") then + break + end + + -- function? + if info.what == "C" then + results = results .. string.format(" [C]: in function '%s'\n", info.name) + elseif info.name then + results = results .. string.format(" [%s:%d]: in function '%s'\n", info.short_src, info.currentline, info.name) + elseif info.what == "main" then + results = results .. string.format(" [%s:%d]: in main chunk\n", info.short_src, info.currentline) + else + results = results .. string.format(" [%s:%d]:\n", info.short_src, info.currentline) + end + + -- next + level = level + 1 + end + + -- ok? + return results +end + +-- load interpreter +function interpreter.load(file) + + -- check + assert(file) + + -- load the script + local script = loadfile(file) + if not script then + return nil, string.format("load %s failed!", file) + end + + -- init the private scope + local private = {} + + -- bind the environment + local env = {_PRIVATE = private} +-- setfenv(script, env) + + -- done the script + local ok, errors = xpcall(script, interpreter._traceback) + if not ok then + return nil, errors + end + + -- get results + return nil +end + +-- return module: interpreter +return interpreter diff --git a/xmake/core/sandbox/sandbox.lua b/xmake/core/sandbox/sandbox.lua deleted file mode 100644 index 1e534a928..000000000 --- a/xmake/core/sandbox/sandbox.lua +++ /dev/null @@ -1,101 +0,0 @@ ---!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 http://www.gnu.org/licenses/ --- --- Copyright (C) 2009 - 2015, ruki All rights reserved. --- --- @author ruki --- @file sandbox.lua --- - --- define module: sandbox -local sandbox = sandbox or {} - --- load modules -local os = require("base/os") -local utils = require("base/utils") - --- traceback -function sandbox._traceback(errors) - - -- init results - local results = "" - if errors then - results = errors .. "\n" - end - results = results .. "stack traceback:\n" - - -- make results - local level = 2 - while true do - - -- get debug info - local info = debug.getinfo(level, "Sln") - - -- end? - if not info or (info.name and info.name == "xpcall") then - break - end - - -- function? - if info.what == "C" then - results = results .. string.format(" [C]: in function '%s'\n", info.name) - elseif info.name then - results = results .. string.format(" [%s:%d]: in function '%s'\n", info.short_src, info.currentline, info.name) - elseif info.what == "main" then - results = results .. string.format(" [%s:%d]: in main chunk\n", info.short_src, info.currentline) - else - results = results .. string.format(" [%s:%d]:\n", info.short_src, info.currentline) - end - - -- next - level = level + 1 - end - - -- ok? - return results -end - --- load sandbox -function sandbox.load(file) - - -- check - assert(file) - - -- load the script - local script = loadfile(file) - if not script then - return nil, string.format("load %s failed!", file) - end - - -- init the private scope - local private = {} - - -- bind the environment - local env = {_PRIVATE = private} --- setfenv(script, env) - - -- done the script - local ok, errors = xpcall(script, sandbox._traceback) - if not ok then - return nil, errors - end - - -- get results - return nil -end - --- return module: sandbox -return sandbox -- cgit v1.3.1