lua-users home
lua-l archive

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


Ultron14@aol.com wrote:
> 
> lua_newtable(state);
> state->lua_pushstring("active"); state->lua_pushnumber(lastworld->active);
> lua_settable(state,-3);
> 
> I have 2 questions:
> 
> 1) How do I change the above to return just a table with just values, and not
> a property/value table

I assume you mean this kind of tables: { "foo", "bar" }

These are regular tables.  Only the keys are the numbers 1, 2, ...

lua_newtable(state);
lua_pushnumber(state, 1);
lua_pushnumber(state, lastworld->active);
lua_settable(state,-3);

or:

lua_newtable(state);
lua_pushnumber(state, lastworld->active);
lua_rawseti(state, -2, 1);  // the 1 is the numeric index

> 2) how I GET the values from a table passed in (both indexed and with
> properties)

Same as above:

lua_pushstring(state, "active");
lua_gettable(state, <tableindex>);

or

lua_pushnumber(state, 1);
lua_gettable(state, <tableindex>);

or

lua_rawgeti(state, <tableindex>, 1);  // get field nr 1

or iterate over all elements using lua_next().

Ciao, ET.