diff options
Diffstat (limited to 'src/script/lua_api/l_env.cpp')
-rw-r--r-- | src/script/lua_api/l_env.cpp | 44 |
1 files changed, 7 insertions, 37 deletions
diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp index b26c89e7d..8f2dc0cb4 100644 --- a/src/script/lua_api/l_env.cpp +++ b/src/script/lua_api/l_env.cpp @@ -158,7 +158,7 @@ int LuaRaycast::l_next(lua_State *L) csm = getClient(L) != nullptr; #endif - LuaRaycast *o = checkobject(L, 1); + LuaRaycast *o = checkObject<LuaRaycast>(L, 1); PointedThing pointed; env->continueRaycast(&o->state, &pointed); if (pointed.type == POINTEDTHING_NOTHING) @@ -194,17 +194,6 @@ int LuaRaycast::create_object(lua_State *L) return 1; } -LuaRaycast *LuaRaycast::checkobject(lua_State *L, int narg) -{ - NO_MAP_LOCK_REQUIRED; - - luaL_checktype(L, narg, LUA_TUSERDATA); - void *ud = luaL_checkudata(L, narg, className); - if (!ud) - luaL_typerror(L, narg, className); - return *(LuaRaycast **) ud; -} - int LuaRaycast::gc_object(lua_State *L) { LuaRaycast *o = *(LuaRaycast **) (lua_touserdata(L, 1)); @@ -214,31 +203,12 @@ int LuaRaycast::gc_object(lua_State *L) void LuaRaycast::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); - - 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, "__call"); - lua_pushcfunction(L, l_next); - lua_settable(L, metatable); - - lua_pop(L, 1); - - luaL_register(L, nullptr, methods); - lua_pop(L, 1); + static const luaL_Reg metamethods[] = { + {"__call", l_next}, + {"__gc", gc_object}, + {0, 0} + }; + registerClass(L, className, methods, metamethods); lua_register(L, className, create_object); } |