Not enough arguments

Find quick help here to get you started with Hollywood
Post Reply
User avatar
lazi
Posts: 295
Joined: Fri Feb 25, 2011 12:08 am

Not enough arguments

Post by lazi » Thu Nov 16, 2017 11:18 am

Code: Select all

param1={10,10,100,20,#WHITE}
param2={20,20,100,20}
param3={30,100,20,#WHITE}

Box (Unpack(param1))
;Box (Unpack(param2),#WHITE)
Box (30,Unpack(param3))

WaitLeftMouse
                     
The second box command fails with "Not enough arguments".
How does the interpreter deals internally with the parameter list and cause that Unpack can throw parameters at the end, but not inside the parameter list?

Not a problem, just made me curious. :-)

User avatar
airsoftsoftwair
Posts: 2558
Joined: Fri Feb 12, 2010 3:33 pm
Location: Germany
Contact:

Re: Not enough arguments

Post by airsoftsoftwair » Sun Nov 19, 2017 12:36 pm

That's how the Lua interpreter works. This is what the Lua 5.0 reference manual says:
Because a function can return any number of results (see 2.4.4), the number of results must be adjusted before they are used. If the function is called as a statement (see 2.4.6), then its return list is adjusted to zero elements, thus discarding all returned values. If the function is called inside another expression or in the middle of a list of expressions, then its return list is adjusted to one element, thus discarding all returned values except the first one. If the function is called as the last element of a list of expressions, then no adjustment is made (unless the call is enclosed in parentheses).
In other words: The only way to make sure that Unpack()'s return values aren't adjusted to just one value is to use Unpack() as the last parameter...

Post Reply