From 88b436e6a9c98af7215bd115e1b7a3f1a1db99d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Blot?= Date: Sat, 19 Aug 2017 22:23:47 +0200 Subject: Code modernization: subfolders (#6283) * Code modernization: subfolders Modernize various code on subfolders client, network, script, threading, unittests, util * empty function * default constructor/destructor * for range-based loops * use emplace_back instead of push_back * C++ STL header style * Make connection.cpp readable in a pointed place + typo --- src/script/lua_api/l_object.cpp | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) (limited to 'src/script/lua_api/l_object.cpp') 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::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="<getId()<