Re: [luabind] Iterating through a table (luabind::object)
Brought to you by:
arvidn,
daniel_wallin
From: anders l. <and...@gm...> - 2006-05-11 10:07:55
|
Dereferencing the iterator gives you a luabind::object, similarly object.ke= y() gives you another object. Use object_cast<> to get your data back for ( luabind::iterator i( myLuaObject ), end; i !=3D end; ++i ) { string strKey =3D object_cast<string>( i.key() ); luabind::object val =3D *i; if ( luabind::type( val ) =3D=3D LUA_TNUMBER ) { // ... deal with number type e.g. object_cast<double>( val ) } else if ( luabind::type( val ) =3D=3D LUA_TSTRING ) { // deal with string type e.g. object_cast<string>( val ) } else { // handle error } } Anders On 5/11/06, Jesse Van Beurden <be...@in...> wrote: > > Hi, > I'd like to iterate through a lua table just printing out the key/value > along the way. I'm not really sure how to get the data out of the iterato= r > though. > > Here is what I have so far (myLuaObject is guaranteed to be a table): > > //... > for(luabind::iterator i(myLuaObject), end; i !=3D end; i++) { > printf("%s =3D %s (or %d for 'number')\n", __KEY__, __VALUE__); > } > //... > > I believe i.key() gives a luabind object? How do you get the string for > the key out of it? And how do you extract the string (or number) for the > value as well (type(value) is also guaranteed to always be either 'string= ' > or 'number')? I haven't been able to find an answer by searching the > mailing list, or reading the luabind source. > > Thank you, > Jesse Van Beurden. > > > > ------------------------------------------------------- > Using Tomcat but need to do more? Need to support web services, security? > Get stuff done quickly with pre-integrated technology to make your job > easier > Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronim= o > http://sel.as-us.falkag.net/sel?cmd=3Dlnk&kid=3D120709&bid=3D263057&dat= =3D121642 > _______________________________________________ > luabind-user mailing list > lua...@li... > https://lists.sourceforge.net/lists/listinfo/luabind-user > |