summaryrefslogtreecommitdiff
path: root/src/script/lua_api
diff options
context:
space:
mode:
Diffstat (limited to 'src/script/lua_api')
-rw-r--r--src/script/lua_api/l_client.cpp1
-rw-r--r--src/script/lua_api/l_env.cpp4
-rw-r--r--src/script/lua_api/l_inventory.cpp33
-rw-r--r--src/script/lua_api/l_mainmenu.cpp92
-rw-r--r--src/script/lua_api/l_mapgen.cpp9
-rw-r--r--src/script/lua_api/l_metadata.cpp7
-rw-r--r--src/script/lua_api/l_metadata.h2
-rw-r--r--src/script/lua_api/l_object.cpp2
8 files changed, 72 insertions, 78 deletions
diff --git a/src/script/lua_api/l_client.cpp b/src/script/lua_api/l_client.cpp
index 6a87b20e9..81bf49329 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"
-
int ModApiClient::l_get_current_modname(lua_State *L)
{
lua_rawgeti(L, LUA_REGISTRYINDEX, CUSTOM_RIDX_CURRENT_MOD_NAME);
diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp
index 94edf201e..07d33a4eb 100644
--- a/src/script/lua_api/l_env.cpp
+++ b/src/script/lua_api/l_env.cpp
@@ -743,7 +743,7 @@ 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 (v3s16 i : list) {
+ for (const v3s16 &i : list) {
v3s16 p = pos + i;
content_t c = env->getMap().getNodeNoEx(p).getContent();
if (filter.count(c) != 0) {
@@ -1127,7 +1127,7 @@ int ModApiEnvMod::l_find_path(lua_State *L)
lua_newtable(L);
int top = lua_gettop(L);
unsigned int index = 1;
- for (v3s16 i : path) {
+ for (const v3s16 &i : path) {
lua_pushnumber(L,index);
push_v3s16(L, i);
lua_settable(L, top);
diff --git a/src/script/lua_api/l_inventory.cpp b/src/script/lua_api/l_inventory.cpp
index b0d43090c..f3097582e 100644
--- a/src/script/lua_api/l_inventory.cpp
+++ b/src/script/lua_api/l_inventory.cpp
@@ -495,28 +495,29 @@ int ModApiInventory::l_get_inventory(lua_State *L)
v3s16 pos = check_v3s16(L, -1);
loc.setNodeMeta(pos);
- if(getServer(L)->getInventory(loc) != NULL)
+ if (getServer(L)->getInventory(loc) != NULL)
InvRef::create(L, loc);
else
lua_pushnil(L);
return 1;
- } else {
- NO_MAP_LOCK_REQUIRED;
- if(type == "player"){
- std::string name = checkstringfield(L, 1, "name");
- loc.setPlayer(name);
- } else if(type == "detached"){
- std::string name = checkstringfield(L, 1, "name");
- loc.setDetached(name);
- }
+ }
- if(getServer(L)->getInventory(loc) != NULL)
- InvRef::create(L, loc);
- else
- lua_pushnil(L);
- return 1;
- // END NO_MAP_LOCK_REQUIRED;
+ NO_MAP_LOCK_REQUIRED;
+ if (type == "player") {
+ std::string name = checkstringfield(L, 1, "name");
+ loc.setPlayer(name);
+ } else if (type == "detached") {
+ std::string name = checkstringfield(L, 1, "name");
+ loc.setDetached(name);
}
+
+ if (getServer(L)->getInventory(loc) != NULL)
+ InvRef::create(L, loc);
+ else
+ lua_pushnil(L);
+ return 1;
+ // END NO_MAP_LOCK_REQUIRED;
+
}
// create_detached_inventory_raw(name, [player_name])
diff --git a/src/script/lua_api/l_mainmenu.cpp b/src/script/lua_api/l_mainmenu.cpp
index b0ce6b740..86305de82 100644
--- a/src/script/lua_api/l_mainmenu.cpp
+++ b/src/script/lua_api/l_mainmenu.cpp
@@ -233,23 +233,22 @@ int ModApiMainMenu::l_get_worlds(lua_State *L)
int top = lua_gettop(L);
unsigned int index = 1;
- for (unsigned int i = 0; i < worlds.size(); i++)
- {
+ for (const WorldSpec &world : worlds) {
lua_pushnumber(L,index);
lua_newtable(L);
int top_lvl2 = lua_gettop(L);
lua_pushstring(L,"path");
- lua_pushstring(L,worlds[i].path.c_str());
+ lua_pushstring(L, world.path.c_str());
lua_settable(L, top_lvl2);
lua_pushstring(L,"name");
- lua_pushstring(L,worlds[i].name.c_str());
+ lua_pushstring(L, world.name.c_str());
lua_settable(L, top_lvl2);
lua_pushstring(L,"gameid");
- lua_pushstring(L,worlds[i].gameid.c_str());
+ lua_pushstring(L, world.gameid.c_str());
lua_settable(L, top_lvl2);
lua_settable(L, top);
@@ -267,40 +266,38 @@ int ModApiMainMenu::l_get_games(lua_State *L)
int top = lua_gettop(L);
unsigned int index = 1;
- for (unsigned int i = 0; i < games.size(); i++)
- {
+ for (const SubgameSpec &game : games) {
lua_pushnumber(L,index);
lua_newtable(L);
int top_lvl2 = lua_gettop(L);
lua_pushstring(L,"id");
- lua_pushstring(L,games[i].id.c_str());
+ lua_pushstring(L, game.id.c_str());
lua_settable(L, top_lvl2);
lua_pushstring(L,"path");
- lua_pushstring(L,games[i].path.c_str());
+ lua_pushstring(L, game.path.c_str());
lua_settable(L, top_lvl2);
lua_pushstring(L,"gamemods_path");
- lua_pushstring(L,games[i].gamemods_path.c_str());
+ lua_pushstring(L, game.gamemods_path.c_str());
lua_settable(L, top_lvl2);
lua_pushstring(L,"name");
- lua_pushstring(L,games[i].name.c_str());
+ lua_pushstring(L, game.name.c_str());
lua_settable(L, top_lvl2);
lua_pushstring(L,"menuicon_path");
- lua_pushstring(L,games[i].menuicon_path.c_str());
+ lua_pushstring(L, game.menuicon_path.c_str());
lua_settable(L, top_lvl2);
lua_pushstring(L,"addon_mods_paths");
lua_newtable(L);
int table2 = lua_gettop(L);
int internal_index=1;
- for (std::set<std::string>::iterator iter = games[i].addon_mods_paths.begin();
- iter != games[i].addon_mods_paths.end(); ++iter) {
+ for (const std::string &addon_mods_path : game.addon_mods_paths) {
lua_pushnumber(L,internal_index);
- lua_pushstring(L,(*iter).c_str());
+ lua_pushstring(L, addon_mods_path.c_str());
lua_settable(L, table2);
internal_index++;
}
@@ -331,112 +328,111 @@ int ModApiMainMenu::l_get_favorites(lua_State *L)
int top = lua_gettop(L);
unsigned int index = 1;
- for (unsigned int i = 0; i < servers.size(); i++)
- {
+ for (const Json::Value &server : servers) {
lua_pushnumber(L,index);
lua_newtable(L);
int top_lvl2 = lua_gettop(L);
- if (servers[i]["clients"].asString().size()) {
- std::string clients_raw = servers[i]["clients"].asString();
+ if (!server["clients"].asString().empty()) {
+ std::string clients_raw = server["clients"].asString();
char* endptr = 0;
int numbervalue = strtol(clients_raw.c_str(),&endptr,10);
- if ((clients_raw != "") && (*endptr == 0)) {
+ if ((!clients_raw.empty()) && (*endptr == 0)) {
lua_pushstring(L,"clients");
lua_pushnumber(L,numbervalue);
lua_settable(L, top_lvl2);
}
}
- if (servers[i]["clients_max"].asString().size()) {
+ if (!server["clients_max"].asString().empty()) {
- std::string clients_max_raw = servers[i]["clients_max"].asString();
+ std::string clients_max_raw = server["clients_max"].asString();
char* endptr = 0;
int numbervalue = strtol(clients_max_raw.c_str(),&endptr,10);
- if ((clients_max_raw != "") && (*endptr == 0)) {
+ if ((!clients_max_raw.empty()) && (*endptr == 0)) {
lua_pushstring(L,"clients_max");
lua_pushnumber(L,numbervalue);
lua_settable(L, top_lvl2);
}
}
- if (servers[i]["version"].asString().size()) {
+ if (!server["version"].asString().empty()) {
lua_pushstring(L,"version");
- std::string topush = servers[i]["version"].asString();
+ std::string topush = server["version"].asString();
lua_pushstring(L,topush.c_str());
lua_settable(L, top_lvl2);
}
- if (servers[i]["proto_min"].asString().size()) {
+ if (!server["proto_min"].asString().empty()) {
lua_pushstring(L,"proto_min");
- lua_pushinteger(L,servers[i]["proto_min"].asInt());
+ lua_pushinteger(L, server["proto_min"].asInt());
lua_settable(L, top_lvl2);
}
- if (servers[i]["proto_max"].asString().size()) {
+ if (!server["proto_max"].asString().empty()) {
lua_pushstring(L,"proto_max");
- lua_pushinteger(L,servers[i]["proto_max"].asInt());
+ lua_pushinteger(L, server["proto_max"].asInt());
lua_settable(L, top_lvl2);
}
- if (servers[i]["password"].asString().size()) {
+ if (!server["password"].asString().empty()) {
lua_pushstring(L,"password");
- lua_pushboolean(L,servers[i]["password"].asBool());
+ lua_pushboolean(L, server["password"].asBool());
lua_settable(L, top_lvl2);
}
- if (servers[i]["creative"].asString().size()) {
+ if (!server["creative"].asString().empty()) {
lua_pushstring(L,"creative");
- lua_pushboolean(L,servers[i]["creative"].asBool());
+ lua_pushboolean(L, server["creative"].asBool());
lua_settable(L, top_lvl2);
}
- if (servers[i]["damage"].asString().size()) {
+ if (!server["damage"].asString().empty()) {
lua_pushstring(L,"damage");
- lua_pushboolean(L,servers[i]["damage"].asBool());
+ lua_pushboolean(L, server["damage"].asBool());
lua_settable(L, top_lvl2);
}
- if (servers[i]["pvp"].asString().size()) {
+ if (!server["pvp"].asString().empty()) {
lua_pushstring(L,"pvp");
- lua_pushboolean(L,servers[i]["pvp"].asBool());
+ lua_pushboolean(L, server["pvp"].asBool());
lua_settable(L, top_lvl2);
}
- if (servers[i]["description"].asString().size()) {
+ if (!server["description"].asString().empty()) {
lua_pushstring(L,"description");
- std::string topush = servers[i]["description"].asString();
+ std::string topush = server["description"].asString();
lua_pushstring(L,topush.c_str());
lua_settable(L, top_lvl2);
}
- if (servers[i]["name"].asString().size()) {
+ if (!server["name"].asString().empty()) {
lua_pushstring(L,"name");
- std::string topush = servers[i]["name"].asString();
+ std::string topush = server["name"].asString();
lua_pushstring(L,topush.c_str());
lua_settable(L, top_lvl2);
}
- if (servers[i]["address"].asString().size()) {
+ if (!server["address"].asString().empty()) {
lua_pushstring(L,"address");
- std::string topush = servers[i]["address"].asString();
+ std::string topush = server["address"].asString();
lua_pushstring(L,topush.c_str());
lua_settable(L, top_lvl2);
}
- if (servers[i]["port"].asString().size()) {
+ if (!server["port"].asString().empty()) {
lua_pushstring(L,"port");
- std::string topush = servers[i]["port"].asString();
+ std::string topush = server["port"].asString();
lua_pushstring(L,topush.c_str());
lua_settable(L, top_lvl2);
}
- if (servers[i].isMember("ping")) {
- float ping = servers[i]["ping"].asFloat();
+ if (server.isMember("ping")) {
+ float ping = server["ping"].asFloat();
lua_pushstring(L, "ping");
lua_pushnumber(L, ping);
lua_settable(L, top_lvl2);
@@ -558,7 +554,7 @@ int ModApiMainMenu::l_set_topleft_text(lua_State *L)
GUIEngine* engine = getGuiEngine(L);
sanity_check(engine != NULL);
- std::string text = "";
+ std::string text;
if (!lua_isnone(L,1) && !lua_isnil(L,1))
text = luaL_checkstring(L, 1);
diff --git a/src/script/lua_api/l_mapgen.cpp b/src/script/lua_api/l_mapgen.cpp
index 454e8f719..a5e122ddb 100644
--- a/src/script/lua_api/l_mapgen.cpp
+++ b/src/script/lua_api/l_mapgen.cpp
@@ -847,9 +847,8 @@ int ModApiMapgen::l_get_gen_notify(lua_State *L)
lua_newtable(L);
int i = 1;
- for (std::set<u32>::iterator it = emerge->gen_notify_on_deco_ids.begin();
- it != emerge->gen_notify_on_deco_ids.end(); ++it) {
- lua_pushnumber(L, *it);
+ for (u32 gen_notify_on_deco_id : emerge->gen_notify_on_deco_ids) {
+ lua_pushnumber(L, gen_notify_on_deco_id);
lua_rawseti(L, -2, i);
i++;
}
@@ -1322,7 +1321,7 @@ int ModApiMapgen::l_create_schematic(lua_State *L)
lua_pop(L, 1);
u8 prob = getintfield_default(L, -1, "prob", MTSCHEM_PROB_ALWAYS);
- prob_list.push_back(std::make_pair(pos, prob));
+ prob_list.emplace_back(pos, prob);
}
lua_pop(L, 1);
@@ -1336,7 +1335,7 @@ int ModApiMapgen::l_create_schematic(lua_State *L)
if (lua_istable(L, -1)) {
s16 ypos = getintfield_default(L, -1, "ypos", 0);
u8 prob = getintfield_default(L, -1, "prob", MTSCHEM_PROB_ALWAYS);
- slice_prob_list.push_back(std::make_pair(ypos, prob));
+ slice_prob_list.emplace_back(ypos, prob);
}
lua_pop(L, 1);
diff --git a/src/script/lua_api/l_metadata.cpp b/src/script/lua_api/l_metadata.cpp
index 5f4e984cb..494d2dce0 100644
--- a/src/script/lua_api/l_metadata.cpp
+++ b/src/script/lua_api/l_metadata.cpp
@@ -218,10 +218,9 @@ void MetaDataRef::handleToTable(lua_State *L, Metadata *meta)
lua_newtable(L);
{
const StringMap &fields = meta->getStrings();
- for (StringMap::const_iterator
- it = fields.begin(); it != fields.end(); ++it) {
- const std::string &name = it->first;
- const std::string &value = it->second;
+ for (const auto &field : fields) {
+ const std::string &name = field.first;
+ 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);
diff --git a/src/script/lua_api/l_metadata.h b/src/script/lua_api/l_metadata.h
index 5a7c7e7f7..e0e9696cb 100644
--- a/src/script/lua_api/l_metadata.h
+++ b/src/script/lua_api/l_metadata.h
@@ -31,7 +31,7 @@ class Metadata;
class MetaDataRef : public ModApiBase
{
public:
- virtual ~MetaDataRef() {}
+ virtual ~MetaDataRef() = default;
protected:
static MetaDataRef *checkobject(lua_State *L, int narg);
diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp
index bad5ec8af..a65a5e88f 100644
--- a/src/script/lua_api/l_object.cpp
+++ b/src/script/lua_api/l_object.cpp
@@ -551,7 +551,7 @@ int ObjectRef::l_get_local_animation(lua_State *L)
float frame_speed;
player->getLocalAnimations(frames, &frame_speed);
- for (v2s32 frame : frames) {
+ for (const v2s32 &frame : frames) {
push_v2s32(L, frame);
}