lua-users home
lua-l archive

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



On Oct 7, 2014, at 11:58 PM, Philipp Kraus <philipp.kraus@tu-clausthal.de> wrote:


Can you clarify your intent here? Are you trying to clone the *current state* of an existing lua_State, so that when cloned it can continue from the point of the clone, or are you trying to clone the original chunk of Lua code that was launched by the source state? Some of your posts seem to imply this.

If you just wish to clone the script and re-start it, there should be no need for a deep copy unless you have loaded scripts externally at run-time. Otherwise, as the other posters have noted, you will end up in a complete mess trying to find out what state to copy.

What is the ultimate goal of cloning the Lua state anyway? Why do you need a copy constructor?

I have the lua_state* pointer encapsulate by a class and with the class ctor the Lua script is loaded in the Lua state.
I would like to overload the Copy-Ctor and =-operator in a way, that the lua_state* is point to a new Lua state (lua_newstate is called) and the data from the right-hand-side is copy to the new state (in this case the Lua script is pushed into the new lua state), but I load the the Lua script with luaL_loadstring, because the script is set by a database call. My current code excerpt of the =-operator:


Yes, I understand what a copy constructor does, but why do you want to actually copy a running Lua state? What is the end goal of having this functionality? As has been noted, there is *no* easy way to do this and so I was wondering why you needed to do this at all, and what alternatives could be proposed that might fit your needs.

—Tim