summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNiels Breuker <niels.breuker@hotmail.nl>2022-10-02 12:58:42 +0200
committerNiels Breuker <niels.breuker@hotmail.nl>2022-10-02 12:58:42 +0200
commit3fa47b4c8df3dedc20f04cf04edab9de408bbd1b (patch)
tree27c2992031a7c134a959ac30d6654d168054aa4c
parentFirst PoC for multithreading in plugins. (diff)
downloadcuberite-threading.tar
cuberite-threading.tar.gz
cuberite-threading.tar.bz2
cuberite-threading.tar.lz
cuberite-threading.tar.xz
cuberite-threading.tar.zst
cuberite-threading.zip
-rw-r--r--Server/Plugins/.gitignore1
-rw-r--r--Server/Plugins/MultiThreadTest/init.lua40
2 files changed, 41 insertions, 0 deletions
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