mirror of
https://github.com/luanti-org/luanti.git
synced 2025-09-05 18:41:05 +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
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue