From 3fa47b4c8df3dedc20f04cf04edab9de408bbd1b Mon Sep 17 00:00:00 2001 From: Niels Breuker Date: Sun, 2 Oct 2022 12:58:42 +0200 Subject: Added small plugin to show multithreading --- Server/Plugins/.gitignore | 1 + Server/Plugins/MultiThreadTest/init.lua | 40 +++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 Server/Plugins/MultiThreadTest/init.lua diff --git a/Server/Plugins/.gitignore b/Server/Plugins/.gitignore index 99844d3a0..b742adb70 100644 --- a/Server/Plugins/.gitignore +++ b/Server/Plugins/.gitignore @@ -5,3 +5,4 @@ !/HookNotify !/NetworkTest !/TestLuaRocks +!/MultiThreadTest \ No newline at end of file diff --git a/Server/Plugins/MultiThreadTest/init.lua b/Server/Plugins/MultiThreadTest/init.lua new file mode 100644 index 000000000..f2c4fe6d5 --- /dev/null +++ b/Server/Plugins/MultiThreadTest/init.lua @@ -0,0 +1,40 @@ + + +local PLUGIN_NAME = "MultiThreadTest"; + + + +function Initialize(a_Plugin) + a_Plugin:SetName(PLUGIN_NAME) + cPluginManager:BindConsoleCommand("startthread", HandleStartThreadCommand, ""); + LOG("Initialized"); + + return true; +end + + + + +function Callback() + cRoot:Get():GetDefaultWorld():QueueTask(function() + print("From world thread"); + end); +end + + + + +function HandleStartThreadCommand(a_Split) + cThread.new(function() + print("Test"); + for i = 1, 5 do + cThread.sleep(1); + print("Testing", i); + + end + -- Really ugly way to return to the default lua_State + cPluginManager:CallPlugin(PLUGIN_NAME, "Callback"); + end) + + return true; +end -- cgit v1.2.3