diff options
author | Niels Breuker <niels.breuker@hotmail.nl> | 2022-10-02 12:58:42 +0200 |
---|---|---|
committer | Niels Breuker <niels.breuker@hotmail.nl> | 2022-10-02 12:58:42 +0200 |
commit | 3fa47b4c8df3dedc20f04cf04edab9de408bbd1b (patch) | |
tree | 27c2992031a7c134a959ac30d6654d168054aa4c | |
parent | First PoC for multithreading in plugins. (diff) | |
download | cuberite-3fa47b4c8df3dedc20f04cf04edab9de408bbd1b.tar cuberite-3fa47b4c8df3dedc20f04cf04edab9de408bbd1b.tar.gz cuberite-3fa47b4c8df3dedc20f04cf04edab9de408bbd1b.tar.bz2 cuberite-3fa47b4c8df3dedc20f04cf04edab9de408bbd1b.tar.lz cuberite-3fa47b4c8df3dedc20f04cf04edab9de408bbd1b.tar.xz cuberite-3fa47b4c8df3dedc20f04cf04edab9de408bbd1b.tar.zst cuberite-3fa47b4c8df3dedc20f04cf04edab9de408bbd1b.zip |
-rw-r--r-- | Server/Plugins/.gitignore | 1 | ||||
-rw-r--r-- | Server/Plugins/MultiThreadTest/init.lua | 40 |
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 |