How can I delete a metatable foo
created with luaL_newmetatable( L, "foo" );
, so that luaL_getmetatable( L, "foo" );
will push a NIL value again?
Asked
Active
Viewed 1,102 times
1 Answers
4
Whatever the reason you may have to delete the metatable, it is possible. luaL_newmetatable(L, "foo")
creates a table, which is stored in the Lua registry with the key "foo"
.
To delete the table, just set the field "foo"
in the registry to nil
. The code in C:
lua_pushnil(L);
lua_setfield(L, LUA_REGISTRYINDEX, "foo");
Equivalent code in Lua:
debug.getregistry()["foo"] = nil

Michal Kottman
- 16,375
- 3
- 47
- 62