summaryrefslogtreecommitdiff
path: root/src/script/api
diff options
context:
space:
mode:
authorrubidium42 <rubidium@openttd.org>2021-05-14 17:33:29 +0200
committerrubidium42 <rubidium42@users.noreply.github.com>2021-05-30 10:15:22 +0200
commite58581f1f825da4d318b0b09fc12726788e95ccc (patch)
tree9d99b3939df44d3afd43fde4ac396095af5bf617 /src/script/api
parent29f2bd27c44ef51f8af1299cf16012a4fa89cc61 (diff)
downloadopenttd-e58581f1f825da4d318b0b09fc12726788e95ccc.tar.xz
Codechange: [Network] Let admin-game script use std::string
Diffstat (limited to 'src/script/api')
-rw-r--r--src/script/api/script_admin.cpp2
-rw-r--r--src/script/api/script_event_types.cpp14
-rw-r--r--src/script/api/script_event_types.hpp5
3 files changed, 8 insertions, 13 deletions
diff --git a/src/script/api/script_admin.cpp b/src/script/api/script_admin.cpp
index 8f7371266..24aa0bcaf 100644
--- a/src/script/api/script_admin.cpp
+++ b/src/script/api/script_admin.cpp
@@ -139,7 +139,7 @@
return 1;
}
- NetworkAdminGameScript(json.c_str());
+ NetworkAdminGameScript(json);
sq_pushinteger(vm, 1);
return 1;
diff --git a/src/script/api/script_event_types.cpp b/src/script/api/script_event_types.cpp
index 84d6d99cd..3cc5287eb 100644
--- a/src/script/api/script_event_types.cpp
+++ b/src/script/api/script_event_types.cpp
@@ -118,23 +118,18 @@ bool ScriptEventCompanyAskMerger::AcceptMerger()
return ScriptObject::DoCommand(0, this->owner, 0, CMD_BUY_COMPANY);
}
-ScriptEventAdminPort::ScriptEventAdminPort(const char *json) :
+ScriptEventAdminPort::ScriptEventAdminPort(const std::string &json) :
ScriptEvent(ET_ADMIN_PORT),
- json(stredup(json))
+ json(json)
{
}
-ScriptEventAdminPort::~ScriptEventAdminPort()
-{
- free(this->json);
-}
-
#define SKIP_EMPTY(p) while (*(p) == ' ' || *(p) == '\n' || *(p) == '\r') (p)++;
#define RETURN_ERROR(stack) { ScriptLog::Error("Received invalid JSON data from AdminPort."); if (stack != 0) sq_pop(vm, stack); return nullptr; }
SQInteger ScriptEventAdminPort::GetObject(HSQUIRRELVM vm)
{
- const char *p = this->json;
+ const char *p = this->json.c_str();
if (this->ReadTable(vm, p) == nullptr) {
sq_pushnull(vm);
@@ -168,7 +163,8 @@ const char *ScriptEventAdminPort::ReadString(HSQUIRRELVM vm, const char *p)
p++;
}
- sq_pushstring(vm, value, p - value);
+ size_t len = p - value;
+ sq_pushstring(vm, value, len);
p++; // Step past the end-of-string marker (")
return p;
diff --git a/src/script/api/script_event_types.hpp b/src/script/api/script_event_types.hpp
index b6ed7bfbc..3ed6c5b10 100644
--- a/src/script/api/script_event_types.hpp
+++ b/src/script/api/script_event_types.hpp
@@ -837,8 +837,7 @@ public:
/**
* @param json The JSON string which got sent.
*/
- ScriptEventAdminPort(const char *json);
- ~ScriptEventAdminPort();
+ ScriptEventAdminPort(const std::string &json);
/**
* Convert an ScriptEvent to the real instance.
@@ -853,7 +852,7 @@ public:
SQInteger GetObject(HSQUIRRELVM vm);
private:
- char *json; ///< The JSON string.
+ std::string json; ///< The JSON string.
/**
* Read a table from a JSON string.