[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Return a variable number of values from function
- From: Thiago Conde Figueiro <thiago@...>
- Date: Mon, 19 Nov 2001 09:33:21 -0200
On Mon, 19 Nov 2001 01:11:38 +0100, "Matthias Gall" <matthias@sechsta-sinn.de> wrote:
MG> So, I tried this with a C function, which is registered properly. It pushes
MG> some random values and returns the number of values (lua_pushnumber(MyState,
MG> iRandomNumber); ... return iNumOfNumbers;). Using getn on the result of this
MG> 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. Instead you should do something like
function foo()
local RetVal = {}
while (getting return values) do
tinsert(RetVal, ReturnValueN)
end
return RetVal
end
Now getn(foo()) will work. I think. :)
Regards,
--
Thiago Conde Figueiró
Infraestrutura
Cipher Technology
http://www.ciphertech.com.br/
_____
"Segurança em TI - uma especialidade Cipher Technology"