summaryrefslogtreecommitdiff
path: root/src/script/lua_api/l_object.cpp
diff options
context:
space:
mode:
authorLoïc Blot <nerzhul@users.noreply.github.com>2017-08-19 22:23:47 +0200
committerGitHub <noreply@github.com>2017-08-19 22:23:47 +0200
commit88b436e6a9c98af7215bd115e1b7a3f1a1db99d3 (patch)
treef07cdd7f93ca26b84192d7b89f7b952e603ba5cf /src/script/lua_api/l_object.cpp
parent7528986e4449febead9b18b6118f0b096f7cf800 (diff)
downloadminetest-88b436e6a9c98af7215bd115e1b7a3f1a1db99d3.tar.gz
minetest-88b436e6a9c98af7215bd115e1b7a3f1a1db99d3.tar.bz2
minetest-88b436e6a9c98af7215bd115e1b7a3f1a1db99d3.zip
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
Diffstat (limited to 'src/script/lua_api/l_object.cpp')
-rw-r--r--src/script/lua_api/l_object.cpp36
1 files changed, 13 insertions, 23 deletions
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, &params, &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 &param : 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)