lua-users home
lua-l archive

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

Thanks Andrew for these valuable information.
I got from cqueues source code (in fact, Lua's lstrlib.c), I have to use lua_dump() and a wrapper to store the result.
Then, I'll have to find how to load it back in a new state.

Thanks again.

Le lundi 9 avril 2018 à 21:36:15 UTC+2, Andrew Gierth <> a écrit :

>>>>> "Laurent" == Laurent FAILLIE <> writes:

Laurent> So, what should I do to correctly call a function in another
Laurent> thread ?

Dump the function to a bytecode string and load the string in the other


You can't safely do it any other way, because each "main" state has its
own independent garbage collection, and can't know whether any of its
objects are referenced by other main states. Even if you worked around
that by holding references to everything, you'd fall foul of memory
synchronization issues, string interning issues, and all sorts of other
breakage (some of which you mentioned in your message).

If you turn on API checks, you'll notice that lua_xmove will abort if
you try and move values between independent states; this operation is
forbidden. The only way to communicate values between independent states
is to serialize them in some form.

(cqueues has an example, you might look at that)