avoiding globals and keeping execution within the Lua engine would be preferable yes.
here's an approach that avoids both globals and invoking the commandline interpreter:
Code
local function myecho(str)
for i=1,5 do
Echo(str)
coroutine.yield(0.5)
end
end
local function outsource(func, ...)
local args = {...}
Timer(function() return func(table.unpack(args)) end, 0, 1)
end
return function()
Echo('same coroutine:')
myecho('hello')
myecho('world')
Echo('different coroutines:')
outsource(myecho, 'hello')
outsource(myecho, 'world')
end
Display More