Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何删除使用foo创建的元表luaL_newmetatable( L, "foo" );,以便luaL_getmetatable( L, "foo" );再次推送 NIL 值?
foo
luaL_newmetatable( L, "foo" );
luaL_getmetatable( L, "foo" );
无论您出于何种原因必须删除元表,都是有可能的。luaL_newmetatable(L, "foo")创建一个表,该表使用键 存储在 Lua 注册表中"foo"。
luaL_newmetatable(L, "foo")
"foo"
要删除表,只需将"foo"注册表中的字段设置为nil. C中的代码:
nil
lua_pushnil(L); lua_setfield(L, LUA_REGISTRYINDEX, "foo");
Lua 中的等效代码:
debug.getregistry()["foo"] = nil