Created
February 24, 2017 14:23
-
-
Save tst2005/d2848767ac821b0d8ac50dd7985bbeae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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