aboutsummaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
authorLoïc Blot <nerzhul@users.noreply.github.com>2017-04-19 23:02:07 +0200
committerGitHub <noreply@github.com>2017-04-19 23:02:07 +0200
commitf3fe62a0bf9e775b3e6e838f104ab605a2238792 (patch)
tree1335fc9752d54924dd3a8f22e70d555fb54945c8 /src/script
parentcfe0291b131630a7400fdcf46b720bd70d8d0fa0 (diff)
downloadminetest-f3fe62a0bf9e775b3e6e838f104ab605a2238792.tar.gz
minetest-f3fe62a0bf9e775b3e6e838f104ab605a2238792.tar.bz2
minetest-f3fe62a0bf9e775b3e6e838f104ab605a2238792.zip
Fix various copy instead of const ref reported by cppcheck (#5615)
* Also remove InventoryList::peekItem unused function * Fix some post increment to preincrement reported by cppcheck
Diffstat (limited to 'src/script')
-rw-r--r--src/script/common/c_content.cpp19
-rw-r--r--src/script/common/c_content.h4
-rw-r--r--src/script/lua_api/l_item.cpp2
3 files changed, 10 insertions, 15 deletions
diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp
index bcae874b9..8dfb851e6 100644
--- a/src/script/common/c_content.cpp
+++ b/src/script/common/c_content.cpp
@@ -43,15 +43,12 @@ struct EnumString es_TileAnimationType[] =
};
/******************************************************************************/
-ItemDefinition read_item_definition(lua_State* L,int index,
- ItemDefinition default_def)
+void read_item_definition(lua_State* L, int index,
+ const ItemDefinition &default_def, ItemDefinition &def)
{
- if(index < 0)
+ if (index < 0)
index = lua_gettop(L) + 1 + index;
- // Read the item definition
- ItemDefinition def = default_def;
-
def.type = (ItemType)getenumfield(L, index, "type",
es_ItemType, ITEM_NONE);
getstringfield(L, index, "name", def.name);
@@ -118,8 +115,6 @@ ItemDefinition read_item_definition(lua_State* L,int index,
// "" = no prediction
getstringfield(L, index, "node_placement_prediction",
def.node_placement_prediction);
-
- return def;
}
/******************************************************************************/
@@ -873,7 +868,7 @@ void push_tool_capabilities(lua_State *L,
lua_newtable(L);
// For each groupcap
for (ToolGCMap::const_iterator i = toolcap.groupcaps.begin();
- i != toolcap.groupcaps.end(); i++) {
+ i != toolcap.groupcaps.end(); ++i) {
// Create groupcap table
lua_newtable(L);
const std::string &name = i->first;
@@ -881,7 +876,7 @@ void push_tool_capabilities(lua_State *L,
// Create subtable "times"
lua_newtable(L);
for (UNORDERED_MAP<int, float>::const_iterator
- i = groupcap.times.begin(); i != groupcap.times.end(); i++) {
+ i = groupcap.times.begin(); i != groupcap.times.end(); ++i) {
lua_pushinteger(L, i->first);
lua_pushnumber(L, i->second);
lua_settable(L, -3);
@@ -900,7 +895,7 @@ void push_tool_capabilities(lua_State *L,
lua_newtable(L);
// For each damage group
for (DamageGroup::const_iterator i = toolcap.damageGroups.begin();
- i != toolcap.damageGroups.end(); i++) {
+ i != toolcap.damageGroups.end(); ++i) {
// Create damage group table
lua_pushinteger(L, i->second);
lua_setfield(L, -2, i->first.c_str());
@@ -939,7 +934,7 @@ void read_inventory_list(lua_State *L, int tableindex,
InventoryList *invlist = inv->addList(name, listsize);
int index = 0;
for(std::vector<ItemStack>::const_iterator
- i = items.begin(); i != items.end(); i++){
+ i = items.begin(); i != items.end(); ++i){
if(forcesize != -1 && index == forcesize)
break;
invlist->changeItem(index, *i);
diff --git a/src/script/common/c_content.h b/src/script/common/c_content.h
index 949b136eb..c701c0384 100644
--- a/src/script/common/c_content.h
+++ b/src/script/common/c_content.h
@@ -86,8 +86,8 @@ ToolCapabilities read_tool_capabilities (lua_State *L, int table);
void push_tool_capabilities (lua_State *L,
const ToolCapabilities &prop);
-ItemDefinition read_item_definition (lua_State *L, int index,
- ItemDefinition default_def);
+void read_item_definition (lua_State *L, int index, const ItemDefinition &default_def,
+ ItemDefinition &def);
void read_object_properties (lua_State *L, int index,
ObjectProperties *prop,
IItemDefManager *idef);
diff --git a/src/script/lua_api/l_item.cpp b/src/script/lua_api/l_item.cpp
index 2d32093a7..0e4fc4ef0 100644
--- a/src/script/lua_api/l_item.cpp
+++ b/src/script/lua_api/l_item.cpp
@@ -526,7 +526,7 @@ int ModApiItemMod::l_register_item_raw(lua_State *L)
def.node_placement_prediction = "__default";
// Read the item definition
- def = read_item_definition(L, table, def);
+ read_item_definition(L, table, def, def);
// Default to having client-side placement prediction for nodes
// ("" in item definition sets it off)