Created
December 10, 2010 17:04
-
-
Save garybernhardt/736472 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
function wrap(f) | |
return function() | |
-- Storing the result of the wrapped function is the source of the | |
-- problem. | |
result = f() | |
return result | |
end | |
end | |
function f() | |
return 1, 2 | |
end | |
f = wrap(f); | |
x, y = f() | |
assert(x == 1 and y == 2) | |
-- The assertion will fail: x will be 1 and y will be nil. The variable-length | |
-- return of f() doesn't get passed through the wrapper. When the wrapper says | |
-- "result = f()", result gets only the first element of the variable return. | |
-- The rest are silently discarded. See my executable Lua spec for examples | |
-- that show this in detail: | |
-- <https://github.com/garybernhardt/LuaSpec/blob/master/spec/function_spec.lua>. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment