diff options
Diffstat (limited to 'src/script/lua_api/l_camera.cpp')
-rw-r--r-- | src/script/lua_api/l_camera.cpp | 44 |
1 files changed, 7 insertions, 37 deletions
diff --git a/src/script/lua_api/l_camera.cpp b/src/script/lua_api/l_camera.cpp index d85d16283..aef90562b 100644 --- a/src/script/lua_api/l_camera.cpp +++ b/src/script/lua_api/l_camera.cpp @@ -165,17 +165,6 @@ int LuaCamera::l_get_aspect_ratio(lua_State *L) return 1; } -LuaCamera *LuaCamera::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 *(LuaCamera **)ud; -} - Camera *LuaCamera::getobject(LuaCamera *ref) { return ref->m_camera; @@ -183,12 +172,9 @@ Camera *LuaCamera::getobject(LuaCamera *ref) Camera *LuaCamera::getobject(lua_State *L, int narg) { - LuaCamera *ref = checkobject(L, narg); + LuaCamera *ref = checkObject<LuaCamera>(L, narg); assert(ref); - Camera *camera = getobject(ref); - if (!camera) - return NULL; - return camera; + return getobject(ref); } int LuaCamera::gc_object(lua_State *L) @@ -200,27 +186,11 @@ int LuaCamera::gc_object(lua_State *L) void LuaCamera::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_pop(L, 1); - - luaL_register(L, nullptr, methods); - lua_pop(L, 1); + static const luaL_Reg metamethods[] = { + {"__gc", gc_object}, + {0, 0} + }; + registerClass(L, className, methods, metamethods); } // clang-format off |