What you need to do is define a Lua function and then break it down into related API calls.
shallow_copy = function(tab) local retval = {} for k, v in pairs(tab) do retval[k] = v end return retval end
So, we will need to take the index of the table on the stack and lua_State.
void shallow_copy(lua_State* L, int index) { lua_newtable(L); lua_pushnil(L); while(lua_next(L, index) != 0) { lua_pushvalue(L, -2); lua_insert(L, -2); lua_settable(L, -4); } }
Now our copied table is at the top of the stack.
Christ, Lua API sucks.
Puppy source share