diff options
Diffstat (limited to 'src/script')
25 files changed, 72 insertions, 114 deletions
diff --git a/src/script/lua_api/l_camera.h b/src/script/lua_api/l_camera.h index a7103c9b0..f3021bc49 100644 --- a/src/script/lua_api/l_camera.h +++ b/src/script/lua_api/l_camera.h @@ -48,7 +48,7 @@ private: public: LuaCamera(Camera *m); - ~LuaCamera() {} + ~LuaCamera() = default; static void create(lua_State *L, Camera *m); diff --git a/src/script/lua_api/l_client.cpp b/src/script/lua_api/l_client.cpp index 81dfdb1e9..6a87b20e9 100644 --- a/src/script/lua_api/l_client.cpp +++ b/src/script/lua_api/l_client.cpp @@ -34,7 +34,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "util/string.h" #include "nodedef.h" -extern MainGameCallback *g_gamecallback; int ModApiClient::l_get_current_modname(lua_State *L) { diff --git a/src/script/lua_api/l_craft.cpp b/src/script/lua_api/l_craft.cpp index 315391856..7bf1d314b 100644 --- a/src/script/lua_api/l_craft.cpp +++ b/src/script/lua_api/l_craft.cpp @@ -57,7 +57,7 @@ bool ModApiCraft::readCraftRecipeShaped(lua_State *L, int index, // key at index -2 and value at index -1 if(!lua_isstring(L, -1)) return false; - recipe.push_back(lua_tostring(L, -1)); + recipe.emplace_back(lua_tostring(L, -1)); // removes value, keeps key for next iteration lua_pop(L, 1); colcount++; @@ -90,7 +90,7 @@ bool ModApiCraft::readCraftRecipeShapeless(lua_State *L, int index, // key at index -2 and value at index -1 if(!lua_isstring(L, -1)) return false; - recipe.push_back(lua_tostring(L, -1)); + recipe.emplace_back(lua_tostring(L, -1)); // removes value, keeps key for next iteration lua_pop(L, 1); } @@ -122,8 +122,7 @@ bool ModApiCraft::readCraftReplacements(lua_State *L, int index, return false; std::string replace_to = lua_tostring(L, -1); lua_pop(L, 1); - replacements.pairs.push_back( - std::make_pair(replace_from, replace_to)); + replacements.pairs.emplace_back(replace_from, replace_to); // removes value, keeps key for next iteration lua_pop(L, 1); } @@ -148,7 +147,7 @@ int ModApiCraft::l_register_craft(lua_State *L) */ if(type == "shaped"){ std::string output = getstringfield_default(L, table, "output", ""); - if(output == "") + if (output.empty()) throw LuaError("Crafting definition is missing an output"); int width = 0; @@ -179,7 +178,7 @@ int ModApiCraft::l_register_craft(lua_State *L) */ else if(type == "shapeless"){ std::string output = getstringfield_default(L, table, "output", ""); - if(output == "") + if (output.empty()) throw LuaError("Crafting definition (shapeless)" " is missing an output"); @@ -222,12 +221,12 @@ int ModApiCraft::l_register_craft(lua_State *L) */ else if(type == "cooking"){ std::string output = getstringfield_default(L, table, "output", ""); - if(output == "") + if (output.empty()) throw LuaError("Crafting definition (cooking)" " is missing an output"); std::string recipe = getstringfield_default(L, table, "recipe", ""); - if(recipe == "") + if (recipe.empty()) throw LuaError("Crafting definition (cooking)" " is missing a recipe" " (output=\"" + output + "\")"); @@ -252,7 +251,7 @@ int ModApiCraft::l_register_craft(lua_State *L) */ else if(type == "fuel"){ std::string recipe = getstringfield_default(L, table, "recipe", ""); - if(recipe == "") + if (recipe.empty()) throw LuaError("Crafting definition (fuel)" " is missing a recipe"); @@ -294,12 +293,12 @@ int ModApiCraft::l_clear_craft(lua_State *L) std::string output = getstringfield_default(L, table, "output", ""); std::string type = getstringfield_default(L, table, "type", "shaped"); CraftOutput c_output(output, 0); - if (output != "") { + if (!output.empty()) { if (craftdef->clearCraftRecipesByOutput(c_output, getServer(L))) return 0; - else - throw LuaError("No craft recipe known for output" - " (output=\"" + output + "\")"); + + throw LuaError("No craft recipe known for output" + " (output=\"" + output + "\")"); } std::vector<std::string> recipe; int width = 0; @@ -330,7 +329,7 @@ int ModApiCraft::l_clear_craft(lua_State *L) else if (type == "cooking") { method = CRAFT_METHOD_COOKING; std::string rec = getstringfield_default(L, table, "recipe", ""); - if (rec == "") + if (rec.empty()) throw LuaError("Crafting definition (cooking)" " is missing a recipe"); recipe.push_back(rec); @@ -341,7 +340,7 @@ int ModApiCraft::l_clear_craft(lua_State *L) else if (type == "fuel") { method = CRAFT_METHOD_FUEL; std::string rec = getstringfield_default(L, table, "recipe", ""); - if (rec == "") + if (rec.empty()) throw LuaError("Crafting definition (fuel)" " is missing a recipe"); recipe.push_back(rec); diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp index 1b1f96389..94edf201e 100644 --- a/src/script/lua_api/l_env.cpp +++ b/src/script/lua_api/l_env.cpp @@ -743,9 +743,8 @@ int ModApiEnvMod::l_find_node_near(lua_State *L) for (int d = start_radius; d <= radius; d++) { std::vector<v3s16> list = FacePositionCache::getFacePositions(d); - for (std::vector<v3s16>::iterator i = list.begin(); - i != list.end(); ++i) { - v3s16 p = pos + (*i); + for (v3s16 i : list) { + v3s16 p = pos + i; content_t c = env->getMap().getNodeNoEx(p).getContent(); if (filter.count(c) != 0) { push_v3s16(L, p); @@ -809,10 +808,9 @@ int ModApiEnvMod::l_find_nodes_in_area(lua_State *L) } } lua_newtable(L); - for (std::set<content_t>::const_iterator it = filter.begin(); - it != filter.end(); ++it) { - lua_pushnumber(L, individual_count[*it]); - lua_setfield(L, -2, ndef->get(*it).name.c_str()); + for (content_t it : filter) { + lua_pushnumber(L, individual_count[it]); + lua_setfield(L, -2, ndef->get(it).name.c_str()); } return 2; } @@ -1004,12 +1002,11 @@ int ModApiEnvMod::l_fix_light(lua_State *L) for (blockpos.Z = blockpos1.Z; blockpos.Z <= blockpos2.Z; blockpos.Z++) { success = success & map.repairBlockLight(blockpos, &modified_blocks); } - if (modified_blocks.size() > 0) { + if (!modified_blocks.empty()) { MapEditEvent event; event.type = MEET_OTHER; - for (std::map<v3s16, MapBlock *>::iterator it = modified_blocks.begin(); - it != modified_blocks.end(); ++it) - event.modified_blocks.insert(it->first); + for (auto &modified_block : modified_blocks) + event.modified_blocks.insert(modified_block.first); map.dispatchEvent(&event); } @@ -1126,14 +1123,13 @@ int ModApiEnvMod::l_find_path(lua_State *L) std::vector<v3s16> path = get_path(env, pos1, pos2, searchdistance, max_jump, max_drop, algo); - if (path.size() > 0) - { + if (!path.empty()) { lua_newtable(L); int top = lua_gettop(L); unsigned int index = 1; - for (std::vector<v3s16>::iterator i = path.begin(); i != path.end(); ++i) { + for (v3s16 i : path) { lua_pushnumber(L,index); - push_v3s16(L, *i); + push_v3s16(L, i); lua_settable(L, top); index++; } @@ -1167,8 +1163,7 @@ int ModApiEnvMod::l_spawn_tree(lua_State *L) tree_def.leavesnode=ndef->getId(leaves); tree_def.leaves2_chance=0; getstringfield(L, 2, "leaves2", leaves); - if (leaves !="") - { + if (!leaves.empty()) { tree_def.leaves2node=ndef->getId(leaves); getintfield(L, 2, "leaves2_chance", tree_def.leaves2_chance); } @@ -1180,8 +1175,7 @@ int ModApiEnvMod::l_spawn_tree(lua_State *L) getboolfield(L, 2, "thin_branches", tree_def.thin_branches); tree_def.fruit_chance=0; getstringfield(L, 2, "fruit", fruit); - if (fruit != "") - { + if (!fruit.empty()) { tree_def.fruitnode=ndef->getId(fruit); getintfield(L, 2, "fruit_chance",tree_def.fruit_chance); } diff --git a/src/script/lua_api/l_http.cpp b/src/script/lua_api/l_http.cpp index 8bd39b6ed..641f4194a 100644 --- a/src/script/lua_api/l_http.cpp +++ b/src/script/lua_api/l_http.cpp @@ -69,7 +69,7 @@ void ModApiHttp::read_http_fetch_request(lua_State *L, HTTPFetchRequest &req) while (lua_next(L, 2) != 0) { const char *header = luaL_checkstring(L, -1); - req.extra_headers.push_back(header); + req.extra_headers.emplace_back(header); lua_pop(L, 1); } } diff --git a/src/script/lua_api/l_inventory.cpp b/src/script/lua_api/l_inventory.cpp index aac5eed8e..b0d43090c 100644 --- a/src/script/lua_api/l_inventory.cpp +++ b/src/script/lua_api/l_inventory.cpp @@ -409,10 +409,6 @@ InvRef::InvRef(const InventoryLocation &loc): { } -InvRef::~InvRef() -{ -} - // Creates an InvRef and leaves it on top of stack // Not callable from Lua; all references are created on the C side. void InvRef::create(lua_State *L, const InventoryLocation &loc) diff --git a/src/script/lua_api/l_inventory.h b/src/script/lua_api/l_inventory.h index f12377ece..2b7910ac3 100644 --- a/src/script/lua_api/l_inventory.h +++ b/src/script/lua_api/l_inventory.h @@ -106,7 +106,7 @@ private: public: InvRef(const InventoryLocation &loc); - ~InvRef(); + ~InvRef() = default; // Creates an InvRef and leaves it on top of stack // Not callable from Lua; all references are created on the C side. diff --git a/src/script/lua_api/l_item.cpp b/src/script/lua_api/l_item.cpp index 0e4fc4ef0..207a04c6c 100644 --- a/src/script/lua_api/l_item.cpp +++ b/src/script/lua_api/l_item.cpp @@ -67,7 +67,7 @@ int LuaItemStack::l_set_name(lua_State *L) bool status = true; item.name = luaL_checkstring(L, 2); - if (item.name == "" || item.empty()) { + if (item.name.empty() || item.empty()) { item.clear(); status = false; } @@ -231,12 +231,11 @@ int LuaItemStack::l_to_table(lua_State *L) lua_newtable(L); const StringMap &fields = item.metadata.getStrings(); - for (StringMap::const_iterator it = fields.begin(); - it != fields.end(); ++it) { - const std::string &name = it->first; + for (const auto &field : fields) { + const std::string &name = field.first; if (name.empty()) continue; - const std::string &value = it->second; + const std::string &value = field.second; lua_pushlstring(L, name.c_str(), name.size()); lua_pushlstring(L, value.c_str(), value.size()); lua_settable(L, -3); @@ -391,10 +390,6 @@ LuaItemStack::LuaItemStack(const ItemStack &item): { } -LuaItemStack::~LuaItemStack() -{ -} - const ItemStack& LuaItemStack::getItem() const { return m_stack; diff --git a/src/script/lua_api/l_item.h b/src/script/lua_api/l_item.h index 6aa62808b..5ff715b2a 100644 --- a/src/script/lua_api/l_item.h +++ b/src/script/lua_api/l_item.h @@ -121,7 +121,7 @@ private: public: LuaItemStack(const ItemStack &item); - ~LuaItemStack(); + ~LuaItemStack() = default; const ItemStack& getItem() const; ItemStack& getItem(); diff --git a/src/script/lua_api/l_itemstackmeta.h b/src/script/lua_api/l_itemstackmeta.h index cfaece794..241f04c4c 100644 --- a/src/script/lua_api/l_itemstackmeta.h +++ b/src/script/lua_api/l_itemstackmeta.h @@ -46,7 +46,7 @@ private: static int gc_object(lua_State *L); public: ItemStackMetaRef(ItemStack *istack): istack(istack) {} - ~ItemStackMetaRef() {} + ~ItemStackMetaRef() = default; // Creates an ItemStackMetaRef and leaves it on top of stack // Not callable from Lua; all references are created on the C side. diff --git a/src/script/lua_api/l_localplayer.h b/src/script/lua_api/l_localplayer.h index dcb5c878c..d30fe1d64 100644 --- a/src/script/lua_api/l_localplayer.h +++ b/src/script/lua_api/l_localplayer.h @@ -70,7 +70,7 @@ private: public: LuaLocalPlayer(LocalPlayer *m); - ~LuaLocalPlayer() {} + ~LuaLocalPlayer() = default; static void create(lua_State *L, LocalPlayer *m); diff --git a/src/script/lua_api/l_minimap.h b/src/script/lua_api/l_minimap.h index 2d0e6ae9f..cc859ad0d 100644 --- a/src/script/lua_api/l_minimap.h +++ b/src/script/lua_api/l_minimap.h @@ -51,7 +51,7 @@ private: public: LuaMinimap(Minimap *m); - ~LuaMinimap() {} + ~LuaMinimap() = default; static void create(lua_State *L, Minimap *object); diff --git a/src/script/lua_api/l_nodemeta.cpp b/src/script/lua_api/l_nodemeta.cpp index d1f314079..3d7adf27d 100644 --- a/src/script/lua_api/l_nodemeta.cpp +++ b/src/script/lua_api/l_nodemeta.cpp @@ -182,10 +182,6 @@ NodeMetaRef::NodeMetaRef(Metadata *meta): { } -NodeMetaRef::~NodeMetaRef() -{ -} - // Creates an NodeMetaRef and leaves it on top of stack // Not callable from Lua; all references are created on the C side. void NodeMetaRef::create(lua_State *L, v3s16 p, ServerEnvironment *env) diff --git a/src/script/lua_api/l_nodemeta.h b/src/script/lua_api/l_nodemeta.h index 683f79932..b0b4a9623 100644 --- a/src/script/lua_api/l_nodemeta.h +++ b/src/script/lua_api/l_nodemeta.h @@ -80,7 +80,7 @@ public: NodeMetaRef(v3s16 p, ServerEnvironment *env); NodeMetaRef(Metadata *meta); - ~NodeMetaRef(); + ~NodeMetaRef() = default; // Creates an NodeMetaRef and leaves it on top of stack // Not callable from Lua; all references are created on the C side. diff --git a/src/script/lua_api/l_nodetimer.cpp b/src/script/lua_api/l_nodetimer.cpp index 17b275c46..55d3aec70 100644 --- a/src/script/lua_api/l_nodetimer.cpp +++ b/src/script/lua_api/l_nodetimer.cpp @@ -113,10 +113,6 @@ NodeTimerRef::NodeTimerRef(v3s16 p, ServerEnvironment *env): { } -NodeTimerRef::~NodeTimerRef() -{ -} - // Creates an NodeTimerRef and leaves it on top of stack // Not callable from Lua; all references are created on the C side. void NodeTimerRef::create(lua_State *L, v3s16 p, ServerEnvironment *env) diff --git a/src/script/lua_api/l_nodetimer.h b/src/script/lua_api/l_nodetimer.h index c7cc76244..b894c5c8c 100644 --- a/src/script/lua_api/l_nodetimer.h +++ b/src/script/lua_api/l_nodetimer.h @@ -51,7 +51,7 @@ private: public: NodeTimerRef(v3s16 p, ServerEnvironment *env); - ~NodeTimerRef(); + ~NodeTimerRef() = default; // Creates an NodeTimerRef and leaves it on top of stack // Not callable from Lua; all references are created on the C side. diff --git a/src/script/lua_api/l_noise.cpp b/src/script/lua_api/l_noise.cpp index e3e76191f..35d3bbb6e 100644 --- a/src/script/lua_api/l_noise.cpp +++ b/src/script/lua_api/l_noise.cpp @@ -36,11 +36,6 @@ LuaPerlinNoise::LuaPerlinNoise(NoiseParams *params) : } -LuaPerlinNoise::~LuaPerlinNoise() -{ -} - - int LuaPerlinNoise::l_get2d(lua_State *L) { NO_MAP_LOCK_REQUIRED; diff --git a/src/script/lua_api/l_noise.h b/src/script/lua_api/l_noise.h index 8af4fbd12..552d67db9 100644 --- a/src/script/lua_api/l_noise.h +++ b/src/script/lua_api/l_noise.h @@ -43,7 +43,7 @@ private: public: LuaPerlinNoise(NoiseParams *params); - ~LuaPerlinNoise(); + ~LuaPerlinNoise() = default; // LuaPerlinNoise(seed, octaves, persistence, scale) // Creates an LuaPerlinNoise and leaves it on top of stack diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp index 9ddbc3e41..bad5ec8af 100644 --- a/src/script/lua_api/l_object.cpp +++ b/src/script/lua_api/l_object.cpp @@ -551,8 +551,8 @@ int ObjectRef::l_get_local_animation(lua_State *L) float frame_speed; player->getLocalAnimations(frames, &frame_speed); - for (int i = 0; i < 4; i++) { - push_v2s32(L, frames[i]); + for (v2s32 frame : frames) { + push_v2s32(L, frame); } lua_pushnumber(L, frame_speed); @@ -611,7 +611,7 @@ int ObjectRef::l_set_bone_position(lua_State *L) ServerActiveObject *co = getobject(ref); if (co == NULL) return 0; // Do it - std::string bone = ""; + std::string bone; if (!lua_isnil(L, 2)) bone = lua_tostring(L, 2); v3f position = v3f(0, 0, 0); @@ -633,7 +633,7 @@ int ObjectRef::l_get_bone_position(lua_State *L) if (co == NULL) return 0; // Do it - std::string bone = ""; + std::string bone; if (!lua_isnil(L, 2)) bone = lua_tostring(L, 2); @@ -661,7 +661,7 @@ int ObjectRef::l_set_attach(lua_State *L) return 0; // Do it int parent_id = 0; - std::string bone = ""; + std::string bone; v3f position = v3f(0, 0, 0); v3f rotation = v3f(0, 0, 0); co->getAttachment(&parent_id, &bone, &position, &rotation); @@ -696,7 +696,7 @@ int ObjectRef::l_get_attach(lua_State *L) // Do it int parent_id = 0; - std::string bone = ""; + std::string bone; v3f position = v3f(0, 0, 0); v3f rotation = v3f(0, 0, 0); co->getAttachment(&parent_id, &bone, &position, &rotation); @@ -722,7 +722,7 @@ int ObjectRef::l_set_detach(lua_State *L) return 0; int parent_id = 0; - std::string bone = ""; + std::string bone; v3f position; v3f rotation; co->getAttachment(&parent_id, &bone, &position, &rotation); @@ -1223,7 +1223,7 @@ int ObjectRef::l_get_attribute(lua_State *L) std::string attr = luaL_checkstring(L, 2); - std::string value = ""; + std::string value; if (co->getExtendedAttribute(attr, &value)) { lua_pushstring(L, value.c_str()); return 1; @@ -1684,9 +1684,9 @@ int ObjectRef::l_set_sky(lua_State *L) while (lua_next(L, 4) != 0) { // key at index -2 and value at index -1 if (lua_isstring(L, -1)) - params.push_back(lua_tostring(L, -1)); + params.emplace_back(lua_tostring(L, -1)); else - params.push_back(""); + params.emplace_back(""); // removes value, keeps key for next iteration lua_pop(L, 1); } @@ -1720,15 +1720,14 @@ int ObjectRef::l_get_sky(lua_State *L) bool clouds; player->getSky(&bgcolor, &type, ¶ms, &clouds); - type = type == "" ? "regular" : type; + type = type.empty() ? "regular" : type; push_ARGB8(L, bgcolor); lua_pushlstring(L, type.c_str(), type.size()); lua_newtable(L); s16 i = 1; - for (std::vector<std::string>::iterator it = params.begin(); - it != params.end(); ++it) { - lua_pushlstring(L, it->c_str(), it->size()); + for (const std::string ¶m : params) { + lua_pushlstring(L, param.c_str(), param.size()); lua_rawseti(L, -2, i); i++; } @@ -1865,15 +1864,6 @@ ObjectRef::ObjectRef(ServerActiveObject *object): //infostream<<"ObjectRef created for id="<<m_object->getId()<<std::endl; } -ObjectRef::~ObjectRef() -{ - /*if (m_object) - infostream<<"ObjectRef destructing for id=" - <<m_object->getId()<<std::endl; - else - infostream<<"ObjectRef destructing for id=unknown"<<std::endl;*/ -} - // Creates an ObjectRef and leaves it on top of stack // Not callable from Lua; all references are created on the C side. void ObjectRef::create(lua_State *L, ServerActiveObject *object) diff --git a/src/script/lua_api/l_object.h b/src/script/lua_api/l_object.h index a2438e434..19cc890c7 100644 --- a/src/script/lua_api/l_object.h +++ b/src/script/lua_api/l_object.h @@ -35,7 +35,7 @@ class ObjectRef : public ModApiBase { public: ObjectRef(ServerActiveObject *object); - ~ObjectRef(); + ~ObjectRef() = default; // Creates an ObjectRef and leaves it on top of stack // Not callable from Lua; all references are created on the C side. diff --git a/src/script/lua_api/l_particles.cpp b/src/script/lua_api/l_particles.cpp index 2f3e9a58d..8a7de8b4f 100644 --- a/src/script/lua_api/l_particles.cpp +++ b/src/script/lua_api/l_particles.cpp @@ -53,8 +53,8 @@ int ModApiParticles::l_add_particle(lua_State *L) struct TileAnimationParams animation; animation.type = TAT_NONE; - std::string texture = ""; - std::string playername = ""; + std::string texture; + std::string playername; u8 glow = 0; @@ -158,8 +158,8 @@ int ModApiParticles::l_add_particlespawner(lua_State *L) struct TileAnimationParams animation; animation.type = TAT_NONE; ServerActiveObject *attached = NULL; - std::string texture = ""; - std::string playername = ""; + std::string texture; + std::string playername; u8 glow = 0; if (lua_gettop(L) > 1) //deprecated @@ -262,7 +262,7 @@ int ModApiParticles::l_delete_particlespawner(lua_State *L) // Get parameters u32 id = luaL_checknumber(L, 1); - std::string playername = ""; + std::string playername; if (lua_gettop(L) == 2) { playername = luaL_checkstring(L, 2); } diff --git a/src/script/lua_api/l_settings.cpp b/src/script/lua_api/l_settings.cpp index 3dc5c9574..2d6769ea1 100644 --- a/src/script/lua_api/l_settings.cpp +++ b/src/script/lua_api/l_settings.cpp @@ -198,10 +198,9 @@ int LuaSettings::l_to_table(lua_State* L) std::vector<std::string> keys = o->m_settings->getNames(); lua_newtable(L); - for (unsigned int i=0; i < keys.size(); i++) - { - lua_pushstring(L, o->m_settings->get(keys[i]).c_str()); - lua_setfield(L, -2, keys[i].c_str()); + for (const std::string &key : keys) { + lua_pushstring(L, o->m_settings->get(key).c_str()); + lua_setfield(L, -2, key.c_str()); } return 1; diff --git a/src/script/lua_api/l_storage.h b/src/script/lua_api/l_storage.h index 4e808c393..f8d102d04 100644 --- a/src/script/lua_api/l_storage.h +++ b/src/script/lua_api/l_storage.h @@ -50,7 +50,7 @@ private: public: StorageRef(ModMetadata *object); - ~StorageRef() {} + ~StorageRef() = default; static void Register(lua_State *L); static void create(lua_State *L, ModMetadata *object); diff --git a/src/script/lua_api/l_util.cpp b/src/script/lua_api/l_util.cpp index c68f64a64..dffbc66d1 100644 --- a/src/script/lua_api/l_util.cpp +++ b/src/script/lua_api/l_util.cpp @@ -344,9 +344,9 @@ int ModApiUtil::l_get_dir_list(lua_State *L) int index = 0; lua_newtable(L); - for (size_t i = 0; i < list.size(); i++) { - if (list_all || list_dirs == list[i].dir) { - lua_pushstring(L, list[i].name.c_str()); + for (const fs::DirListNode &dln : list) { + if (list_all || list_dirs == dln.dir) { + lua_pushstring(L, dln.name.c_str()); lua_rawseti(L, -2, ++index); } } @@ -414,7 +414,7 @@ int ModApiUtil::l_get_version(lua_State *L) lua_pushstring(L, g_version_string); lua_setfield(L, table, "string"); - if (strcmp(g_version_string, g_version_hash)) { + if (strcmp(g_version_string, g_version_hash) != 0) { lua_pushstring(L, g_version_hash); lua_setfield(L, table, "hash"); } diff --git a/src/script/lua_api/l_vmanip.cpp b/src/script/lua_api/l_vmanip.cpp index 1e973703c..a84ecfc0f 100644 --- a/src/script/lua_api/l_vmanip.cpp +++ b/src/script/lua_api/l_vmanip.cpp @@ -111,7 +111,7 @@ int LuaVoxelManip::l_write_to_map(lua_State *L) MAP_LOCK_REQUIRED; LuaVoxelManip *o = checkobject(L, 1); - bool update_light = lua_isboolean(L, 2) ? lua_toboolean(L, 2) : true; + bool update_light = !lua_isboolean(L, 2) || lua_toboolean(L, 2); GET_ENV_PTR; ServerMap *map = &(env->getServerMap()); if (o->is_mapgen_vm || !update_light) { @@ -123,9 +123,8 @@ int LuaVoxelManip::l_write_to_map(lua_State *L) MapEditEvent event; event.type = MEET_OTHER; - for (std::map<v3s16, MapBlock *>::iterator it = o->modified_blocks.begin(); - it != o->modified_blocks.end(); ++it) - event.modified_blocks.insert(it->first); + for (const auto &modified_block : o->modified_blocks) + event.modified_blocks.insert(modified_block.first); map->dispatchEvent(&event); @@ -198,7 +197,7 @@ int LuaVoxelManip::l_calc_lighting(lua_State *L) v3s16 fpmax = vm->m_area.MaxEdge; v3s16 pmin = lua_istable(L, 2) ? check_v3s16(L, 2) : fpmin + yblock; v3s16 pmax = lua_istable(L, 3) ? check_v3s16(L, 3) : fpmax - yblock; - bool propagate_shadow = lua_isboolean(L, 4) ? lua_toboolean(L, 4) : true; + bool propagate_shadow = !lua_isboolean(L, 4) || lua_toboolean(L, 4); sortBoxVerticies(pmin, pmax); if (!vm->m_area.contains(VoxelArea(pmin, pmax))) |