Skip to content

Commit 6a1424f

Browse files
authoredAug 28, 2021
Async-related script cleanups
1 parent 0f8a6d7 commit 6a1424f

15 files changed

+135
-156
lines changed
 

‎builtin/async/init.lua

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11

22
core.log("info", "Initializing Asynchronous environment")
33

4-
function core.job_processor(serialized_func, serialized_param)
5-
local func = loadstring(serialized_func)
4+
function core.job_processor(func, serialized_param)
65
local param = core.deserialize(serialized_param)
7-
local retval = nil
86

9-
if type(func) == "function" then
10-
retval = core.serialize(func(param))
11-
else
12-
core.log("error", "ASYNC WORKER: Unable to deserialize function")
13-
end
7+
local retval = core.serialize(func(param))
148

159
return retval or core.serialize(nil)
1610
end

‎src/gui/guiEngine.cpp

-7
Original file line numberDiff line numberDiff line change
@@ -614,10 +614,3 @@ void GUIEngine::stopSound(s32 handle)
614614
{
615615
m_sound_manager->stopSound(handle);
616616
}
617-
618-
/******************************************************************************/
619-
unsigned int GUIEngine::queueAsync(const std::string &serialized_func,
620-
const std::string &serialized_params)
621-
{
622-
return m_script->queueAsync(serialized_func, serialized_params);
623-
}

‎src/gui/guiEngine.h

-4
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,6 @@ class GUIEngine {
175175
return m_scriptdir;
176176
}
177177

178-
/** pass async callback to scriptengine **/
179-
unsigned int queueAsync(const std::string &serialized_fct,
180-
const std::string &serialized_params);
181-
182178
private:
183179

184180
/** find and run the main menu script */

‎src/script/cpp_api/s_async.cpp

