diff --git a/debugger.lua b/debugger.lua index 1581d7f..8d638e3 100644 --- a/debugger.lua +++ b/debugger.lua @@ -1,11 +1,19 @@ -local function execDebug() +local function copyObject(o) + local obj = {} + for k,v in pairs(o) do + obj[k] = v + end + return obj +end + +local function execDebug(env) local input = io.input() local result = { pcall(input.read, input, "*l") } if not result[1] then return false, result[2] end - local func = load("return " .. result[2]) + local func = load(result[2], "debug", "bt", env) if type(func) ~= "function" then return false, func end @@ -13,10 +21,12 @@ local function execDebug() return pcall(func) end -local function debugREPL(onResult) +local function debugREPL(onResult, debugArgs) + local globalEnv = copyObject(_ENV) + globalEnv._debug = debugArgs local result, retval repeat - result, retval = execDebug() + result, retval = execDebug(globalEnv) if result and type(onResult) == "function" then onResult(retval) end