lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Thankyou.  I missed that completely.  It's obvious now you've pointed it out
:)


-----Original Message-----
From: Tomas [mailto:tomas@ccpa.puc-rio.br]
Sent: 21 May 2003 14:40
To: Lua list
Subject: Re: Returning a table from a C function


> 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