Skip to content

Instantly share code, notes, and snippets.

@garybernhardt
Created December 10, 2010 17:04
Show Gist options
  • Save garybernhardt/736472 to your computer and use it in GitHub Desktop.
Save garybernhardt/736472 to your computer and use it in GitHub Desktop.
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