diff options
Diffstat (limited to 'xmake/core/base/interpreter.lua')
| -rw-r--r-- | xmake/core/base/interpreter.lua | 101 |
1 files changed, 101 insertions, 0 deletions
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 <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a> +-- +-- 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 |
