summaryrefslogtreecommitdiff
path: root/src/script/lua_api/l_craft.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_craft.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_craft.cpp')
-rw-r--r--src/script/lua_api/l_craft.cpp29
1 files changed, 14 insertions, 15 deletions
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);