summaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
Diffstat (limited to 'src/script')
-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.