From 3e85e833a707e6b781d00eae09c9465bacbf1d69 Mon Sep 17 00:00:00 2001 From: Michael Lutz Date: Tue, 30 Nov 2021 00:52:23 +0100 Subject: Codechange: Add support for additional command result values. --- src/script/api/script_object.cpp | 10 ++++++++++ src/script/api/script_object.hpp | 36 ++++++++++++++++++++++++++++++------ src/script/script_instance.cpp | 3 ++- src/script/script_instance.hpp | 3 ++- src/script/script_storage.hpp | 1 + 5 files changed, 45 insertions(+), 8 deletions(-) (limited to 'src/script') diff --git a/src/script/api/script_object.cpp b/src/script/api/script_object.cpp index ff109dbdf..dad79309a 100644 --- a/src/script/api/script_object.cpp +++ b/src/script/api/script_object.cpp @@ -173,6 +173,16 @@ ScriptObject::ActiveInstance::~ActiveInstance() return GetStorage()->last_command_res; } +/* static */ void ScriptObject::SetLastCommandResData(CommandDataBuffer data) +{ + GetStorage()->last_cmd_ret = std::move(data); +} + +/* static */ const CommandDataBuffer &ScriptObject::GetLastCommandResData() +{ + return GetStorage()->last_cmd_ret; +} + /* static */ void ScriptObject::SetNewVehicleID(VehicleID vehicle_id) { GetStorage()->new_vehicle_id = vehicle_id; diff --git a/src/script/api/script_object.hpp b/src/script/api/script_object.hpp index 11d9542c8..f9a66f8a8 100644 --- a/src/script/api/script_object.hpp +++ b/src/script/api/script_object.hpp @@ -61,6 +61,12 @@ public: */ static void SetLastCommandRes(bool res); + /** + * Store the extra data return by the last DoCommand. + * @param data Extra data return by the command. + */ + static void SetLastCommandResData(CommandDataBuffer data); + /** * Get the currently active instance. * @return The instance. @@ -74,10 +80,11 @@ protected: * Templated wrapper that exposes the command parameter arguments * on the various DoCommand calls. * @tparam Tcmd The command-id to execute. + * @tparam Tret Return type of the command. * @tparam Targs The command parameter types. */ - template - struct ScriptDoCommandHelper { + template + struct ScriptDoCommandHelper { static bool Do(Script_SuspendCallbackProc *callback, Targs... args) { return Execute(callback, std::forward_as_tuple(args...)); @@ -180,6 +187,11 @@ protected: */ static bool GetLastCommandRes(); + /** + * Get the extra return data from the last DoCommand. + */ + static const CommandDataBuffer &GetLastCommandResData(); + /** * Get the latest stored new_vehicle_id. */ @@ -363,10 +375,17 @@ namespace ScriptObjectInternal { { ((SetClientIdHelper(std::get(values))), ...); } + + /** Remove the first element of a tuple. */ + template