From e98014d29bf6d8f2efdd37320251c6bb20e767ce Mon Sep 17 00:00:00 2001 From: Gabriel Tofvesson Date: Thu, 28 Nov 2024 23:11:18 +0100 Subject: [PATCH] Add locals to debug context --- debugger.lua | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) 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