diff options
Diffstat (limited to 'src/script/lua_api')
-rw-r--r-- | src/script/lua_api/l_env.cpp | 9 | ||||
-rw-r--r-- | src/script/lua_api/l_internal.h | 10 | ||||
-rw-r--r-- | src/script/lua_api/l_inventory.cpp | 3 | ||||
-rw-r--r-- | src/script/lua_api/l_mapgen.cpp | 44 | ||||
-rw-r--r-- | src/script/lua_api/l_nodemeta.cpp | 18 | ||||
-rw-r--r-- | src/script/lua_api/l_nodetimer.cpp | 6 | ||||
-rw-r--r-- | src/script/lua_api/l_noise.cpp | 5 | ||||
-rw-r--r-- | src/script/lua_api/l_object.cpp | 34 | ||||
-rw-r--r-- | src/script/lua_api/l_particles.cpp | 6 | ||||
-rw-r--r-- | src/script/lua_api/l_rollback.cpp | 4 | ||||
-rw-r--r-- | src/script/lua_api/l_server.cpp | 1 | ||||
-rw-r--r-- | src/script/lua_api/l_util.cpp | 6 | ||||
-rw-r--r-- | src/script/lua_api/l_vmanip.cpp | 32 |
13 files changed, 141 insertions, 37 deletions
diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp index 04b47e6d0..2645c8007 100644 --- a/src/script/lua_api/l_env.cpp +++ b/src/script/lua_api/l_env.cpp @@ -36,10 +36,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "emerge.h" #include "pathfinder.h" -#define GET_ENV_PTR ServerEnvironment* env = \ - dynamic_cast<ServerEnvironment*>(getEnv(L)); \ - if (env == NULL) return 0 - /////////////////////////////////////////////////////////////////////////////// @@ -658,7 +654,7 @@ int ModApiEnvMod::l_find_nodes_in_area_under_air(lua_State *L) // returns world-specific PerlinNoise int ModApiEnvMod::l_get_perlin(lua_State *L) { - GET_ENV_PTR; + GET_ENV_PTR_NO_MAP_LOCK; NoiseParams params; @@ -684,7 +680,7 @@ int ModApiEnvMod::l_get_perlin(lua_State *L) // returns world-specific PerlinNoiseMap int ModApiEnvMod::l_get_perlin_map(lua_State *L) { - GET_ENV_PTR; + GET_ENV_PTR_NO_MAP_LOCK; NoiseParams np; if (!read_noiseparams(L, 1, &np)) @@ -945,6 +941,7 @@ int ModApiEnvMod::l_forceload_free_block(lua_State *L) // get_us_time() int ModApiEnvMod::l_get_us_time(lua_State *L) { + NO_MAP_LOCK_REQUIRED; lua_pushnumber(L, porting::getTimeUs()); return 1; } diff --git a/src/script/lua_api/l_internal.h b/src/script/lua_api/l_internal.h index 1e40c5c4a..456c8fcce 100644 --- a/src/script/lua_api/l_internal.h +++ b/src/script/lua_api/l_internal.h @@ -33,6 +33,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #define API_FCT(name) registerFunction(L, #name, l_##name,top) #define ASYNC_API_FCT(name) engine.registerFunction(#name, l_##name) +#define MAP_LOCK_REQUIRED #define NO_MAP_LOCK_REQUIRED /* @@ -45,4 +46,13 @@ with this program; if not, write to the Free Software Foundation, Inc., #endif */ +#define GET_ENV_PTR_NO_MAP_LOCK \ + ServerEnvironment *env = (ServerEnvironment *)getEnv(L); \ + if (env == NULL) \ + return 0 + +#define GET_ENV_PTR \ + MAP_LOCK_REQUIRED; \ + GET_ENV_PTR_NO_MAP_LOCK + #endif /* L_INTERNAL_H_ */ diff --git a/src/script/lua_api/l_inventory.cpp b/src/script/lua_api/l_inventory.cpp index f48f6083b..de9f9374a 100644 --- a/src/script/lua_api/l_inventory.cpp +++ b/src/script/lua_api/l_inventory.cpp @@ -491,6 +491,7 @@ int ModApiInventory::l_get_inventory(lua_State *L) std::string type = checkstringfield(L, 1, "type"); if(type == "node"){ + MAP_LOCK_REQUIRED; lua_getfield(L, 1, "pos"); v3s16 pos = check_v3s16(L, -1); loc.setNodeMeta(pos); @@ -514,7 +515,7 @@ int ModApiInventory::l_get_inventory(lua_State *L) InvRef::create(L, loc); else lua_pushnil(L); - return 1; + return 1; // END NO_MAP_LOCK_REQUIRED; } } diff --git a/src/script/lua_api/l_mapgen.cpp b/src/script/lua_api/l_mapgen.cpp index cfa216a3d..825292419 100644 --- a/src/script/lua_api/l_mapgen.cpp +++ b/src/script/lua_api/l_mapgen.cpp @@ -454,6 +454,8 @@ size_t get_biome_list(lua_State *L, int index, // returns the biome id used in biomemap int ModApiMapgen::l_get_biome_id(lua_State *L) { + NO_MAP_LOCK_REQUIRED; + const char *biome_str = lua_tostring(L, 1); if (!biome_str) return 0; @@ -463,7 +465,7 @@ int ModApiMapgen::l_get_biome_id(lua_State *L) if (!bmgr) return 0; - Biome *biome = (Biome *) bmgr->getByName(biome_str); + Biome *biome = (Biome *)bmgr->getByName(biome_str); if (!biome || biome->index == OBJDEF_INVALID_INDEX) return 0; @@ -478,6 +480,8 @@ int ModApiMapgen::l_get_biome_id(lua_State *L) // returns the requested object used during map generation int ModApiMapgen::l_get_mapgen_object(lua_State *L) { + NO_MAP_LOCK_REQUIRED; + const char *mgobjstr = lua_tostring(L, 1); int mgobjint; @@ -588,6 +592,8 @@ int ModApiMapgen::l_get_mapgen_object(lua_State *L) int ModApiMapgen::l_get_mapgen_params(lua_State *L) { + NO_MAP_LOCK_REQUIRED; + MapgenParams *params = &getServer(L)->getEmergeManager()->params; lua_newtable(L); @@ -616,6 +622,8 @@ int ModApiMapgen::l_get_mapgen_params(lua_State *L) // set mapgen parameters int ModApiMapgen::l_set_mapgen_params(lua_State *L) { + NO_MAP_LOCK_REQUIRED; + if (!lua_istable(L, 1)) return 0; @@ -664,6 +672,8 @@ int ModApiMapgen::l_set_mapgen_params(lua_State *L) // set global config values for noise parameters int ModApiMapgen::l_set_noiseparams(lua_State *L) { + NO_MAP_LOCK_REQUIRED; + const char *name = luaL_checkstring(L, 1); NoiseParams np; @@ -681,6 +691,8 @@ int ModApiMapgen::l_set_noiseparams(lua_State *L) // get_noiseparams(name) int ModApiMapgen::l_get_noiseparams(lua_State *L) { + NO_MAP_LOCK_REQUIRED; + std::string name = luaL_checkstring(L, 1); NoiseParams np; @@ -695,6 +707,8 @@ int ModApiMapgen::l_get_noiseparams(lua_State *L) // set_gen_notify(flags, {deco_id_table}) int ModApiMapgen::l_set_gen_notify(lua_State *L) { + NO_MAP_LOCK_REQUIRED; + u32 flags = 0, flagmask = 0; EmergeManager *emerge = getServer(L)->getEmergeManager(); @@ -719,6 +733,8 @@ int ModApiMapgen::l_set_gen_notify(lua_State *L) // get_gen_notify() int ModApiMapgen::l_get_gen_notify(lua_State *L) { + NO_MAP_LOCK_REQUIRED; + EmergeManager *emerge = getServer(L)->getEmergeManager(); push_flags_string(L, flagdesc_gennotify, emerge->gen_notify_on, emerge->gen_notify_on); @@ -738,6 +754,8 @@ int ModApiMapgen::l_get_gen_notify(lua_State *L) // register_biome({lots of stuff}) int ModApiMapgen::l_register_biome(lua_State *L) { + NO_MAP_LOCK_REQUIRED; + int index = 1; luaL_checktype(L, index, LUA_TTABLE); @@ -762,6 +780,8 @@ int ModApiMapgen::l_register_biome(lua_State *L) // register_decoration({lots of stuff}) int ModApiMapgen::l_register_decoration(lua_State *L) { + NO_MAP_LOCK_REQUIRED; + int index = 1; luaL_checktype(L, index, LUA_TTABLE); @@ -902,6 +922,8 @@ bool read_deco_schematic(lua_State *L, SchematicManager *schemmgr, DecoSchematic // register_ore({lots of stuff}) int ModApiMapgen::l_register_ore(lua_State *L) { + NO_MAP_LOCK_REQUIRED; + int index = 1; luaL_checktype(L, index, LUA_TTABLE); @@ -1030,6 +1052,8 @@ int ModApiMapgen::l_register_ore(lua_State *L) // register_schematic({schematic}, replacements={}) int ModApiMapgen::l_register_schematic(lua_State *L) { + NO_MAP_LOCK_REQUIRED; + SchematicManager *schemmgr = getServer(L)->getEmergeManager()->schemmgr; StringMap replace_names; @@ -1055,6 +1079,8 @@ int ModApiMapgen::l_register_schematic(lua_State *L) // clear_registered_biomes() int ModApiMapgen::l_clear_registered_biomes(lua_State *L) { + NO_MAP_LOCK_REQUIRED; + BiomeManager *bmgr = getServer(L)->getEmergeManager()->biomemgr; bmgr->clear(); return 0; @@ -1064,6 +1090,8 @@ int ModApiMapgen::l_clear_registered_biomes(lua_State *L) // clear_registered_decorations() int ModApiMapgen::l_clear_registered_decorations(lua_State *L) { + NO_MAP_LOCK_REQUIRED; + DecorationManager *dmgr = getServer(L)->getEmergeManager()->decomgr; dmgr->clear(); return 0; @@ -1073,6 +1101,8 @@ int ModApiMapgen::l_clear_registered_decorations(lua_State *L) // clear_registered_ores() int ModApiMapgen::l_clear_registered_ores(lua_State *L) { + NO_MAP_LOCK_REQUIRED; + OreManager *omgr = getServer(L)->getEmergeManager()->oremgr; omgr->clear(); return 0; @@ -1082,6 +1112,8 @@ int ModApiMapgen::l_clear_registered_ores(lua_State *L) // clear_registered_schematics() int ModApiMapgen::l_clear_registered_schematics(lua_State *L) { + NO_MAP_LOCK_REQUIRED; + SchematicManager *smgr = getServer(L)->getEmergeManager()->schemmgr; smgr->clear(); return 0; @@ -1091,6 +1123,8 @@ int ModApiMapgen::l_clear_registered_schematics(lua_State *L) // generate_ores(vm, p1, p2, [ore_id]) int ModApiMapgen::l_generate_ores(lua_State *L) { + NO_MAP_LOCK_REQUIRED; + EmergeManager *emerge = getServer(L)->getEmergeManager(); Mapgen mg; @@ -1115,6 +1149,8 @@ int ModApiMapgen::l_generate_ores(lua_State *L) // generate_decorations(vm, p1, p2, [deco_id]) int ModApiMapgen::l_generate_decorations(lua_State *L) { + NO_MAP_LOCK_REQUIRED; + EmergeManager *emerge = getServer(L)->getEmergeManager(); Mapgen mg; @@ -1139,6 +1175,8 @@ int ModApiMapgen::l_generate_decorations(lua_State *L) // create_schematic(p1, p2, probability_list, filename, y_slice_prob_list) int ModApiMapgen::l_create_schematic(lua_State *L) { + MAP_LOCK_REQUIRED; + INodeDefManager *ndef = getServer(L)->getNodeDefManager(); const char *filename = luaL_checkstring(L, 4); @@ -1202,6 +1240,8 @@ int ModApiMapgen::l_create_schematic(lua_State *L) // place_schematic(p, schematic, rotation, replacement) int ModApiMapgen::l_place_schematic(lua_State *L) { + MAP_LOCK_REQUIRED; + Map *map = &(getEnv(L)->getMap()); SchematicManager *schemmgr = getServer(L)->getEmergeManager()->schemmgr; @@ -1240,6 +1280,8 @@ int ModApiMapgen::l_place_schematic(lua_State *L) // serialize_schematic(schematic, format, options={...}) int ModApiMapgen::l_serialize_schematic(lua_State *L) { + NO_MAP_LOCK_REQUIRED; + SchematicManager *schemmgr = getServer(L)->getEmergeManager()->schemmgr; //// Read options diff --git a/src/script/lua_api/l_nodemeta.cpp b/src/script/lua_api/l_nodemeta.cpp index d8de9a412..c8bc7d558 100644 --- a/src/script/lua_api/l_nodemeta.cpp +++ b/src/script/lua_api/l_nodemeta.cpp @@ -82,6 +82,8 @@ int NodeMetaRef::gc_object(lua_State *L) { // get_string(self, name) int NodeMetaRef::l_get_string(lua_State *L) { + MAP_LOCK_REQUIRED; + NodeMetaRef *ref = checkobject(L, 1); std::string name = luaL_checkstring(L, 2); @@ -98,6 +100,8 @@ int NodeMetaRef::l_get_string(lua_State *L) // set_string(self, name, var) int NodeMetaRef::l_set_string(lua_State *L) { + MAP_LOCK_REQUIRED; + NodeMetaRef *ref = checkobject(L, 1); std::string name = luaL_checkstring(L, 2); size_t len = 0; @@ -115,6 +119,8 @@ int NodeMetaRef::l_set_string(lua_State *L) // get_int(self, name) int NodeMetaRef::l_get_int(lua_State *L) { + MAP_LOCK_REQUIRED; + NodeMetaRef *ref = checkobject(L, 1); std::string name = lua_tostring(L, 2); @@ -131,6 +137,8 @@ int NodeMetaRef::l_get_int(lua_State *L) // set_int(self, name, var) int NodeMetaRef::l_set_int(lua_State *L) { + MAP_LOCK_REQUIRED; + NodeMetaRef *ref = checkobject(L, 1); std::string name = lua_tostring(L, 2); int a = lua_tointeger(L, 3); @@ -147,6 +155,8 @@ int NodeMetaRef::l_set_int(lua_State *L) // get_float(self, name) int NodeMetaRef::l_get_float(lua_State *L) { + MAP_LOCK_REQUIRED; + NodeMetaRef *ref = checkobject(L, 1); std::string name = lua_tostring(L, 2); @@ -163,6 +173,8 @@ int NodeMetaRef::l_get_float(lua_State *L) // set_float(self, name, var) int NodeMetaRef::l_set_float(lua_State *L) { + MAP_LOCK_REQUIRED; + NodeMetaRef *ref = checkobject(L, 1); std::string name = lua_tostring(L, 2); float a = lua_tonumber(L, 3); @@ -179,6 +191,8 @@ int NodeMetaRef::l_set_float(lua_State *L) // get_inventory(self) int NodeMetaRef::l_get_inventory(lua_State *L) { + MAP_LOCK_REQUIRED; + NodeMetaRef *ref = checkobject(L, 1); getmeta(ref, true); // try to ensure the metadata exists InvRef::createNodeMeta(L, ref->m_p); @@ -188,6 +202,8 @@ int NodeMetaRef::l_get_inventory(lua_State *L) // to_table(self) int NodeMetaRef::l_to_table(lua_State *L) { + MAP_LOCK_REQUIRED; + NodeMetaRef *ref = checkobject(L, 1); NodeMetadata *meta = getmeta(ref, true); @@ -230,6 +246,8 @@ int NodeMetaRef::l_to_table(lua_State *L) // from_table(self, table) int NodeMetaRef::l_from_table(lua_State *L) { + MAP_LOCK_REQUIRED; + NodeMetaRef *ref = checkobject(L, 1); int base = 2; diff --git a/src/script/lua_api/l_nodetimer.cpp b/src/script/lua_api/l_nodetimer.cpp index c81a7ebc9..601113516 100644 --- a/src/script/lua_api/l_nodetimer.cpp +++ b/src/script/lua_api/l_nodetimer.cpp @@ -39,6 +39,7 @@ NodeTimerRef* NodeTimerRef::checkobject(lua_State *L, int narg) int NodeTimerRef::l_set(lua_State *L) { + MAP_LOCK_REQUIRED; NodeTimerRef *o = checkobject(L, 1); ServerEnvironment *env = o->m_env; if(env == NULL) return 0; @@ -50,6 +51,7 @@ int NodeTimerRef::l_set(lua_State *L) int NodeTimerRef::l_start(lua_State *L) { + MAP_LOCK_REQUIRED; NodeTimerRef *o = checkobject(L, 1); ServerEnvironment *env = o->m_env; if(env == NULL) return 0; @@ -60,6 +62,7 @@ int NodeTimerRef::l_start(lua_State *L) int NodeTimerRef::l_stop(lua_State *L) { + MAP_LOCK_REQUIRED; NodeTimerRef *o = checkobject(L, 1); ServerEnvironment *env = o->m_env; if(env == NULL) return 0; @@ -69,6 +72,7 @@ int NodeTimerRef::l_stop(lua_State *L) int NodeTimerRef::l_is_started(lua_State *L) { + MAP_LOCK_REQUIRED; NodeTimerRef *o = checkobject(L, 1); ServerEnvironment *env = o->m_env; if(env == NULL) return 0; @@ -80,6 +84,7 @@ int NodeTimerRef::l_is_started(lua_State *L) int NodeTimerRef::l_get_timeout(lua_State *L) { + MAP_LOCK_REQUIRED; NodeTimerRef *o = checkobject(L, 1); ServerEnvironment *env = o->m_env; if(env == NULL) return 0; @@ -91,6 +96,7 @@ int NodeTimerRef::l_get_timeout(lua_State *L) int NodeTimerRef::l_get_elapsed(lua_State *L) { + MAP_LOCK_REQUIRED; NodeTimerRef *o = checkobject(L, 1); ServerEnvironment *env = o->m_env; if(env == NULL) return 0; diff --git a/src/script/lua_api/l_noise.cpp b/src/script/lua_api/l_noise.cpp index c8dc2d2dc..43dd32023 100644 --- a/src/script/lua_api/l_noise.cpp +++ b/src/script/lua_api/l_noise.cpp @@ -410,6 +410,7 @@ const luaL_reg LuaPerlinNoiseMap::methods[] = { int LuaPseudoRandom::l_next(lua_State *L) { NO_MAP_LOCK_REQUIRED; + LuaPseudoRandom *o = checkobject(L, 1); int min = 0; int max = 32767; @@ -437,6 +438,8 @@ int LuaPseudoRandom::l_next(lua_State *L) int LuaPseudoRandom::create_object(lua_State *L) { + NO_MAP_LOCK_REQUIRED; + int seed = luaL_checknumber(L, 1); LuaPseudoRandom *o = new LuaPseudoRandom(seed); *(void **)(lua_newuserdata(L, sizeof(void *))) = o; @@ -532,6 +535,8 @@ int LuaPcgRandom::l_rand_normal_dist(lua_State *L) int LuaPcgRandom::create_object(lua_State *L) { + NO_MAP_LOCK_REQUIRED; + lua_Integer seed = luaL_checknumber(L, 1); LuaPcgRandom *o = lua_isnumber(L, 2) ? new LuaPcgRandom(seed, lua_tointeger(L, 2)) : diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp index 2bd5299dc..52190d60e 100644 --- a/src/script/lua_api/l_object.cpp +++ b/src/script/lua_api/l_object.cpp @@ -31,10 +31,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "hud.h" #include "scripting_game.h" -#define GET_ENV_PTR ServerEnvironment* env = \ - dynamic_cast<ServerEnvironment*>(getEnv(L)); \ - if (env == NULL) return 0 - struct EnumString es_HudElementType[] = { {HUD_ELEM_IMAGE, "image"}, @@ -132,7 +128,6 @@ int ObjectRef::gc_object(lua_State *L) { // remove(self) int ObjectRef::l_remove(lua_State *L) { - NO_MAP_LOCK_REQUIRED; GET_ENV_PTR; ObjectRef *ref = checkobject(L, 1); @@ -409,6 +404,7 @@ int ObjectRef::l_get_armor_groups(lua_State *L) // physics_override_gravity, sneak, sneak_glitch) int ObjectRef::l_set_physics_override(lua_State *L) { + NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); PlayerSAO *co = (PlayerSAO *) getobject(ref); if (co == NULL) return 0; @@ -441,6 +437,7 @@ int ObjectRef::l_set_physics_override(lua_State *L) // get_physics_override(self) int ObjectRef::l_get_physics_override(lua_State *L) { + NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); PlayerSAO *co = (PlayerSAO *)getobject(ref); if (co == NULL) @@ -509,7 +506,7 @@ int ObjectRef::l_get_animation(lua_State *L) // set_local_animation(self, {stand/idle}, {walk}, {dig}, {walk+dig}, frame_speed) int ObjectRef::l_set_local_animation(lua_State *L) { - //NO_MAP_LOCK_REQUIRED; + NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); Player *player = getplayer(ref); if (player == NULL) @@ -534,7 +531,7 @@ int ObjectRef::l_set_local_animation(lua_State *L) // get_local_animation(self) int ObjectRef::l_get_local_animation(lua_State *L) { - //NO_MAP_LOCK_REQUIRED + NO_MAP_LOCK_REQUIRED ObjectRef *ref = checkobject(L, 1); Player *player = getplayer(ref); if (player == NULL) @@ -555,7 +552,7 @@ int ObjectRef::l_get_local_animation(lua_State *L) // set_eye_offset(self, v3f first pv, v3f third pv) int ObjectRef::l_set_eye_offset(lua_State *L) { - //NO_MAP_LOCK_REQUIRED; + NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); Player *player = getplayer(ref); if (player == NULL) @@ -585,7 +582,7 @@ int ObjectRef::l_set_eye_offset(lua_State *L) // get_eye_offset(self) int ObjectRef::l_get_eye_offset(lua_State *L) { - //NO_MAP_LOCK_REQUIRED; + NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); Player *player = getplayer(ref); if (player == NULL) @@ -642,7 +639,6 @@ int ObjectRef::l_get_bone_position(lua_State *L) // set_attach(self, parent, bone, position, rotation) int ObjectRef::l_set_attach(lua_State *L) { - NO_MAP_LOCK_REQUIRED; GET_ENV_PTR; ObjectRef *ref = checkobject(L, 1); @@ -681,7 +677,6 @@ int ObjectRef::l_set_attach(lua_State *L) // get_attach(self) int ObjectRef::l_get_attach(lua_State *L) { - NO_MAP_LOCK_REQUIRED; GET_ENV_PTR; ObjectRef *ref = checkobject(L, 1); @@ -709,7 +704,6 @@ int ObjectRef::l_get_attach(lua_State *L) // set_detach(self) int ObjectRef::l_set_detach(lua_State *L) { - NO_MAP_LOCK_REQUIRED; GET_ENV_PTR; ObjectRef *ref = checkobject(L, 1); @@ -1137,6 +1131,7 @@ int ObjectRef::l_get_player_control_bits(lua_State *L) // hud_add(self, form) int ObjectRef::l_hud_add(lua_State *L) { + NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); Player *player = getplayer(ref); if (player == NULL) @@ -1199,6 +1194,7 @@ int ObjectRef::l_hud_add(lua_State *L) // hud_remove(self, id) int ObjectRef::l_hud_remove(lua_State *L) { + NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); Player *player = getplayer(ref); if (player == NULL) @@ -1218,6 +1214,7 @@ int ObjectRef::l_hud_remove(lua_State *L) // hud_change(self, id, stat, data) int ObjectRef::l_hud_change(lua_State *L) { + NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); Player *player = getplayer(ref); if (player == NULL) @@ -1294,6 +1291,7 @@ int ObjectRef::l_hud_change(lua_State *L) // hud_get(self, id) int ObjectRef::l_hud_get(lua_State *L) { + NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); Player *player = getplayer(ref); if (player == NULL) @@ -1344,6 +1342,7 @@ int ObjectRef::l_hud_get(lua_State *L) // hud_set_flags(self, flags) int ObjectRef::l_hud_set_flags(lua_State *L) { + NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); Player *player = getplayer(ref); if (player == NULL) @@ -1369,6 +1368,7 @@ int ObjectRef::l_hud_set_flags(lua_State *L) int ObjectRef::l_hud_get_flags(lua_State *L) { + NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); Player *player = getplayer(ref); if (player == NULL) @@ -1394,6 +1394,7 @@ int ObjectRef::l_hud_get_flags(lua_State *L) // hud_set_hotbar_itemcount(self, hotbar_itemcount) int ObjectRef::l_hud_set_hotbar_itemcount(lua_State *L) { + NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); Player *player = getplayer(ref); if (player == NULL) @@ -1411,6 +1412,7 @@ int ObjectRef::l_hud_set_hotbar_itemcount(lua_State *L) // hud_get_hotbar_itemcount(self) int ObjectRef::l_hud_get_hotbar_itemcount(lua_State *L) { + NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); Player *player = getplayer(ref); if (player == NULL) @@ -1425,6 +1427,7 @@ int ObjectRef::l_hud_get_hotbar_itemcount(lua_State *L) // hud_set_hotbar_image(self, name) int ObjectRef::l_hud_set_hotbar_image(lua_State *L) { + NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); Player *player = getplayer(ref); if (player == NULL) @@ -1439,6 +1442,7 @@ int ObjectRef::l_hud_set_hotbar_image(lua_State *L) // hud_get_hotbar_image(self) int ObjectRef::l_hud_get_hotbar_image(lua_State *L) { + NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); Player *player = getplayer(ref); if (player == NULL) @@ -1452,6 +1456,7 @@ int ObjectRef::l_hud_get_hotbar_image(lua_State *L) // hud_set_hotbar_selected_image(self, name) int ObjectRef::l_hud_set_hotbar_selected_image(lua_State *L) { + NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); Player *player = getplayer(ref); if (player == NULL) @@ -1466,6 +1471,7 @@ int ObjectRef::l_hud_set_hotbar_selected_image(lua_State *L) // hud_get_hotbar_selected_image(self) int ObjectRef::l_hud_get_hotbar_selected_image(lua_State *L) { + NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); Player *player = getplayer(ref); if (player == NULL) @@ -1479,6 +1485,7 @@ int ObjectRef::l_hud_get_hotbar_selected_image(lua_State *L) // set_sky(self, bgcolor, type, list) int ObjectRef::l_set_sky(lua_State *L) { + NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); Player *player = getplayer(ref); if (player == NULL) @@ -1517,6 +1524,7 @@ int ObjectRef::l_set_sky(lua_State *L) // get_sky(self) int ObjectRef::l_get_sky(lua_State *L) { + NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); Player *player = getplayer(ref); if (player == NULL) @@ -1544,6 +1552,7 @@ int ObjectRef::l_get_sky(lua_State *L) // override_day_night_ratio(self, brightness=0...1) int ObjectRef::l_override_day_night_ratio(lua_State *L) { + NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); Player *player = getplayer(ref); if (player == NULL) @@ -1566,6 +1575,7 @@ int ObjectRef::l_override_day_night_ratio(lua_State *L) // get_day_night_ratio(self) int ObjectRef::l_get_day_night_ratio(lua_State *L) { + NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); Player *player = getplayer(ref); if (player == NULL) diff --git a/src/script/lua_api/l_particles.cpp b/src/script/lua_api/l_particles.cpp index 2532b2b08..f6c1725de 100644 --- a/src/script/lua_api/l_particles.cpp +++ b/src/script/lua_api/l_particles.cpp @@ -32,6 +32,8 @@ with this program; if not, write to the Free Software Foundation, Inc., // texture = e.g."default_wood.png" int ModApiParticles::l_add_particle(lua_State *L) { + MAP_LOCK_REQUIRED; + // Get parameters v3f pos, vel, acc; pos = vel = acc = v3f(0, 0, 0); @@ -119,6 +121,8 @@ int ModApiParticles::l_add_particle(lua_State *L) // texture = e.g."default_wood.png" int ModApiParticles::l_add_particlespawner(lua_State *L) { + MAP_LOCK_REQUIRED; + // Get parameters u16 amount = 1; v3f minpos, maxpos, minvel, maxvel, minacc, maxacc; @@ -208,6 +212,8 @@ int ModApiParticles::l_add_particlespawner(lua_State *L) // player (string) is optional int ModApiParticles::l_delete_particlespawner(lua_State *L) { + MAP_LOCK_REQUIRED; + // Get parameters u32 id = luaL_checknumber(L, 1); std::string playername = ""; diff --git a/src/script/lua_api/l_rollback.cpp b/src/script/lua_api/l_rollback.cpp index 5744e6813..482b0cbf5 100644 --- a/src/script/lua_api/l_rollback.cpp +++ b/src/script/lua_api/l_rollback.cpp @@ -38,6 +38,8 @@ void push_RollbackNode(lua_State *L, RollbackNode &node) // rollback_get_node_actions(pos, range, seconds, limit) -> {{actor, pos, time, oldnode, newnode}, ...} int ModApiRollback::l_rollback_get_node_actions(lua_State *L) { + NO_MAP_LOCK_REQUIRED; + v3s16 pos = read_v3s16(L, 1); int range = luaL_checknumber(L, 2); time_t seconds = (time_t) luaL_checknumber(L, 3); @@ -79,6 +81,8 @@ int ModApiRollback::l_rollback_get_node_actions(lua_State *L) // rollback_revert_actions_by(actor, seconds) -> bool, log messages int ModApiRollback::l_rollback_revert_actions_by(lua_State *L) { + MAP_LOCK_REQUIRED; + std::string actor = luaL_checkstring(L, 1); int seconds = luaL_checknumber(L, 2); Server *server = getServer(L); diff --git a/src/script/lua_api/l_server.cpp b/src/script/lua_api/l_server.cpp index 6a8183088..85314a3bc 100644 --- a/src/script/lua_api/l_server.cpp +++ b/src/script/lua_api/l_server.cpp @@ -30,6 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc., // request_shutdown() int ModApiServer::l_request_shutdown(lua_State *L) { + NO_MAP_LOCK_REQUIRED; const char *msg = lua_tolstring(L, 1, NULL); bool reconnect = lua_toboolean(L, 2); getServer(L)->requestShutdown(msg ? msg : "", reconnect); diff --git a/src/script/lua_api/l_util.cpp b/src/script/lua_api/l_util.cpp index 106edc01e..d5adc7ab0 100644 --- a/src/script/lua_api/l_util.cpp +++ b/src/script/lua_api/l_util.cpp @@ -260,6 +260,8 @@ int ModApiUtil::l_is_yes(lua_State *L) int ModApiUtil::l_get_builtin_path(lua_State *L) { + NO_MAP_LOCK_REQUIRED; + std::string path = porting::path_share + DIR_DELIM + "builtin"; lua_pushstring(L, path.c_str()); return 1; @@ -268,6 +270,8 @@ int ModApiUtil::l_get_builtin_path(lua_State *L) // compress(data, method, level) int ModApiUtil::l_compress(lua_State *L) { + NO_MAP_LOCK_REQUIRED; + size_t size; const char *data = luaL_checklstring(L, 1, &size); @@ -287,6 +291,8 @@ int ModApiUtil::l_compress(lua_State *L) // decompress(data, method) int ModApiUtil::l_decompress(lua_State *L) { + NO_MAP_LOCK_REQUIRED; + size_t size; const char *data = luaL_checklstring(L, 1, &size); diff --git a/src/script/lua_api/l_vmanip.cpp b/src/script/lua_api/l_vmanip.cpp index ac6c10303..ec9be8fba 100644 --- a/src/script/lua_api/l_vmanip.cpp +++ b/src/script/lua_api/l_vmanip.cpp @@ -28,10 +28,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "server.h" #include "mapgen.h" -#define GET_ENV_PTR ServerEnvironment* env = \ - dynamic_cast<ServerEnvironment*>(getEnv(L)); \ - if (env == NULL) return 0 - // garbage collector int LuaVoxelManip::gc_object(lua_State *L) { @@ -43,6 +39,8 @@ int LuaVoxelManip::gc_object(lua_State *L) int LuaVoxelManip::l_read_from_map(lua_State *L) { + MAP_LOCK_REQUIRED; + LuaVoxelManip *o = checkobject(L, 1); MMVManip *vm = o->vm; @@ -108,6 +106,8 @@ int LuaVoxelManip::l_set_data(lua_State *L) int LuaVoxelManip::l_write_to_map(lua_State *L) { + MAP_LOCK_REQUIRED; + LuaVoxelManip *o = checkobject(L, 1); MMVManip *vm = o->vm; @@ -119,23 +119,25 @@ int LuaVoxelManip::l_write_to_map(lua_State *L) int LuaVoxelManip::l_get_node_at(lua_State *L) { NO_MAP_LOCK_REQUIRED; - GET_ENV_PTR; + + INodeDefManager *ndef = getServer(L)->getNodeDefManager(); LuaVoxelManip *o = checkobject(L, 1); v3s16 pos = check_v3s16(L, 2); - pushnode(L, o->vm->getNodeNoExNoEmerge(pos), env->getGameDef()->ndef()); + pushnode(L, o->vm->getNodeNoExNoEmerge(pos), ndef); return 1; } int LuaVoxelManip::l_set_node_at(lua_State *L) { NO_MAP_LOCK_REQUIRED; - GET_ENV_PTR; + + INodeDefManager *ndef = getServer(L)->getNodeDefManager(); LuaVoxelManip *o = checkobject(L, 1); v3s16 pos = check_v3s16(L, 2); - MapNode n = readnode(L, 3, env->getGameDef()->ndef()); + MapNode n = readnode(L, 3, ndef); o->vm->setNodeNoEmerge(pos, n); @@ -313,14 +315,12 @@ int LuaVoxelManip::l_set_param2_data(lua_State *L) int LuaVoxelManip::l_update_map(lua_State *L) { + GET_ENV_PTR; + LuaVoxelManip *o = checkobject(L, 1); if (o->is_mapgen_vm) return 0; - Environment *env = getEnv(L); - if (!env) - return 0; - Map *map = &(env->getMap()); // TODO: Optimize this by using Mapgen::calcLighting() instead @@ -359,6 +359,8 @@ int LuaVoxelManip::l_was_modified(lua_State *L) int LuaVoxelManip::l_get_emerged_area(lua_State *L) { + NO_MAP_LOCK_REQUIRED; + LuaVoxelManip *o = checkobject(L, 1); push_v3s16(L, o->vm->m_area.MinEdge); @@ -400,11 +402,7 @@ LuaVoxelManip::~LuaVoxelManip() // Creates an LuaVoxelManip and leaves it on top of stack int LuaVoxelManip::create_object(lua_State *L) { - NO_MAP_LOCK_REQUIRED; - - Environment *env = getEnv(L); - if (!env) - return 0; + GET_ENV_PTR; Map *map = &(env->getMap()); LuaVoxelManip *o = (lua_istable(L, 1) && lua_istable(L, 2)) ? |