mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Consolidate API object code (#12728)
Co-authored-by: sfan5 <sfan5@live.de>
This commit is contained in:
parent
b21fb18379
commit
7632af3c73
42 changed files with 463 additions and 1079 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue