lua-users home
lua-l archive

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


Helo

Thank you very very much. It works! Now I can finaly load my level data.
I am starting to realy like this LUA lenguage. :-)

Bye 



On Tue, 29 Apr 2003 at 13:28:29, Tomas wrote:

> > I have embeded LUA in my VC++6.0. Now I know haw to simple tabel data out
> by 
> > lua_getglobal(), lua_pushstring() and lua_gettable() via stack. But I dont
> > know haw to get data out if I have table inside the table.
> 	It's almost the same!  A table is a value like others:
> 
> > > function get (i, j)
> > > 	return EnemyList["Enemy"..i][j]
> > > end
> /* untested code */
> void get (lua_State *L, int i, char *j) {
> 	/* push EnemyList table on stack */
> 	lua_pushstring (L, "EnemyList");
> 	lua_rawget (L, LUA_GLOBALSINDEX);
> 	/* first key */
> 	lua_pushstring (L, "Enemy");
> 	lua_pushnumber (L, i);
> 	lua_concat (L, 2);
> 	/* get the "Enemy?" table */
> 	lua_gettable (L, -2);
> 	/* second key (the field name) */
> 	lua_pushstring (L, j);
> 	/* get result */
> 	lua_gettable (L, -2);
> }
> 
> 	The result will be on top of the stack!
> 		Tomas
> 
> > > > Haw do I get out path or x,y,z from this table? 
> > > > 
> > > > EnemyList = {
> > > >     
> > > >     Enemy1 = {
> > > >         path = ".\mesh\kock4.x",
> > > >         x = 67,
> > > >         y = 57,
> > > >         z = 23
> > > >     },
> > > > 
> > > >     Enemy2 = {
> > > >         path = ".\mesh\kock2.x",
> > > >         x = 10,
> > > >         y = 1,
> > > >         z = 45
> > > >     }
> > > > }
> > > 	Do you mean EnemyList.Enemy1.path?  Or a generic
> > > way?  Something like:
> > > 
> > > 
> > > get (1, 'path')
> > > 
> > > 	might give you the same result.
> > > 		Tomas
> > 
> > 
> > 
> > ____________________
> > http://www.email.si/
> >



____________________
http://www.email.si/