mirror of
https://github.com/cuberite/cuberite.git
synced 2025-01-08 11:57:39 +08:00
Added tiny PoC to create new luastate in a different thread.
This commit is contained in:
parent
834d61dacc
commit
92fac6b5b4
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user