lua-users home
lua-l archive

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


Hi lua coders!

I've been told lua_xmove is not to be used for moving data between lua_States that are not coroutines of each other. This is definitely true! So I've coded up a nice funtion which handles copying from state to state and it works fine supporting all the lua types.

Now to my question. After doing this function, I started to think. What if I just make every lua_State in my program a coroutine of each other? Then I could use lua_xmove all the time. But the problem is they would all share global variables, however, that can be fixed by just giving each new coroutine it's own global table....

Is this a valid solution?  What are the drawbacks/penalities?

To be clear, I suggest doing something like this:
At program start, create a master lua_State, then never create a new state again. Just always just lua_newthread on the master state, then give the new thread a separate global table...

On a separate note: I think my copy_state_state function is quite complete, and even handles userdata (if a special metamethod is defined), would there be interest in adding it to the lua_api so others don't have to reinvent it? Because it seems like a sorely lacking feature. It could probably be inserted behind the scenes in lua_xmove so that it does the state to state copy when lua_xmove is used on 2 states that are not coroutines of each other.

Jeff