aboutsummaryrefslogtreecommitdiff
path: root/src/script/lua_api/l_localplayer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/script/lua_api/l_localplayer.cpp')
-rw-r--r--src/script/lua_api/l_localplayer.cpp39
1 files changed, 6 insertions, 33 deletions
diff --git a/src/script/lua_api/l_localplayer.cpp b/src/script/lua_api/l_localplayer.cpp
index 1066beed1..ff9c61f53 100644
--- a/src/script/lua_api/l_localplayer.cpp
+++ b/src/script/lua_api/l_localplayer.cpp
@@ -401,17 +401,6 @@ int LuaLocalPlayer::l_hud_get(lua_State *L)
return 1;
}
-LuaLocalPlayer *LuaLocalPlayer::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 *(LuaLocalPlayer **)ud;
-}
-
LocalPlayer *LuaLocalPlayer::getobject(LuaLocalPlayer *ref)
{
return ref->m_localplayer;
@@ -419,7 +408,7 @@ LocalPlayer *LuaLocalPlayer::getobject(LuaLocalPlayer *ref)
LocalPlayer *LuaLocalPlayer::getobject(lua_State *L, int narg)
{
- LuaLocalPlayer *ref = checkobject(L, narg);
+ LuaLocalPlayer *ref = checkObject<LuaLocalPlayer>(L, narg);
assert(ref);
LocalPlayer *player = getobject(ref);
assert(player);
@@ -435,27 +424,11 @@ int LuaLocalPlayer::gc_object(lua_State *L)
void LuaLocalPlayer::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, "__index");
- lua_pushvalue(L, methodtable);
- lua_settable(L, metatable);
-
- lua_pushliteral(L, "__gc");
- lua_pushcfunction(L, gc_object);
- lua_settable(L, metatable);
-
- lua_pop(L, 1); // Drop metatable
-
- luaL_register(L, nullptr, methods); // fill methodtable
- lua_pop(L, 1); // Drop methodtable
+ static const luaL_Reg metamethods[] = {
+ {"__gc", gc_object},
+ {0, 0}
+ };
+ registerClass(L, className, methods, metamethods);
}
const char LuaLocalPlayer::className[] = "LocalPlayer";