From e50fa84f61f3373b3da231aa5b999efa10193c1d Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Fri, 15 Feb 2019 09:25:06 +0100 Subject: [PATCH] gears.protected_call: Automatically detect xpcall features In Lua 5.1, xpcall() has exactly two arguments: The function to call and the error handler. Everywhere else, xpcall() passes extra arguments on to the function to call. This includes LuaJIT, however since LuaJIT sets _VERSION to "Lua 5.1", so far gears.protected_call used the workaround for Lua 5.1 here. This commit switches gears.protected_call to actually test for this feature instead of just guessing based on _VERSION. Thus, this now also uses the better code with LuaJIT. Signed-off-by: Uli Schlachter --- lib/gears/protected_call.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/gears/protected_call.lua b/lib/gears/protected_call.lua index c182e149..ef22f609 100644 --- a/lib/gears/protected_call.lua +++ b/lib/gears/protected_call.lua @@ -23,7 +23,7 @@ local function handle_result(success, ...) end local do_pcall -if _VERSION <= "Lua 5.1" then +if not select(2, xpcall(function(a) return a end, error, true)) then -- Lua 5.1 doesn't support arguments in xpcall :-( do_pcall = function(func, ...) local args = { ... }