Skip to content

Instantly share code, notes, and snippets.

@tst2005
Created February 24, 2017 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tst2005/d2848767ac821b0d8ac50dd7985bbeae to your computer and use it in GitHub Desktop.
Save tst2005/d2848767ac821b0d8ac50dd7985bbeae to your computer and use it in GitHub Desktop.
local function test(f)
local function pack2end(a1, ...)
return a1, {...}
end
local ok, t_result = pack2end(pcall(f))
if not ok then
return("error="..t_result[1] )
else
return("ok="..#t_result )
end
end
assert(
test(function() return 1, 2, 3 end) == "ok=3"
)
assert( string.find(
test(function() error("raise an error") end),
"^error=.*raise an error$" )
)
print("OK")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment