1
0
Fork 0
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:
Jude Melton-Houghton 2022-10-04 08:31:36 -04:00 committed by GitHub
parent b21fb18379
commit 7632af3c73
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
42 changed files with 463 additions and 1079 deletions

View file

@ -44,7 +44,7 @@ int LuaVoxelManip::l_read_from_map(lua_State *L)
{
MAP_LOCK_REQUIRED;
LuaVoxelManip *o = checkobject(L, 1);
LuaVoxelManip *o = checkObject<LuaVoxelManip>(L, 1);
MMVManip *vm = o->vm;
if (vm->isOrphan())
return 0;
@ -65,7 +65,7 @@ int LuaVoxelManip::l_get_data(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
LuaVoxelManip *o = checkobject(L, 1);
LuaVoxelManip *o = checkObject<LuaVoxelManip>(L, 1);
bool use_buffer = lua_istable(L, 2);
MMVManip *vm = o->vm;
@ -90,7 +90,7 @@ int LuaVoxelManip::l_set_data(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
LuaVoxelManip *o = checkobject(L, 1);
LuaVoxelManip *o = checkObject<LuaVoxelManip>(L, 1);
MMVManip *vm = o->vm;
if (!lua_istable(L, 2))
@ -113,7 +113,7 @@ int LuaVoxelManip::l_write_to_map(lua_State *L)
{
MAP_LOCK_REQUIRED;
LuaVoxelManip *o = checkobject(L, 1);
LuaVoxelManip *o = checkObject<LuaVoxelManip>(L, 1);
bool update_light = !lua_isboolean(L, 2) || readParam<bool>(L, 2);
GET_ENV_PTR;
@ -141,7 +141,7 @@ int LuaVoxelManip::l_get_node_at(lua_State *L)
const NodeDefManager *ndef = getServer(L)->getNodeDefManager();
LuaVoxelManip *o = checkobject(L, 1);
LuaVoxelManip *o = checkObject<LuaVoxelManip>(L, 1);
v3s16 pos = check_v3s16(L, 2);
pushnode(L, o->vm->getNodeNoExNoEmerge(pos), ndef);
@ -154,7 +154,7 @@ int LuaVoxelManip::l_set_node_at(lua_State *L)
const NodeDefManager *ndef = getServer(L)->getNodeDefManager();
LuaVoxelManip *o = checkobject(L, 1);
LuaVoxelManip *o = checkObject<LuaVoxelManip>(L, 1);
v3s16 pos = check_v3s16(L, 2);
MapNode n = readnode(L, 3, ndef);
@ -167,7 +167,7 @@ int LuaVoxelManip::l_update_liquids(lua_State *L)
{
GET_ENV_PTR;
LuaVoxelManip *o = checkobject(L, 1);
LuaVoxelManip *o = checkObject<LuaVoxelManip>(L, 1);
ServerMap *map = &(env->getServerMap());
const NodeDefManager *ndef = getServer(L)->getNodeDefManager();
@ -187,7 +187,7 @@ int LuaVoxelManip::l_calc_lighting(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
LuaVoxelManip *o = checkobject(L, 1);
LuaVoxelManip *o = checkObject<LuaVoxelManip>(L, 1);
if (!o->is_mapgen_vm) {
warningstream << "VoxelManip:calc_lighting called for a non-mapgen "
"VoxelManip object" << std::endl;
@ -223,7 +223,7 @@ int LuaVoxelManip::l_set_lighting(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
LuaVoxelManip *o = checkobject(L, 1);
LuaVoxelManip *o = checkObject<LuaVoxelManip>(L, 1);
if (!o->is_mapgen_vm) {
warningstream << "VoxelManip:set_lighting called for a non-mapgen "
"VoxelManip object" << std::endl;
@ -259,7 +259,7 @@ int LuaVoxelManip::l_get_light_data(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
LuaVoxelManip *o = checkobject(L, 1);
LuaVoxelManip *o = checkObject<LuaVoxelManip>(L, 1);
bool use_buffer = lua_istable(L, 2);
MMVManip *vm = o->vm;
@ -284,7 +284,7 @@ int LuaVoxelManip::l_set_light_data(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
LuaVoxelManip *o = checkobject(L, 1);
LuaVoxelManip *o = checkObject<LuaVoxelManip>(L, 1);
MMVManip *vm = o->vm;
if (!lua_istable(L, 2))
@ -308,7 +308,7 @@ int LuaVoxelManip::l_get_param2_data(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
LuaVoxelManip *o = checkobject(L, 1);
LuaVoxelManip *o = checkObject<LuaVoxelManip>(L, 1);
bool use_buffer = lua_istable(L, 2);
MMVManip *vm = o->vm;
@ -333,7 +333,7 @@ int LuaVoxelManip::l_set_param2_data(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
LuaVoxelManip *o = checkobject(L, 1);
LuaVoxelManip *o = checkObject<LuaVoxelManip>(L, 1);
MMVManip *vm = o->vm;
if (!lua_istable(L, 2))
@ -362,7 +362,7 @@ int LuaVoxelManip::l_was_modified(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
LuaVoxelManip *o = checkobject(L, 1);
LuaVoxelManip *o = checkObject<LuaVoxelManip>(L, 1);
MMVManip *vm = o->vm;
lua_pushboolean(L, vm->m_is_dirty);
@ -374,7 +374,7 @@ int LuaVoxelManip::l_get_emerged_area(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
LuaVoxelManip *o = checkobject(L, 1);
LuaVoxelManip *o = checkObject<LuaVoxelManip>(L, 1);
push_v3s16(L, o->vm->m_area.MinEdge);
push_v3s16(L, o->vm->m_area.MaxEdge);
@ -425,22 +425,9 @@ int LuaVoxelManip::create_object(lua_State *L)
return 1;
}
LuaVoxelManip *LuaVoxelManip::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 *(LuaVoxelManip **)ud; // unbox pointer
}
void *LuaVoxelManip::packIn(lua_State *L, int idx)
{
LuaVoxelManip *o = checkobject(L, idx);
LuaVoxelManip *o = checkObject<LuaVoxelManip>(L, idx);
if (o->is_mapgen_vm)
throw LuaError("nope");
@ -468,27 +455,11 @@ void LuaVoxelManip::packOut(lua_State *L, void *ptr)
void LuaVoxelManip::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); // hide metatable from Lua getmetatable()
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); // drop metatable
luaL_register(L, nullptr, methods); // fill methodtable
lua_pop(L, 1); // drop methodtable
static const luaL_Reg metamethods[] = {
{"__gc", gc_object},
{0, 0}
};
registerClass(L, className, methods, metamethods);
// Can be created from Lua (VoxelManip())
lua_register(L, className, create_object);