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 /Server/Plugins/MultiThreadTest/init.lua | |
parent | First PoC for multithreading in plugins. (diff) | |
download | cuberite-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 |
Diffstat (limited to '')
-rw-r--r-- | Server/Plugins/MultiThreadTest/init.lua | 40 |
1 files changed, 40 insertions, 0 deletions
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 |