Closed orange451 closed 5 months ago
Sorry if this is supposed to go in "Discussions" section.
No, you can't call coroutine.yield()
from Java. To yield
from a coroutine, Lua needs to somehow save the whole calling stack in order to restore execution afterwards. Since it has no idea about C stack or Java stacks, it cannot save them without possibly crashing the whole program, and thus calling from C (or Java) is prohibited by Lua. You may still achieve what you want with a bit of additional lua code of course, e.g., function wait(sec) coroutine.yield("wait", sec) end
(whose yielded values may then be processed by your scheduler calling coroutine.resume
, which can be in pure Java).
I am trying to make a set of nice sandboxed functions to play around with in lua, but controlled from java.
To start, I want to create a wait() function, which yields the current coroutine for a given amount of time, then resumes. I want this to be controlled from Java side, so that there is no additional lua code that needs to be defined for each script that runs. My current implementation looks like this:
However, this produces the following error:
Is there any way to achieve this? It would be very nice in my project to just be able to write lua like this: