Hey! I wanted to embed lua in to a project of mine, but I have a requirement that I want to see if this library can meet. I want to be able to have multiple scripts execute cooperatively. This means that they are running on the same thread and sharing the same context, but maintain their own stacks (local variables, functions, etc).
Here is an example scenario:
-- Script 1
print("Hello From Script 1")
wait(5)
print("Finished 1")
Obviously wait() is a method that I would have to design and build a scheduler for. But I would want these two scripts to be able to run at the same time. The desired output would be:
> Hello From Script 1
> Hello From Script 2
> Finished 1
> Finished 2
Actually, Lua itself supports this via its builtin coroutine library, with a few caveats though:
I don't think the scripts can literally "run at the same time" since Lua does not guarantee OS-thread safety. (But you've mentioned that "they are running on the same thread" so it is probably fine to you?)
Hey! I wanted to embed lua in to a project of mine, but I have a requirement that I want to see if this library can meet. I want to be able to have multiple scripts execute cooperatively. This means that they are running on the same thread and sharing the same context, but maintain their own stacks (local variables, functions, etc).
Here is an example scenario:
Obviously wait() is a method that I would have to design and build a scheduler for. But I would want these two scripts to be able to run at the same time. The desired output would be: