aboutsummaryrefslogtreecommitdiff
path: root/src/script/lua_api/l_camera.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_camera.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_camera.cpp')
-rw-r--r--src/script/lua_api/l_camera.cpp44
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