Original Post
table is only struct in table. but it is simple. How to describe the struct below: struct A { int id; string name; string parent; string type; } table A = {} .........//still no solution
int lua_GetA( lua_State* state ){ A* a = getA( "..whatever you're gonna do to get the value/pointer/whatever you want.." ); // create a new table lua_newtable( state ); // push the ID lua_pushstring(state, "id"); lua_pushnumber(state, a->id); // set the table lua_settable( state, -3 ); // rinse and repeat.. // push the name lua_pushstring(state, "name"); lua_pushstring(state, a->name.c_str()); lua_settable( state, -3 ); // push the parent lua_pushstring(state, "parent"); lua_pushstring(state, a->parent.c_str()); lua_settable( state, -3 ); // push the type lua_pushstring(state, "type"); lua_pushstring(state, a->type.c_str()); lua_settable( state, -3 ); // return the table return 1;}myA = GetA( "I don't know, some value used to tell what A you want?" )SetAPosition( myA.id, 24, 32 )SetAAwesomeness( myA.id, 2000000000 ) -- two billion!Quote:
Original post by luasitdown
table is only struct in table. but it is simple.
How to describe the struct below:
struct A
{
int id;
string name;
string parent;
string type;
}
table A = {}
.........//still no solution
local A = {}; -- A is a tableA['id'] = 230; --A['name'] = 'foo';A['parent'] = B;A['type'] = 'big_scary_monster';function Gloat() print('I'm gloating') endA['on_kill'] = Gloat;function MakeStruct(id, name, parent, type) local tmp = {} tmp['id'] = id; tmp['name'] = name; tmp['parent'] = parent; tmp['type'] = type; return tmp;endlocal X = MakeStruct( 20, "my_name", "dads_name", "wimp" );print( X['id'] );This topic has been locked by a moderator. New replies are not allowed.
With your permission, GameDev.net uses analytics cookies to understand how people use the platform. You can accept analytics or continue with necessary cookies only. Learn more