There are heaps of examples of how to clone a Lua table in Lua, however I wasn’t able to find any example of how to do it with the native Lua C API. I tried to do it by hand twice, but ended up with a real (although working) mess.
Does anyone have any tips or links on how to elegantly do a shallow copy of a Lua table in the C API?
What you need to do is define the Lua function, and then break it down into the associated API calls.
So we’re going to need to take the index of a table on the stack and the lua_State.
Now our copied table sits on the top of the stack.
Christ, the Lua API sucks.