Save titan_globals to stack to avoid segfault
I thought I didn't need to save it because it was set as upvalue to the
init_modname closure, which was in turn added to the stack. However, the
lua_call pops this closure from the stack, which means that titan_globals
became garbage and could be collected.
@@ -69,6 +69,10 @@ int luaopen_${MODNAME}(lua_State *L)
Table *titan_globals = luaH_new(L);
luaH_resizearray(L, titan_globals, ${N_TOPLEVEL});
+ /* Save to stack because lua_call might invoke the GC*/
+ sethvalue(L, s2v(L->top), titan_globals);
+ api_incr_top(L);
+
{
CClosure *func = luaF_newCclosure(L, 1);
func->f = init_${MODNAME};
