[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Wrong number of elements in stack ...
- From: "Andrei A. Voropaev" <avorop@...>
- Date: Fri, 7 May 2004 14:22:48 +0200
On Fri, May 07, 2004 at 01:44:09PM +0200, Gil Damoiseaux wrote:
> Hi,
>
> I'm using Lua since some months now, and I've come across a problem today
> that I've never noticed. I have a C++ function that returns 3 integers, let
> says a GetPosition() that return x,y and z.
>
> when I do:
> print(GetPosition())
> I have :
> 12 34 55
>
> But when I do
> print(GetPosition(),99)
> I have:
> 12 99
>
> Is this really normal? Or did I miss something?
Yes, you are missing careful read of documentation :)
[Quote from manual section 2.5.7]
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).
HTH
Andrei