From 92fac6b5b47764031a8a163cce29cafacff158f4 Mon Sep 17 00:00:00 2001 From: NiLSPACE Date: Tue, 22 Sep 2020 15:23:49 +0200 Subject: Added tiny PoC to create new luastate in a different thread. --- src/Bindings/ManualBindings.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src') diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 7f7cb8ea9..a23b67688 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -1777,6 +1777,34 @@ static int tolua_cPluginLua_AddWebTab(lua_State * tolua_S) +static int tolua_cPluginLua_ExecuteOffThread(lua_State * tolua_S) +{ + cLuaState own = cLuaState(tolua_S); + AString luaCode; + if (!own.GetStackValue(2, luaCode)) + { + LOGWARNING("Expected string with Lua code."); + return 0; + } + + auto callback = [luaCode]() { + cLuaState state = cLuaState("Testing"); + state.Create(); + state.RegisterAPILibs(); + state.LoadStringW(luaCode, ""); + }; + + std::thread thread = std::thread(callback); + thread.detach(); + own.Push(true); + + return 1; +} + + + + + static int tolua_cPlugin_GetDirectory(lua_State * tolua_S) { cLuaState L(tolua_S); -- cgit v1.2.3