[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: Odd behaviour with multiple return values and varargs
- From: "Mason Deaver" <mc.deaver@...>
- Date: Sat, 15 Sep 2007 13:42:21 -0500
How about this alternative (variation of code submitted by
Tom Miles):
function Position()
return { 1,2 }
end
function Dimensions()
return { 100,200 }
end
function push_clip(pos,dim)
x, y = unpack(pos)
w,h = unpack(dim)
print(x,y,w,h)
end
push_clip(Position(), Dimensions())
-- prints: 1 2 100 200
This at least hides from the parent code details about what
Position() and Dimensions() are returning.
Mason Deaver
----------
Tom Miles wrote:
> function Position()
> return x,y
> end
>
> function Dimensions()
> return w,h
> end
>
> function push_clip(x,y,w,h)
> -- Do stuff
> end
>
> push_clip(Position(), Dimensions())
>
> As it is, I have to do:
> local x,y = Position()
> push_clip(x,y, Dimensions())