July 2018
Beginner
202 pages
5h 42m
English
Lua offers the lua_settable (lua_State*, int) function to set fields in a table. The function returns nothing. Its first argument is the Lua state to work on and the second argument is the index of a table on the stack.
The value being set is expected to be on top of the stack, and the key to set it to is expected to be just below that. lua_settable will pop both the key and value off the stack, but it will leave the table on the stack.
For example, the Lua code vector["y"] = 7 could be written with this API as follows:
// Push vector onto the stacklua_gettable(L, "vector");// Push y onto the stacklua_pushstring(L, "y");// Push 7 onto the stacklua_pushnumber(L, 7);// The stack has three new variables on it// The ...