From 2521a90712b06e3ab72f7ed9fbe9726dab2202f1 Mon Sep 17 00:00:00 2001 From: Ryan Ward Date: Wed, 29 Jan 2020 21:47:14 -0500 Subject: [PATCH] tests --- test.lua | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/test.lua b/test.lua index 9c85db4..0ca015c 100644 --- a/test.lua +++ b/test.lua @@ -1,5 +1,29 @@ package.path="?/init.lua;?.lua;"..package.path multi,thread = require("multi"):init() -multi.OnExit(function(n) - print("Code Exited") +function test() -- Auto converts your function into a threaded function + thread.sleep(1) + return 1,2 +end +multi:newThread(function() + while true do + thread.sleep(.1) + print("hi") + end end) +c,d = test() +print(c,d) +a,b = 6,7 +multi:newThread(function() + -- a,b = test().wait() -- Will modify Global + -- when wait is used the special metamethod routine is not triggered and variables are set as normal + a,b = test() -- Will modify GLocal + -- the threaded function test triggers a special routine within the metamethod that alters the thread's enviroment instead of the global enviroment. + print("Waited:",a,b) + --This returns instantly even though the function isn't done! + test().connect(function(a,b) + print("Connected:",a,b) + os.exit() + end) + -- This waits for the returns since we are demanding them +end) +multi:mainloop() \ No newline at end of file