From 46b3056a0996d1bbdf4c1d4baa9f841e2d22299f Mon Sep 17 00:00:00 2001 From: Philipp Janda Date: Sun, 26 Apr 2015 14:39:57 +0200 Subject: Add nonyieldable xpcall that takes extra arguments. Although the full-featured yieldable xpcall has been moved to the compat53 module, the compat53.module module can at least have a version that takes and passes extra arguments. Also remove some unnecessary local aliases left over from previous refactoring. --- compat53/init.lua | 4 ++-- compat53/module.lua | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/compat53/init.lua b/compat53/init.lua index e5f7692..e738091 100644 --- a/compat53/init.lua +++ b/compat53/init.lua @@ -9,8 +9,8 @@ local lua_version = _VERSION:sub(-3) if lua_version == "5.1" then -- cache globals - local error, pcall, rawset, select, setmetatable, tostring, type, unpack, xpcall = - error, pcall, rawset, select, setmetatable, tostring, type, unpack, xpcall + local error, pcall, rawset, select, setmetatable, tostring, unpack, xpcall = + error, pcall, rawset, select, setmetatable, tostring, unpack, xpcall local coroutine, debug, io, package, string = coroutine, debug, io, package, string local coroutine_create = coroutine.create diff --git a/compat53/module.lua b/compat53/module.lua index 30b42ee..c69c131 100644 --- a/compat53/module.lua +++ b/compat53/module.lua @@ -7,8 +7,8 @@ local M = _G if lua_version < "5.3" then -- cache globals in upvalues - local error, getmetatable, ipairs, pairs, pcall, require, select, setmetatable, type = - error, getmetatable, ipairs, pairs, pcall, require, select, setmetatable, type + local error, ipairs, pairs, pcall, require, select, setmetatable, type = + error, ipairs, pairs, pcall, require, select, setmetatable, type local debug, math, package, string, table = debug, math, package, string, table @@ -352,8 +352,8 @@ if lua_version < "5.3" then #setmetatable({}, { __len = function() return 1 end }) == 1 -- cache globals in upvalues - local load, loadfile, loadstring, setfenv, tostring, unpack, xpcall = - load, loadfile, loadstring, setfenv, tostring, unpack, xpcall + local load, loadfile, loadstring, setfenv, unpack, xpcall = + load, loadfile, loadstring, setfenv, unpack, xpcall local coroutine, io, os = coroutine, io, os local coroutine_create = coroutine.create local coroutine_resume = coroutine.resume @@ -529,6 +529,14 @@ if lua_version < "5.3" then end + if not is_luajit then + function M.xpall(f, msgh, ...) + local args, n = { ... }, select('#', ...) + return xpcall(function() return f(unpack(args, 1, n)) end, msgh) + end + end + + if not is_luajit52 then function M.os.execute(cmd) local code = os_execute(cmd) -- cgit v1.2.3-55-g6feb