Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

lua_xmove between different lua states

Tags:

lua

According to the lua 5.1 manual, lua_xmove moves values between stacks of different threads belonging to the same Lua state. But, I accidentally happened to use it to move values across different Lua states and it seemed to work fine! Is there any other API to move values from one Lua state to another (in 5.1), or can lua_xmove be used?

like image 512
vyom Avatar asked Oct 15 '13 18:10

vyom


1 Answers

Lua stores garbage collection data in the global state. So, if you move GC or string objects across states, you can potentially confuse the garbage collector and create dangling references.

So, while it might look like it works, it could just as easily cause problems later on.

For reference, see this mailing list thread where developers discuss this exact issue.

Note that lua_xmove does check that the global states are the same:

api_check(from, G(from) == G(to));
like image 122
nneonneo Avatar answered Dec 31 '22 19:12

nneonneo