gilzoide / godot-lua-pluginscript

Godot PluginScript for the Lua language, currently based on LuaJIT's FFI
https://gilzoide.github.io/godot-lua-pluginscript/topics/README.md.html
MIT License
300 stars 21 forks source link

Passing data between GD.yield() and resume() #14

Closed gilzoide closed 2 years ago

gilzoide commented 2 years ago

Discussed in https://github.com/gilzoide/godot-lua-pluginscript/discussions/13

Originally posted by **Alikae** January 27, 2022 Hi ! I would like to know if there is currently a way to pass data between between GD.yield() and the corresponding resume(). All my tests so far behave as if GD.yield() always return nil, regardless of how I call resume(). Wanted usage: script a: > b.test() > b.resume('data') script b: > function test() > a = GD.yield() > print(a) -- print data Is there something I missed about how to use it ? Is this maybe not an intended feature ? The wanted behavior is easily reproduced by changing > b.resume('data') by > b.some_prop = 'data' > b.resume() Lastly, I came to the sources to try to understand it by myself, but I stumbled upon coroutine.resume and coroutine.yield, that (in my understanding) doesn't seems to be defined anywhere. Does it come from Godot API ? If so, do you know where I can find some documentation about it ? Pretty hard to find Godot documentation that do more than scratching the surface.
gilzoide commented 2 years ago

This is most likely because of the lack of a return at the end of GD.yield: https://github.com/gilzoide/godot-lua-pluginscript/blob/b2100ffaf54ec24d4ba392d5fac57c83323f09e5/src/late_globals.lua#L132-L133