patch from ToxicFrog

This commit is contained in:
Rebecca Kelly
2022-05-31 19:09:52 -04:00
committed by nhmall
parent 42981361d7
commit 78658e9609
2 changed files with 30 additions and 34 deletions
+17 -19
View File
@@ -608,30 +608,28 @@ static const luaL_Reg l_obj_meta[] = {
int int
l_obj_register(lua_State *L) l_obj_register(lua_State *L)
{ {
int lib_id, meta_id; /* Table of instance methods (e.g. an_object:isnull())
and static methods (e.g. obj.new("dagger")). */
/* newclass = {} */
lua_createtable(L, 0, 0);
lib_id = lua_gettop(L);
/* metatable = {} */
luaL_newmetatable(L, "obj");
meta_id = lua_gettop(L);
luaL_setfuncs(L, l_obj_meta, 0);
/* metatable.__index = _methods */
luaL_newlib(L, l_obj_methods); luaL_newlib(L, l_obj_methods);
lua_setfield(L, meta_id, "__index");
/* metatable.__metatable = _meta */ /* metatable = { __name = "obj", __gc = l_obj_gc } */
luaL_newmetatable(L, "obj");
luaL_setfuncs(L, l_obj_meta, 0);
/* metatable.__index points at the object method table. */
lua_pushvalue(L, -2);
lua_setfield(L, -2, "__index");
/* Don't let lua code mess with the real metatable.
Instead offer a fake one that only contains __gc. */
luaL_newlib(L, l_obj_meta); luaL_newlib(L, l_obj_meta);
lua_setfield(L, meta_id, "__metatable"); lua_setfield(L, -2, "__metatable");
/* class.__metatable = metatable */ /* We don't need the metatable anymore. It's safe in the
lua_setmetatable(L, lib_id); Lua registry for use by luaL_setmetatable. */
lua_pop(L, 1);
/* _G["obj"] = newclass */ /* global obj = the method table we created at the start */
lua_setglobal(L, "obj"); lua_setglobal(L, "obj");
return 0; return 0;
} }
+13 -15
View File
@@ -874,29 +874,27 @@ static const luaL_Reg l_selection_meta[] = {
int int
l_selection_register(lua_State *L) l_selection_register(lua_State *L)
{ {
int lib_id, meta_id; /* Table of instance methods and static methods. */
luaL_newlib(L, l_selection_methods);
/* newclass = {} */ /* metatable = { __name = "selection", __gc = l_selection_gc } */
lua_createtable(L, 0, 0);
lib_id = lua_gettop(L);
/* metatable = {} */
luaL_newmetatable(L, "selection"); luaL_newmetatable(L, "selection");
meta_id = lua_gettop(L);
luaL_setfuncs(L, l_selection_meta, 0); luaL_setfuncs(L, l_selection_meta, 0);
/* metatable.__index = _methods */ /* metatable.__index points at the selection method table. */
luaL_newlib(L, l_selection_methods); lua_pushvalue(L, -2);
lua_setfield(L, meta_id, "__index"); lua_setfield(L, -2, "__index");
/* metatable.__metatable = _meta */ /* Don't let lua code mess with the real metatable.
Instead offer a fake one that only contains __gc. */
luaL_newlib(L, l_selection_meta); luaL_newlib(L, l_selection_meta);
lua_setfield(L, meta_id, "__metatable"); lua_setfield(L, -2, "__metatable");
/* class.__metatable = metatable */ /* We don't need the metatable anymore. It's safe in the
lua_setmetatable(L, lib_id); Lua registry for use by luaL_setmetatable. */
lua_pop(L, 1);
/* _G["selection"] = newclass */ /* global selection = the method table we created at the start */
lua_setglobal(L, "selection"); lua_setglobal(L, "selection");
return 0; return 0;