lua-users home
lua-l archive

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


Is there a built in Lua function to copy one table to another in C, or do I
need to use lua_next()/lua_rawget()/lua_rawset() to do that effectively? I
ask, because in my application I want to use one lua_State that may run
multiple, self-contained scripts. Before each script is run, I want to
"switch out" the globals table for the given script, and switch in the
globals table for the script about to be run (scripts will be represented by
objects in my engine, so I will have a way to identify which globals table
belongs to which object).

Also, once I have made a copy of the globals table, what is the best way to
store that copy in a way that I can quickly get it back? I was thinking of
using the registry, in that each object, at create time, will have a unique
globals tracking id. When I switch the context of the state to that object,
I will fetch its globals table from the registry and swap it in to the
globals table.

I know in Lua, this is very easy to do. I can simply do (correct me if my
syntax is bad):

newGlobs = {}
oldGlobs = globals()

globals(newGlobs)
globals(oldGlobs)

I guess what I am asking is: is there an easy way to mimic that using the C
API.

Thanks,

Matt