From 2971e2e8ed5b2fa0fd7bac54c6750144f1b9427e Mon Sep 17 00:00:00 2001 From: SquidDev Date: Wed, 3 Feb 2016 21:06:26 +0000 Subject: [PATCH] Fix stackoverflow in traceback Closes #21 --- depends/modules/Traceback.lua | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/depends/modules/Traceback.lua b/depends/modules/Traceback.lua index 9f7a188..847f24e 100644 --- a/depends/modules/Traceback.lua +++ b/depends/modules/Traceback.lua @@ -7,10 +7,14 @@ local find = string.find local lineMapper = { header = [[ -- Maps - local lineToModule = setmetatable({{lineToModule}}, { - __index = function(t, k) - if k > 1 then return t[k-1] end + local lineToModule = {{lineToModule}} + local getLine(line) + while line >= 0 do + local l = lineToModule[line] + if l then return l end + line = line - 1 end + return -1 }) local moduleStarts = {{moduleStarts}} local programEnd = {{lastLine}} @@ -28,7 +32,7 @@ local lineMapper = { if line > programEnd then return end -- convert to module lines - filename = lineToModule[line] or "" + filename = getLine(line) or "" local newLine = moduleStarts[filename] if newLine then line = line - newLine + 1