So I have a very simple Lua script like this:
return coroutine.create(function () coroutine.yield(1) end)
And then in C I run it and gets the returned value
lua_State* l = luaL_newstate();
if(luaL_dostring(l, script) == LUA_OK) {
lua_State* co = lua_tothread(l, lua_gettop(l));
lua_pop(l, 1);
}
Later, the C code will pass the co
pointer back into Lua (with lua_pushthread
) and run coroutine.resume(co)
.
I would like to know if Lua will GC the coroutine object in the meantime, rendering the co
pointer in C invalid? If yes, what can I do to prevent that?