wplua: use the registry to store vtables & closures

This commit is contained in:
George Kiagiadakis 2020-12-16 23:19:07 +02:00
parent 70931969b4
commit da375a7408
3 changed files with 10 additions and 5 deletions

View file

@ -117,7 +117,8 @@ wplua_function_to_closure (lua_State *L, int idx)
WpLuaClosure *wlc = (WpLuaClosure *) c;
GPtrArray *closures;
lua_getglobal (L, "__wplua_closures");
lua_pushliteral (L, "wplua_closures");
lua_gettable (L, LUA_REGISTRYINDEX);
closures = wplua_toboxed (L, -1);
lua_pop (L, 1);
@ -149,6 +150,7 @@ _wplua_init_closure (lua_State *L)
{
GPtrArray *a = g_ptr_array_new_with_free_func (
(GDestroyNotify) _wplua_closure_destroy);
lua_pushliteral (L, "wplua_closures");
wplua_pushboxed (L, G_TYPE_PTR_ARRAY, a);
lua_setglobal (L, "__wplua_closures");
lua_settable (L, LUA_REGISTRYINDEX);
}

View file

@ -100,7 +100,8 @@ _wplua_gobject___index (lua_State *L)
lua_CFunction func = NULL;
GHashTable *vtables;
lua_getglobal (L, "__wplua_vtables");
lua_pushliteral (L, "wplua_vtables");
lua_gettable (L, LUA_REGISTRYINDEX);
vtables = wplua_toboxed (L, -1);
lua_pop (L, 1);

View file

@ -62,8 +62,9 @@ wplua_new (void)
{
GHashTable *t = g_hash_table_new (g_direct_hash, g_direct_equal);
lua_pushliteral (L, "wplua_vtables");
wplua_pushboxed (L, G_TYPE_HASH_TABLE, t);
lua_setglobal (L, "__wplua_vtables");
lua_settable (L, LUA_REGISTRYINDEX);
}
return L;
@ -98,7 +99,8 @@ wplua_register_type_methods (lua_State * L, GType type,
if (methods) {
GHashTable *vtables;
lua_getglobal (L, "__wplua_vtables");
lua_pushliteral (L, "wplua_vtables");
lua_gettable (L, LUA_REGISTRYINDEX);
vtables = wplua_toboxed (L, -1);
lua_pop (L, 1);