Here's what I have so far... It creates global table called "mod", but I can't seem to add indexes to the table...
lua_newtable(L);
lua_setglobal(L,"mod");
                The manual says:
void lua_setfield (lua_State *L, int index, const char *k);Does the equivalent to
t[k] = v, wheretis the value at the given valid index andvis the value at the top of the stack.This function pops the value from the stack.
So, more precisely: Push whatever you want to add onto the stack, then call lua_setfield.  For example:
lua_pushnumber( L, 42 );
lua_setfield( L, -2, "answer_to_life_universe_and_rest" )
This inserts the field "answer_to_life..." with value 42 into the table.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With