aboutsummaryrefslogtreecommitdiff
path: root/src/script/lua_api/l_itemstackmeta.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/script/lua_api/l_itemstackmeta.cpp')
-rw-r--r--src/script/lua_api/l_itemstackmeta.cpp50
1 files changed, 3 insertions, 47 deletions
diff --git a/src/script/lua_api/l_itemstackmeta.cpp b/src/script/lua_api/l_itemstackmeta.cpp
index 5bae21a40..3c0f68406 100644
--- a/src/script/lua_api/l_itemstackmeta.cpp
+++ b/src/script/lua_api/l_itemstackmeta.cpp
@@ -24,17 +24,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "common/c_content.h"
/*
- NodeMetaRef
+ ItemStackMetaRef
*/
-ItemStackMetaRef* ItemStackMetaRef::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 *(ItemStackMetaRef**)ud; // unbox pointer
-}
IMetadata* ItemStackMetaRef::getmeta(bool auto_create)
{
@@ -54,7 +45,7 @@ void ItemStackMetaRef::reportMetadataChange(const std::string *name)
// Exported functions
int ItemStackMetaRef::l_set_tool_capabilities(lua_State *L)
{
- ItemStackMetaRef *metaref = checkobject(L, 1);
+ ItemStackMetaRef *metaref = checkObject<ItemStackMetaRef>(L, 1);
if (lua_isnoneornil(L, 2)) {
metaref->clearToolCapabilities();
} else if (lua_istable(L, 2)) {
@@ -77,13 +68,6 @@ ItemStackMetaRef::~ItemStackMetaRef()
istack->drop();
}
-// garbage collector
-int ItemStackMetaRef::gc_object(lua_State *L) {
- ItemStackMetaRef *o = *(ItemStackMetaRef **)(lua_touserdata(L, 1));
- delete o;
- return 0;
-}
-
// Creates an NodeMetaRef and leaves it on top of stack
// Not callable from Lua; all references are created on the C side.
void ItemStackMetaRef::create(lua_State *L, LuaItemStack *istack)
@@ -97,35 +81,7 @@ void ItemStackMetaRef::create(lua_State *L, LuaItemStack *istack)
void ItemStackMetaRef::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
+ registerMetadataClass(L, className, methods);
// Cannot be created from Lua
//lua_register(L, className, create_object);