Fix the test case added in the previous commit
Fix the test case added in the previous commit

Instead of having a global variable that stores a Lua thread, the global
variable is now only used for its address. This address is an index into
the registry where we can find the marshalling thread.

I am not really sure that this patch is okay. According to [1], we are
"basically" allowed to call anything that has no chance of running Lua
code. This "roughly" corresponds to everything that cannot raise errors,
minus lua_pcall.

So, lua_newthread() is not allowed, because that allocates memory, which
could cause a GC step. The new code added in this commit calls
lua_pushlightuserdata(), lua_rawget(), lua_tothread(), and lua_pop()
which are all documented to not cause errors or allocate memory. Let's
hope this is okay.

This commit fixes the segfaults in the test case added in the previous
commit.

[1] http://lua-users.org/lists/lua-l/2017-11/msg00095.html

Signed-off-by: Uli Schlachter <346c0ad49ac8427b61b3b55abbe37dc0ebd524f2@znc.in>

pavouk/lgi