<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://linguifex.com/w/index.php?action=history&amp;feed=atom&amp;title=Module%3Afun%2Fxpcall</id>
	<title>Module:fun/xpcall - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://linguifex.com/w/index.php?action=history&amp;feed=atom&amp;title=Module%3Afun%2Fxpcall"/>
	<link rel="alternate" type="text/html" href="https://linguifex.com/w/index.php?title=Module:fun/xpcall&amp;action=history"/>
	<updated>2026-04-03T20:18:56Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.6</generator>
	<entry>
		<id>https://linguifex.com/w/index.php?title=Module:fun/xpcall&amp;diff=478827&amp;oldid=prev</id>
		<title>Sware: Created page with &quot;local xpcall = xpcall  -- In Lua 5.2+, xpcall() can handle arguments natively, so return the -- built-in version if the argument passed to the test function is returned. if select(2, xpcall(function(v) 	return v -- 1 if xpcall() passes arguments, or nil if not end, xpcall, 1)) == 1 then 	return xpcall end  local table_pack_module = &quot;Module:table/pack&quot;  local unpack = unpack or table.unpack -- Lua 5.2 compatibility  local function pack(...) 	pack = require(table_pack_modu...&quot;</title>
		<link rel="alternate" type="text/html" href="https://linguifex.com/w/index.php?title=Module:fun/xpcall&amp;diff=478827&amp;oldid=prev"/>
		<updated>2025-11-25T17:13:13Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;local xpcall = xpcall  -- In Lua 5.2+, xpcall() can handle arguments natively, so return the -- built-in version if the argument passed to the test function is returned. if select(2, xpcall(function(v) 	return v -- 1 if xpcall() passes arguments, or nil if not end, xpcall, 1)) == 1 then 	return xpcall end  local table_pack_module = &amp;quot;Module:table/pack&amp;quot;  local unpack = unpack or table.unpack -- Lua 5.2 compatibility  local function pack(...) 	pack = require(table_pack_modu...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;local xpcall = xpcall&lt;br /&gt;
&lt;br /&gt;
-- In Lua 5.2+, xpcall() can handle arguments natively, so return the&lt;br /&gt;
-- built-in version if the argument passed to the test function is returned.&lt;br /&gt;
if select(2, xpcall(function(v)&lt;br /&gt;
	return v -- 1 if xpcall() passes arguments, or nil if not&lt;br /&gt;
end, xpcall, 1)) == 1 then&lt;br /&gt;
	return xpcall&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local table_pack_module = &amp;quot;Module:table/pack&amp;quot;&lt;br /&gt;
&lt;br /&gt;
local unpack = unpack or table.unpack -- Lua 5.2 compatibility&lt;br /&gt;
&lt;br /&gt;
local function pack(...)&lt;br /&gt;
	pack = require(table_pack_module)&lt;br /&gt;
	return pack(...)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Smuggle the function and arguments in via upvalues. There is no risk of&lt;br /&gt;
-- collisions across stack levels, because in any given call they are set&lt;br /&gt;
-- before being accessed, then accessed and reset to nil before calling `func`.&lt;br /&gt;
local _func, _args&lt;br /&gt;
&lt;br /&gt;
local function call()&lt;br /&gt;
	local func, args = _func, _args&lt;br /&gt;
	_func, _args = nil, nil&lt;br /&gt;
	return func(unpack(args, 1, args.n))&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[==[&lt;br /&gt;
A version of {xpcall} which takes any arguments to be given to {func} as additional arguments after the error handler.&lt;br /&gt;
&lt;br /&gt;
This fixes a deficiency in the standard version of {xpcall}, which is not able to handle arguments to be given to {func}, and brings it in line with {pcall}.]==]&lt;br /&gt;
return function(func, err_handler, ...)&lt;br /&gt;
	_func, _args = func, pack(...)&lt;br /&gt;
	return xpcall(call, err_handler)&lt;br /&gt;
end&lt;/div&gt;</summary>
		<author><name>Sware</name></author>
	</entry>
</feed>