[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Passing arrays(tables) between C++ and Lua and vice versa
- From: "Zé Pedro" <zarroba@...>
- Date: Tue, 13 Jun 2006 10:53:42 +0100
Hi,
I'm creating some functions in c++ and making them available to lua. Some of this functions required to return and/or receive arrays (in lua arrays are implemented with tables right?).
For example, I have a function called setEffects that can receive an indetermined number of ints. How can I do this? I have tried the following code:
int LCamera::setEffects(lua_State *L)
{
int argument = 1;
try
{
lua_Number effect;
while (true)
{
luaL_checktype(L, argument, LUA_TNUMBER);
effect = luaL_checkint(L,1);
cout << "effect: " << effect << cout;
argument++;
}
} catch (...)
{
//Do nothing. Only checking number of arguments
cout << "number of arguments: " << argument << endl;
}
return 0;
}
I did this hoping that when there were no more arguments an exception would be thrown and catched in the try-catch block, but it isn't the case. An alternative is to pass as argument an array but how?
The other problem is to return a table. If I have a method that can return several values how can I do it?
thanks,
Jose Tavares
PS: sorry for the poor english
--
Believe nothing, no matter where you read it, or who said it,
no matter if I have said it, unless it agrees with your own reason
and your common sense.
- Buda
Para quê ter olhos azuis, se a Natureza deixa os meus vermelhos?
- Bob Marley
"Don't try to use what you learn from Buddhism to be a Buddhist;
use it to be a better whatever-you-already-are."
- His Holiness the 14th Dalai Lama
Idealism is what precedes experience; cynicism is what follows.
- David T. Wolf
"Please don't download, because I want to get a pool in my second home."
- Kanye West