+56-52
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,19 @@ extern "C" {
3232
#include "filesys.h"
3333
#include "porting.h"
3434
#include "common/c_internal.h"
35+
#include "lua_api/l_base.h"
3536

3637
/******************************************************************************/
3738
AsyncEngine::~AsyncEngine()
3839
{
39-
4040
// Request all threads to stop
4141
for (AsyncWorkerThread *workerThread : workerThreads) {
4242
workerThread->stop();
4343
}
4444

45-
4645
// Wake up all threads
47-
for (std::vector<AsyncWorkerThread *>::iterator it = workerThreads.begin();
48-
it != workerThreads.end(); ++it) {
46+
for (auto it : workerThreads) {
47+
(void)it;
4948
jobQueueCounter.post();
5049
}
5150

@@ -68,6 +67,7 @@ AsyncEngine::~AsyncEngine()
6867
/******************************************************************************/
6968
void AsyncEngine::registerStateInitializer(StateInitializer func)
7069
{
70+
FATAL_ERROR_IF(initDone, "Initializer may not be registered after init");
7171
stateInitializers.push_back(func);
7272
}
7373

@@ -85,47 +85,47 @@ void AsyncEngine::initialize(unsigned int numEngines)
8585
}
8686

8787
/******************************************************************************/
88-
unsigned int AsyncEngine::queueAsyncJob(const std::string &func,
89-
const std::string &params)
88+
u32 AsyncEngine::queueAsyncJob(std::string &&func, std::string &&params,
89+
const std::string &mod_origin)
9090
{
9191
jobQueueMutex.lock();
92-
LuaJobInfo toAdd;
93-
toAdd.id = jobIdCounter++;
94-
toAdd.serializedFunction = func;
95-
toAdd.serializedParams = params;
92+
u32 jobId = jobIdCounter++;
9693

97-
jobQueue.push_back(toAdd);
94+
jobQueue.emplace_back();
95+
auto &to_add = jobQueue.back();
96+
to_add.id = jobId;
97+
to_add.function = std::move(func);
98+
to_add.params = std::move(params);
99+
to_add.mod_origin = mod_origin;
98100

99101
jobQueueCounter.post();
100-
101102
jobQueueMutex.unlock();
102-
103-
return toAdd.id;
103+
return jobId;
104104
}
105105

106106
/******************************************************************************/
107-
LuaJobInfo AsyncEngine::getJob()
107+
bool AsyncEngine::getJob(LuaJobInfo *job)
108108
{
109109
jobQueueCounter.wait();
110110
jobQueueMutex.lock();
111111

112-
LuaJobInfo retval;
112+
bool retval = false;
113113

114114
if (!jobQueue.empty()) {
115-
retval = jobQueue.front();
115+
*job = std::move(jobQueue.front());
116116
jobQueue.pop_front();
117-
retval.valid = true;
117+
retval = true;
118118
}
119119
jobQueueMutex.unlock();
120120

121121
return retval;
122122
}
123123

124124
/******************************************************************************/
125-
void AsyncEngine::putJobResult(const LuaJobInfo &result)
125+
void AsyncEngine::putJobResult(LuaJobInfo &&result)
126126
{
127127
resultQueueMutex.lock();
128-
resultQueue.push_back(result);
128+
resultQueue.emplace_back(std::move(result));
129129
resultQueueMutex.unlock();
130130
}
131131

@@ -134,26 +134,30 @@ void AsyncEngine::step(lua_State *L)
134134
{
135135
int error_handler = PUSH_ERROR_HANDLER(L);
136136
lua_getglobal(L, "core");
137-
resultQueueMutex.lock();
137+
138+
ScriptApiBase *script = ModApiBase::getScriptApiBase(L);
139+
140+
MutexAutoLock autolock(resultQueueMutex);
138141
while (!resultQueue.empty()) {
139-
LuaJobInfo jobDone = resultQueue.front();
142+
LuaJobInfo j = std::move(resultQueue.front());
140143
resultQueue.pop_front();
141144

142145
lua_getfield(L, -1, "async_event_handler");
143-
144-
if (lua_isnil(L, -1)) {
146+
if (lua_isnil(L, -1))
145147
FATAL_ERROR("Async event handler does not exist!");
146-
}
147-
148148
luaL_checktype(L, -1, LUA_TFUNCTION);
149149

150-
lua_pushinteger(L, jobDone.id);
151-
lua_pushlstring(L, jobDone.serializedResult.data(),
152-
jobDone.serializedResult.size());
150+
lua_pushinteger(L, j.id);
151+
lua_pushlstring(L, j.result.data(), j.result.size());
153152

154-
PCALL_RESL(L, lua_pcall(L, 2, 0, error_handler));
153+
// Call handler
154+
const char *origin = j.mod_origin.empty() ? nullptr : j.mod_origin.c_str();
155+
script->setOriginDirect(origin);
156+
int result = lua_pcall(L, 2, 0, error_handler);
157+
if (result)
158+
script_error(L, result, origin, "<async>");
155159
}
156-
resultQueueMutex.unlock();
160+
157161
lua_pop(L, 2); // Pop core and error handler
158162
}
159163

@@ -168,8 +172,8 @@ void AsyncEngine::prepareEnvironment(lua_State* L, int top)
168172
/******************************************************************************/
169173
AsyncWorkerThread::AsyncWorkerThread(AsyncEngine* jobDispatcher,
170174
const std::string &name) :
171-
Thread(name),
172175
ScriptApiBase(ScriptingType::Async),
176+
Thread(name),
173177
jobDispatcher(jobDispatcher)
174178
{
175179
lua_State *L = getStack();
@@ -196,9 +200,9 @@ void* AsyncWorkerThread::run()
196200
{
197201
lua_State *L = getStack();
198202

199-
std::string script = getServer()->getBuiltinLuaPath() + DIR_DELIM + "init.lua";
200203
try {
201-
loadScript(script);
204+
loadMod(getServer()->getBuiltinLuaPath() + DIR_DELIM + "init.lua",
205+
BUILTIN_MOD_NAME);
202206
} catch (const ModError &e) {
203207
errorstream << "Execution of async base environment failed: "
204208
<< e.what() << std::endl;
@@ -213,44 +217,44 @@ void* AsyncWorkerThread::run()
213217
}
214218

215219
// Main loop
220+
LuaJobInfo j;
216221
while (!stopRequested()) {
217222
// Wait for job
218-
LuaJobInfo toProcess = jobDispatcher->getJob();
219-
220-
if (!toProcess.valid || stopRequested()) {
223+
if (!jobDispatcher->getJob(&j) || stopRequested())
221224
continue;
222-
}
223225

224226
lua_getfield(L, -1, "job_processor");
225-
if (lua_isnil(L, -1)) {
227+
if (lua_isnil(L, -1))
226228
FATAL_ERROR("Unable to get async job processor!");
227-
}
228-
229229
luaL_checktype(L, -1, LUA_TFUNCTION);
230230

231-
// Call it
232-
lua_pushlstring(L,
233-
toProcess.serializedFunction.data(),
234-
toProcess.serializedFunction.size());
235-
lua_pushlstring(L,
236-
toProcess.serializedParams.data(),
237-
toProcess.serializedParams.size());
231+
if (luaL_loadbuffer(L, j.function.data(), j.function.size(), "=(async)")) {
232+
errorstream << "ASYNC WORKER: Unable to deserialize function" << std::endl;
233+
lua_pushnil(L);
234+
}
235+
lua_pushlstring(L, j.params.data(), j.params.size());
238236

237+
// Call it
238+
setOriginDirect(j.mod_origin.empty() ? nullptr : j.mod_origin.c_str());
239239
int result = lua_pcall(L, 2, 1, error_handler);
240240
if (result) {
241-
PCALL_RES(result);
242-
toProcess.serializedResult = "";
241+
try {
242+
scriptError(result, "<async>");
243+
} catch (const ModError &e) {
244+
errorstream << e.what() << std::endl;
245+
}
243246
} else {
244247
// Fetch result
245248
size_t length;
246249
const char *retval = lua_tolstring(L, -1, &length);
247-
toProcess.serializedResult = std::string(retval, length);
250+
j.result.assign(retval, length);
248251
}
249252

250253
lua_pop(L, 1); // Pop retval
251254

252255
// Put job result
253-
jobDispatcher->putJobResult(toProcess);
256+
if (!j.result.empty())
257+
jobDispatcher->putJobResult(std::move(j));
254258
}
255259

256260
lua_pop(L, 2); // Pop core and error handler

‎src/script/cpp_api/s_async.h

+21-18
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2121

2222
#include <vector>
2323
#include <deque>
24-
#include <map>
2524

2625
#include "threading/semaphore.h"
2726
#include "threading/thread.h"
@@ -39,26 +38,29 @@ struct LuaJobInfo
3938
{
4039
LuaJobInfo() = default;
4140

42-
// Function to be called in async environment
43-
std::string serializedFunction = "";
44-
// Parameter to be passed to function
45-
std::string serializedParams = "";
46-
// Result of function call
47-
std::string serializedResult = "";
41+
// Function to be called in async environment (from string.dump)
42+
std::string function;
43+
// Parameter to be passed to function (serialized)
44+
std::string params;
45+
// Result of function call (serialized)
46+
std::string result;
47+
// Name of the mod who invoked this call
48+
std::string mod_origin;
4849
// JobID used to identify a job and match it to callback
49-
unsigned int id = 0;
50-
51-
bool valid = false;
50+
u32 id;
5251
};
5352

5453
// Asynchronous working environment
55-
class AsyncWorkerThread : public Thread, public ScriptApiBase {
54+
class AsyncWorkerThread : public Thread, virtual public ScriptApiBase {
55+
friend class AsyncEngine;
5656
public:
57-
AsyncWorkerThread(AsyncEngine* jobDispatcher, const std::string &name);
5857
virtual ~AsyncWorkerThread();
5958

6059
void *run();
6160

61+
protected:
62+
AsyncWorkerThread(AsyncEngine* jobDispatcher, const std::string &name);
63+
6264
private:
6365
AsyncEngine *jobDispatcher = nullptr;
6466
};
@@ -89,7 +91,8 @@ class AsyncEngine {
8991
* @param params Serialized parameters
9092
* @return jobid The job is queued
9193
*/
92-
unsigned int queueAsyncJob(const std::string &func, const std::string &params);
94+
u32 queueAsyncJob(std::string &&func, std::string &&params,
95+
const std::string &mod_origin = "");
9396

9497
/**
9598
* Engine step to process finished jobs
@@ -102,15 +105,16 @@ class AsyncEngine {
102105
/**
103106
* Get a Job from queue to be processed
104107
* this function blocks until a job is ready
105-
* @return a job to be processed
108+
* @param job a job to be processed
109+
* @return whether a job was available
106110
*/
107-
LuaJobInfo getJob();
111+
bool getJob(LuaJobInfo *job);
108112

109113
/**
110114
* Put a Job result back to result queue
111115
* @param result result of completed job
112116
*/
113-
void putJobResult(const LuaJobInfo &result);
117+
void putJobResult(LuaJobInfo &&result);
114118

115119
/**
116120
* Initialize environment with current registred functions
@@ -129,11 +133,10 @@ class AsyncEngine {
129133
std::vector<StateInitializer> stateInitializers;
130134

131135
// Internal counter to create job IDs
132-
unsigned int jobIdCounter = 0;
136+
u32 jobIdCounter = 0;
133137

134138
// Mutex to protect job queue
135139
std::mutex jobQueueMutex;
136-
137140
// Job queue
138141
std::deque<LuaJobInfo> jobQueue;
139142

‎src/script/cpp_api/s_base.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -331,13 +331,9 @@ void ScriptApiBase::setOriginDirect(const char *origin)
331331

332332
void ScriptApiBase::setOriginFromTableRaw(int index, const char *fxn)
333333
{
334-
#ifdef SCRIPTAPI_DEBUG
335334
lua_State *L = getStack();
336-
337335
m_last_run_mod = lua_istable(L, index) ?
338336
getstringfield_default(L, index, "mod_origin", "") : "";
339-
//printf(">>>> running %s for mod: %s\n", fxn, m_last_run_mod.c_str());
340-
#endif
341337
}
342338

343339
/*

‎src/script/cpp_api/s_base.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ extern "C" {
3939
#include "config.h"
4040

4141
#define SCRIPTAPI_LOCK_DEBUG
42-
#define SCRIPTAPI_DEBUG
4342

4443
// MUST be an invalid mod name so that mods can't
4544
// use that name to bypass security!
@@ -108,7 +107,9 @@ class ScriptApiBase : protected LuaHelper {
108107
Client* getClient();
109108
#endif
110109

111-
std::string getOrigin() { return m_last_run_mod; }
110+
// IMPORTANT: these cannot be used for any security-related uses, they exist
111+
// only to enrich error messages
112+
const std::string &getOrigin() { return m_last_run_mod; }
112113
void setOriginDirect(const char *origin);
113114
void setOriginFromTableRaw(int index, const char *fxn);
114115

‎src/script/cpp_api/s_security.cpp

+4-17
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
1818
*/
1919

2020
#include "cpp_api/s_security.h"
21-
21+
#include "lua_api/l_base.h"
2222
#include "filesys.h"
2323
#include "porting.h"
2424
#include "server.h"
@@ -538,15 +538,8 @@ bool ScriptApiSecurity::checkPath(lua_State *L, const char *path,
538538
if (!removed.empty())
539539
abs_path += DIR_DELIM + removed;
540540

541-
// Get server from registry
542-
lua_rawgeti(L, LUA_REGISTRYINDEX, CUSTOM_RIDX_SCRIPTAPI);
543-
ScriptApiBase *script;
544-
#if INDIRECT_SCRIPTAPI_RIDX
545-
script = (ScriptApiBase *) *(void**)(lua_touserdata(L, -1));
546-
#else
547-
script = (ScriptApiBase *) lua_touserdata(L, -1);
548-
#endif
549-
lua_pop(L, 1);
541+
// Get gamedef from registry
542+
ScriptApiBase *script = ModApiBase::getScriptApiBase(L);
550543
const IGameDef *gamedef = script->getGameDef();
551544
if (!gamedef)
552545
return false;
@@ -669,13 +662,7 @@ int ScriptApiSecurity::sl_g_load(lua_State *L)
669662
int ScriptApiSecurity::sl_g_loadfile(lua_State *L)
670663
{
671664
#ifndef SERVER
672-
lua_rawgeti(L, LUA_REGISTRYINDEX, CUSTOM_RIDX_SCRIPTAPI);
673-
#if INDIRECT_SCRIPTAPI_RIDX
674-
ScriptApiBase *script = (ScriptApiBase *) *(void**)(lua_touserdata(L, -1));
675-
#else
676-
ScriptApiBase *script = (ScriptApiBase *) lua_touserdata(L, -1);
677-
#endif
678-
lua_pop(L, 1);
665+
ScriptApiBase *script = ModApiBase::getScriptApiBase(L);
679666

680667
// Client implementation
681668
if (script->getType() == ScriptingType::Client) {

‎src/script/lua_api/l_mainmenu.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2121
#include "lua_api/l_internal.h"
2222
#include "common/c_content.h"
2323
#include "cpp_api/s_async.h"
24+
#include "scripting_mainmenu.h"
2425
#include "gui/guiEngine.h"
2526
#include "gui/guiMainMenu.h"
2627
#include "gui/guiKeyChangeMenu.h"
@@ -816,20 +817,20 @@ int ModApiMainMenu::l_open_dir(lua_State *L)
816817
/******************************************************************************/
817818
int ModApiMainMenu::l_do_async_callback(lua_State *L)
818819
{
819-
GUIEngine* engine = getGuiEngine(L);
820+
MainMenuScripting *script = getScriptApi<MainMenuScripting>(L);
820821

821822
size_t func_length, param_length;
822823
const char* serialized_func_raw = luaL_checklstring(L, 1, &func_length);
823-
824824
const char* serialized_param_raw = luaL_checklstring(L, 2, &param_length);
825825

826826
sanity_check(serialized_func_raw != NULL);
827827
sanity_check(serialized_param_raw != NULL);
828828

829-
std::string serialized_func = std::string(serialized_func_raw, func_length);
830-
std::string serialized_param = std::string(serialized_param_raw, param_length);
829+
u32 jobId = script->queueAsync(
830+
std::string(serialized_func_raw, func_length),
831+
std::string(serialized_param_raw, param_length));
831832

832-
lua_pushinteger(L, engine->queueAsync(serialized_func, serialized_param));
833+
lua_pushinteger(L, jobId);
833834

834835
return 1;
835836
}

‎src/script/lua_api/l_server.cpp

+1-28
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2323
#include "common/c_content.h"
2424
#include "cpp_api/s_base.h"
2525
#include "cpp_api/s_security.h"
26+
#include "scripting_server.h"
2627
#include "server.h"
2728
#include "environment.h"
2829
#include "remoteplayer.h"
@@ -498,31 +499,6 @@ int ModApiServer::l_notify_authentication_modified(lua_State *L)
498499
return 0;
499500
}
500501

501-
// get_last_run_mod()
502-
int ModApiServer::l_get_last_run_mod(lua_State *L)
503-
{
504-
NO_MAP_LOCK_REQUIRED;
505-
lua_rawgeti(L, LUA_REGISTRYINDEX, CUSTOM_RIDX_CURRENT_MOD_NAME);
506-
std::string current_mod = readParam<std::string>(L, -1, "");
507-
if (current_mod.empty()) {
508-
lua_pop(L, 1);
509-
lua_pushstring(L, getScriptApiBase(L)->getOrigin().c_str());
510-
}
511-
return 1;
512-
}
513-
514-
// set_last_run_mod(modname)
515-
int ModApiServer::l_set_last_run_mod(lua_State *L)
516-
{
517-
NO_MAP_LOCK_REQUIRED;
518-
#ifdef SCRIPTAPI_DEBUG
519-
const char *mod = lua_tostring(L, 1);
520-
getScriptApiBase(L)->setOriginDirect(mod);
521-
//printf(">>>> last mod set from Lua: %s\n", mod);
522-
#endif
523-
return 0;
524-
}
525-
526502
void ModApiServer::Initialize(lua_State *L, int top)
527503
{
528504
API_FCT(request_shutdown);
@@ -555,7 +531,4 @@ void ModApiServer::Initialize(lua_State *L, int top)
555531
API_FCT(remove_player);
556532
API_FCT(unban_player_or_ip);
557533
API_FCT(notify_authentication_modified);
558-
559-
API_FCT(get_last_run_mod);
560-
API_FCT(set_last_run_mod);
561534
}

‎src/script/lua_api/l_server.h

-6
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,6 @@ class ModApiServer : public ModApiBase
103103
// notify_authentication_modified(name)
104104
static int l_notify_authentication_modified(lua_State *L);
105105

106-
// get_last_run_mod()
107-
static int l_get_last_run_mod(lua_State *L);
108-
109-
// set_last_run_mod(modname)
110-
static int l_set_last_run_mod(lua_State *L);
111-
112106
public:
113107
static void Initialize(lua_State *L, int top);
114108
};

‎src/script/lua_api/l_util.cpp

+30
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,30 @@ int ModApiUtil::l_encode_png(lua_State *L)
535535
return 1;
536536
}
537537

538+
// get_last_run_mod()
539+
int ModApiUtil::l_get_last_run_mod(lua_State *L)
540+
{
541+
NO_MAP_LOCK_REQUIRED;
542+
543+
lua_rawgeti(L, LUA_REGISTRYINDEX, CUSTOM_RIDX_CURRENT_MOD_NAME);
544+
std::string current_mod = readParam<std::string>(L, -1, "");
545+
if (current_mod.empty()) {
546+
lua_pop(L, 1);
547+
lua_pushstring(L, getScriptApiBase(L)->getOrigin().c_str());
548+
}
549+
return 1;
550+
}
551+
552+
// set_last_run_mod(modname)
553+
int ModApiUtil::l_set_last_run_mod(lua_State *L)
554+
{
555+
NO_MAP_LOCK_REQUIRED;
556+
557+
const char *mod = luaL_checkstring(L, 1);
558+
getScriptApiBase(L)->setOriginDirect(mod);
559+
return 0;
560+
}
561+
538562
void ModApiUtil::Initialize(lua_State *L, int top)
539563
{
540564
API_FCT(log);
@@ -574,6 +598,9 @@ void ModApiUtil::Initialize(lua_State *L, int top)
574598

575599
API_FCT(encode_png);
576600

601+
API_FCT(get_last_run_mod);
602+
API_FCT(set_last_run_mod);
603+
577604
LuaSettings::create(L, g_settings, g_settings_path);
578605
lua_setfield(L, top, "settings");
579606
}
@@ -629,6 +656,9 @@ void ModApiUtil::InitializeAsync(lua_State *L, int top)
629656
API_FCT(colorspec_to_colorstring);
630657
API_FCT(colorspec_to_bytes);
631658

659+
API_FCT(get_last_run_mod);
660+
API_FCT(set_last_run_mod);
661+
632662
LuaSettings::create(L, g_settings, g_settings_path);
633663
lua_setfield(L, top, "settings");
634664
}

‎src/script/lua_api/l_util.h

+6
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ class ModApiUtil : public ModApiBase
110110
// encode_png(w, h, data, level)
111111
static int l_encode_png(lua_State *L);
112112

113+
// get_last_run_mod()
114+
static int l_get_last_run_mod(lua_State *L);
115+
116+
// set_last_run_mod(modname)
117+
static int l_set_last_run_mod(lua_State *L);
118+
113119
public:
114120
static void Initialize(lua_State *L, int top);
115121
static void InitializeAsync(lua_State *L, int top);

‎src/script/scripting_mainmenu.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ void MainMenuScripting::step()
9292
}
9393

9494
/******************************************************************************/
95-
unsigned int MainMenuScripting::queueAsync(const std::string &serialized_func,
96-
const std::string &serialized_param)
95+
u32 MainMenuScripting::queueAsync(std::string &&serialized_func,
96+
std::string &&serialized_param)
9797
{
98-
return asyncEngine.queueAsyncJob(serialized_func, serialized_param);
98+
return asyncEngine.queueAsyncJob(std::move(serialized_func), std::move(serialized_param));
9999
}
100100

‎src/script/scripting_mainmenu.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ class MainMenuScripting
3838
void step();
3939

4040
// Pass async events from engine to async threads
41-
unsigned int queueAsync(const std::string &serialized_func,
42-
const std::string &serialized_params);
41+
u32 queueAsync(std::string &&serialized_func,
42+
std::string &&serialized_param);
43+
4344
private:
4445
void initializeModApi(lua_State *L, int top);
4546
static void registerLuaClasses(lua_State *L, int top);

0 commit comments

Comments
 (0)
Please sign in to comment.