[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: Return a variable number of values from function
- From: John Mckenna <jmckenna@...>
- Date: Mon, 19 Nov 2001 11:39:44 -0000
Thiago Conde Figueiro writes in reply to Matthias Gall:
>> So, I tried this with a C function, which is registered
>> properly. It pushes some random values and returns the
>> number of values (lua_pushnumber(MyState, iRandomNumber);
>> ...
>> return iNumOfNumbers;). Using getn on the result of this
>> function leads to a LUA_ERRRUN. Any suggestions?
> Yes. What getn() really does it look up the table for
>a field named "n".
>
>> return {6, "hello", {}, 32}
>
> No field name 'n' on that table, so getn() fails.
No - getn returns the value of the field named "n" if it exists. If there
is no field called "n", it returns the largest numerical index with a
non-nil value in the table.
Matthias should be pushing a single value (a table), instead of multiple
individual values and a count. Or he could push the multiple values and
count and use Edgar Toernig's pack() function (very nifty, btw!).
-Virus scanned and cleared ok