diff --git a/error_handling.lua b/error_handling.lua index 4799ce2..6774e55 100644 --- a/error_handling.lua +++ b/error_handling.lua @@ -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 = { } diff --git a/error_handling.moon b/error_handling.moon index 41d2fe1..d6a0881 100644 --- a/error_handling.moon +++ b/error_handling.moon @@ -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 = {}