[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Returning a table from a C function
- From: Tomas <tomas@...>
- Date: Wed, 21 May 2003 10:39:36 -0300 (BRT)
> void ObjectFactory::CreateThing(lua_state* L)
^^^^
Lua C Functions should return an int.
int ObjectFactory::CreateThing(lua_state* L)
> {
> Thing* pThing = new Thing();
>
> // Create table and push onto stack
> lua_newtable(L);
>
> // Get index of table on stack
> int index = lua_gettop(L);
>
> // Add function to table
> addmemberobjthunk(L, "DoSomething", MyThunker, pThing, pDoThingFn,
> index);
>
> // Add object ptr into table as 'id'
> addmemberdata(L, "id", pThing, index);
>
> // Table is be returned back to Lua
return 1; // number of stack elements to return
> }
I didn't tested it.
Tomas