Wondering how to do multi-threaded scripts, I'm pretty sure it involves the use of co-routines but I don't entirely understand the documentation. http://lua-users.org/wiki/CoroutinesTutorial
So just to give you a quick example, if I had the following:
Both parts need to be coroutines. That is, the print statement needs to be in a separate coroutine. Then you would need to resume other threads within each other. Try maybe something like this:
local threads = {};
function createThread(func)
local tmp = coroutine.create(func);
table.insert(threads, tmp);
end
function main()
local func1 = function()
while(true) do
for i = 1,10 do
print(i);
coroutine.yield();
end
end
end
local func2 = function ()
while(true) do
print("Hello World");
coroutine.yield();
end
end
createThread(func1);
createThread(func2);
while(true) do
for i,v in pairs(threads) do
coroutine.resume(v);
end
end
end
startMacro(main);
Also remember that once the function returns that thread is "dead". That's why I wrapped both functions in while loops for this example.