Skip to content

Garbage collector is trying to destroy current lua_State* #774

Answered by vegorov-rbx
LucaSalmin asked this question in Q&A
Discussion options

You must be logged in to vote

Like in Lua, all garbage-collectable objects have to be reachable from global lua_State, even other lua_State threads.
This is best described in chapter '30.1 Multiple Threads' in the latest 'Programming in Lua' book, but that's not available online.

The solution is to pin an object in the Registry using lua_ref.
It will return an index that you can 'release' later using lua_unref when you don't need the thread any more.
You can also use this index in lua_getref to place the object on the stack.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by LucaSalmin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants