Fix for luajit error handling (old Lua 5.1 API uses getfenv)

This commit is contained in:
Bruce Hill 2019-03-14 17:57:30 -07:00
parent ddb839bfd4
commit c2397620a9
2 changed files with 16 additions and 6 deletions

View File

@ -96,10 +96,16 @@ enhance_error = function(error_message)
local action_name = fn_name:from_lua_id()
error_message = "The action '" .. tostring(action_name) .. "' is not defined."
local func = debug.getinfo(2, 'f').func
local ename, env = debug.getupvalue(func, 1)
if not (ename == "_ENV" or ename == "_G") then
func = debug.getinfo(3, 'f').func
local env
if _VERSION == "Lua 5.1" then
env = getfenv(func)
else
local ename
ename, env = debug.getupvalue(func, 1)
if not (ename == "_ENV" or ename == "_G") then
func = debug.getinfo(3, 'f').func
ename, env = debug.getupvalue(func, 1)
end
end
local THRESHOLD = math.min(4.5, .9 * #action_name)
local candidates = { }

View File

@ -74,10 +74,14 @@ enhance_error = (error_message)->
-- This check is necessary for handling both top-level code and code inside a fn
func = debug.getinfo(2,'f').func
ename,env = debug.getupvalue(func, 1)
unless ename == "_ENV" or ename == "_G"
func = debug.getinfo(3,'f').func
local env
if _VERSION == "Lua 5.1"
env = getfenv(func)
else
ename,env = debug.getupvalue(func, 1)
unless ename == "_ENV" or ename == "_G"
func = debug.getinfo(3,'f').func
ename,env = debug.getupvalue(func, 1)
THRESHOLD = math.min(4.5, .9*#action_name) -- Ignore matches with strdist > THRESHOLD
candidates = {}