aboutsummaryrefslogtreecommitdiff
path: root/src/script/lua_api/l_storage.cpp
diff options
context:
space:
mode:
authorJude Melton-Houghton <jwmhjwmh@gmail.com>2022-10-04 08:31:36 -0400
committerGitHub <noreply@github.com>2022-10-04 08:31:36 -0400
commit7632af3c73fc4e4ae3ad4c98c90c39b47c3b8379 (patch)
tree08b974d6ecafb6c20de565f96e329748030c1519 /src/script/lua_api/l_storage.cpp
parentb21fb1837955e6385137184cac906245821b20e4 (diff)
downloadminetest-7632af3c73fc4e4ae3ad4c98c90c39b47c3b8379.tar.xz
Consolidate API object code (#12728)
Co-authored-by: sfan5 <sfan5@live.de>
Diffstat (limited to 'src/script/lua_api/l_storage.cpp')
-rw-r--r--src/script/lua_api/l_storage.cpp45
1 files changed, 1 insertions, 44 deletions
diff --git a/src/script/lua_api/l_storage.cpp b/src/script/lua_api/l_storage.cpp
index d1cb1fa9c..4b3863ca9 100644
--- a/src/script/lua_api/l_storage.cpp
+++ b/src/script/lua_api/l_storage.cpp
@@ -49,52 +49,9 @@ void StorageRef::create(lua_State *L, const std::string &mod_name, ModMetadataDa
lua_setmetatable(L, -2);
}
-int StorageRef::gc_object(lua_State *L)
-{
- StorageRef *o = *(StorageRef **)(lua_touserdata(L, 1));
- delete o;
- return 0;
-}
-
void StorageRef::Register(lua_State *L)
{
- lua_newtable(L);
- int methodtable = lua_gettop(L);
- luaL_newmetatable(L, className);
- int metatable = lua_gettop(L);
-
- lua_pushliteral(L, "__metatable");
- lua_pushvalue(L, methodtable);
- lua_settable(L, metatable); // hide metatable from Lua getmetatable()
-
- lua_pushliteral(L, "metadata_class");
- lua_pushlstring(L, className, strlen(className));
- lua_settable(L, metatable);
-
- lua_pushliteral(L, "__index");
- lua_pushvalue(L, methodtable);
- lua_settable(L, metatable);
-
- lua_pushliteral(L, "__gc");
- lua_pushcfunction(L, gc_object);
- lua_settable(L, metatable);
-
- lua_pushliteral(L, "__eq");
- lua_pushcfunction(L, l_equals);
- lua_settable(L, metatable);
-
- lua_pop(L, 1); // drop metatable
-
- luaL_register(L, nullptr, methods); // fill methodtable
- lua_pop(L, 1); // drop methodtable
-}
-
-StorageRef* StorageRef::checkobject(lua_State *L, int narg)
-{
- luaL_checktype(L, narg, LUA_TUSERDATA);
- void *ud = luaL_checkudata(L, narg, className);
- if (!ud) luaL_typerror(L, narg, className);
- return *(StorageRef**)ud; // unbox pointer
+ registerMetadataClass(L, className, methods);
}
IMetadata* StorageRef::getmeta(bool auto_create)