aboutsummaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
Diffstat (limited to 'src/script')
-rw-r--r--src/script/cpp_api/s_mainmenu.cpp6
-rw-r--r--src/script/cpp_api/s_mainmenu.h4
-rw-r--r--src/script/cpp_api/s_node.cpp6
-rw-r--r--src/script/cpp_api/s_node.h5
-rw-r--r--src/script/cpp_api/s_player.cpp21
-rw-r--r--src/script/cpp_api/s_player.h10
-rw-r--r--src/script/lua_api/l_nodemeta.cpp22
7 files changed, 39 insertions, 35 deletions
diff --git a/src/script/cpp_api/s_mainmenu.cpp b/src/script/cpp_api/s_mainmenu.cpp
index ef8cea6c9..0bb247fa0 100644
--- a/src/script/cpp_api/s_mainmenu.cpp
+++ b/src/script/cpp_api/s_mainmenu.cpp
@@ -53,7 +53,7 @@ void ScriptApiMainMenu::handleMainMenuEvent(std::string text)
scriptError();
}
-void ScriptApiMainMenu::handleMainMenuButtons(std::map<std::string, std::string> fields)
+void ScriptApiMainMenu::handleMainMenuButtons(const StringMap &fields)
{
SCRIPTAPI_PRECHECKHEADER
@@ -69,8 +69,8 @@ void ScriptApiMainMenu::handleMainMenuButtons(std::map<std::string, std::string>
// Convert fields to a Lua table
lua_newtable(L);
- std::map<std::string, std::string>::const_iterator it;
- for (it = fields.begin(); it != fields.end(); it++){
+ StringMap::const_iterator it;
+ for (it = fields.begin(); it != fields.end(); ++it) {
const std::string &name = it->first;
const std::string &value = it->second;
lua_pushstring(L, name.c_str());
diff --git a/src/script/cpp_api/s_mainmenu.h b/src/script/cpp_api/s_mainmenu.h
index 53dcd37e9..6994b578b 100644
--- a/src/script/cpp_api/s_mainmenu.h
+++ b/src/script/cpp_api/s_mainmenu.h
@@ -21,7 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define S_MAINMENU_H_
#include "cpp_api/s_base.h"
-#include <map>
+#include "util/string.h"
class ScriptApiMainMenu
: virtual public ScriptApiBase
@@ -43,7 +43,7 @@ public:
* process field data recieved from formspec
* @param fields data in field format
*/
- void handleMainMenuButtons(std::map<std::string, std::string> fields);
+ void handleMainMenuButtons(const StringMap &fields);
};
#endif /* S_MAINMENU_H_ */
diff --git a/src/script/cpp_api/s_node.cpp b/src/script/cpp_api/s_node.cpp
index e3d3fb58b..7df712ca0 100644
--- a/src/script/cpp_api/s_node.cpp
+++ b/src/script/cpp_api/s_node.cpp
@@ -200,7 +200,7 @@ bool ScriptApiNode::node_on_timer(v3s16 p, MapNode node, f32 dtime)
void ScriptApiNode::node_on_receive_fields(v3s16 p,
const std::string &formname,
- const std::map<std::string, std::string> &fields,
+ const StringMap &fields,
ServerActiveObject *sender)
{
SCRIPTAPI_PRECHECKHEADER
@@ -220,8 +220,8 @@ void ScriptApiNode::node_on_receive_fields(v3s16 p,
push_v3s16(L, p); // pos
lua_pushstring(L, formname.c_str()); // formname
lua_newtable(L); // fields
- std::map<std::string, std::string>::const_iterator it;
- for (it = fields.begin(); it != fields.end(); it++){
+ StringMap::const_iterator it;
+ for (it = fields.begin(); it != fields.end(); it++) {
const std::string &name = it->first;
const std::string &value = it->second;
lua_pushstring(L, name.c_str());
diff --git a/src/script/cpp_api/s_node.h b/src/script/cpp_api/s_node.h
index b3a6c83b5..fe1180cb3 100644
--- a/src/script/cpp_api/s_node.h
+++ b/src/script/cpp_api/s_node.h
@@ -20,11 +20,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#ifndef S_NODE_H_
#define S_NODE_H_
-#include <map>
-
#include "irr_v3d.h"
#include "cpp_api/s_base.h"
#include "cpp_api/s_nodemeta.h"
+#include "util/string.h"
struct MapNode;
class ServerActiveObject;
@@ -47,7 +46,7 @@ public:
bool node_on_timer(v3s16 p, MapNode node, f32 dtime);
void node_on_receive_fields(v3s16 p,
const std::string &formname,
- const std::map<std::string, std::string> &fields,
+ const StringMap &fields,
ServerActiveObject *sender);
void node_falling_update(v3s16 p);
void node_falling_update_single(v3s16 p);
diff --git a/src/script/cpp_api/s_player.cpp b/src/script/cpp_api/s_player.cpp
index d56766824..9b2c3753c 100644
--- a/src/script/cpp_api/s_player.cpp
+++ b/src/script/cpp_api/s_player.cpp
@@ -83,7 +83,10 @@ bool ScriptApiPlayer::on_respawnplayer(ServerActiveObject *player)
return positioning_handled_by_some;
}
-bool ScriptApiPlayer::on_prejoinplayer(std::string name, std::string ip, std::string &reason)
+bool ScriptApiPlayer::on_prejoinplayer(
+ const std::string &name,
+ const std::string &ip,
+ std::string *reason)
{
SCRIPTAPI_PRECHECKHEADER
@@ -94,7 +97,7 @@ bool ScriptApiPlayer::on_prejoinplayer(std::string name, std::string ip, std::st
lua_pushstring(L, ip.c_str());
script_run_callbacks(L, 2, RUN_CALLBACKS_MODE_OR);
if (lua_isstring(L, -1)) {
- reason.assign(lua_tostring(L, -1));
+ reason->assign(lua_tostring(L, -1));
return true;
}
return false;
@@ -142,7 +145,7 @@ void ScriptApiPlayer::on_cheat(ServerActiveObject *player,
void ScriptApiPlayer::on_playerReceiveFields(ServerActiveObject *player,
const std::string &formname,
- const std::map<std::string, std::string> &fields)
+ const StringMap &fields)
{
SCRIPTAPI_PRECHECKHEADER
@@ -156,17 +159,19 @@ void ScriptApiPlayer::on_playerReceiveFields(ServerActiveObject *player,
lua_pushstring(L, formname.c_str());
// param 3
lua_newtable(L);
- for(std::map<std::string, std::string>::const_iterator
- i = fields.begin(); i != fields.end(); i++){
- const std::string &name = i->first;
- const std::string &value = i->second;
+ StringMap::const_iterator it;
+ for (it = fields.begin(); it != fields.end(); ++it) {
+ const std::string &name = it->first;
+ const std::string &value = it->second;
lua_pushstring(L, name.c_str());
lua_pushlstring(L, value.c_str(), value.size());
lua_settable(L, -3);
}
script_run_callbacks(L, 3, RUN_CALLBACKS_MODE_OR_SC);
}
-ScriptApiPlayer::~ScriptApiPlayer() {
+
+ScriptApiPlayer::~ScriptApiPlayer()
+{
}
diff --git a/src/script/cpp_api/s_player.h b/src/script/cpp_api/s_player.h
index a0f764cd5..9c8d1d1ad 100644
--- a/src/script/cpp_api/s_player.h
+++ b/src/script/cpp_api/s_player.h
@@ -20,10 +20,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#ifndef S_PLAYER_H_
#define S_PLAYER_H_
-#include <map>
-
#include "cpp_api/s_base.h"
#include "irr_v3d.h"
+#include "util/string.h"
struct ToolCapabilities;
@@ -36,17 +35,16 @@ public:
void on_newplayer(ServerActiveObject *player);
void on_dieplayer(ServerActiveObject *player);
bool on_respawnplayer(ServerActiveObject *player);
- bool on_prejoinplayer(std::string name, std::string ip, std::string &reason);
+ bool on_prejoinplayer(const std::string &name, const std::string &ip,
+ std::string *reason);
void on_joinplayer(ServerActiveObject *player);
void on_leaveplayer(ServerActiveObject *player);
void on_cheat(ServerActiveObject *player, const std::string &cheat_type);
bool on_punchplayer(ServerActiveObject *player,
ServerActiveObject *hitter, float time_from_last_punch,
const ToolCapabilities *toolcap, v3f dir, s16 damage);
-
void on_playerReceiveFields(ServerActiveObject *player,
- const std::string &formname,
- const std::map<std::string, std::string> &fields);
+ const std::string &formname, const StringMap &fields);
};
diff --git a/src/script/lua_api/l_nodemeta.cpp b/src/script/lua_api/l_nodemeta.cpp
index 906cc3172..6cdbe5c68 100644
--- a/src/script/lua_api/l_nodemeta.cpp
+++ b/src/script/lua_api/l_nodemeta.cpp
@@ -190,32 +190,34 @@ int NodeMetaRef::l_to_table(lua_State *L)
NodeMetaRef *ref = checkobject(L, 1);
NodeMetadata *meta = getmeta(ref, true);
- if(meta == NULL){
+ if (meta == NULL) {
lua_pushnil(L);
return 1;
}
lua_newtable(L);
+
// fields
lua_newtable(L);
{
- std::map<std::string, std::string> fields = meta->getStrings();
- for(std::map<std::string, std::string>::const_iterator
- i = fields.begin(); i != fields.end(); i++){
- const std::string &name = i->first;
- const std::string &value = i->second;
+ 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;
lua_pushlstring(L, name.c_str(), name.size());
lua_pushlstring(L, value.c_str(), value.size());
lua_settable(L, -3);
}
}
lua_setfield(L, -2, "fields");
+
// inventory
lua_newtable(L);
Inventory *inv = meta->getInventory();
- if(inv){
- std::vector<const InventoryList*> lists = inv->getLists();
- for(std::vector<const InventoryList*>::const_iterator
- i = lists.begin(); i != lists.end(); i++){
+ if (inv) {
+ std::vector<const InventoryList *> lists = inv->getLists();
+ for(std::vector<const InventoryList *>::const_iterator
+ i = lists.begin(); i != lists.end(); i++) {
push_inventory_list(L, inv, (*i)->getName().c_str());
lua_setfield(L, -2, (*i)->getName().c_str());
}