-
-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to implement deferred dependency loading in bevy #43
Comments
Hi @apriori! Thanks for opening this issue! As for alternative approaches, you can always define an API for running scripts, for example |
Hello. Thanks for your swift response. The context is of course a lot more involved. My current approach loads a an entire script without executing it in a coroutine that is stored in a known global member. So far I came up with the following solution:
After that an exclusive system can look in the global variable While this will work, it is quite involved. So far this solution is only working for depth 1, so I guess I need to create a stack of coroutines on the lua side and always drive the stack head further. The thing is, I cannot really change the available lua code too much, because I am loading game assets of an old game in an unchanged way. Do you have async functions for the API provider on the agenda? |
Hmm, thanks for the detailed explanation! I am currently prioritizing completing language and Bevy API support, but I am happy to take on PR's! Did you try the |
Honestly, I can't tell yet, how to do this in an acceptable way. Bevy ergonomics around async is a bit lacking. However, I was able to so solve my usecase using your proposed You will get the general idea looking at this snippet (not a fully runnable example. if you want one, I could create it) Of course one could completely bypass all the mumbo jumbo involving |
I see! Glad to see you got something working, the gist is much appreciated, it's always good to see how the consumers of this crate use it in order to improve it! I will look into this, can't guarantee when but hopefully should get something into next release that will help with your use case! I noticed a new reflect type data |
The "fully resumable" term in this context relates to language features, such as (x)pcall/metamethods/iterators/etc (which lua 5.1 does not support). Unfortuantely LuaJIT cannot yield across C boundaries (this is not part of the VM) and generates the error you see. The mlua's Rust async integration seems the best way to achieve this. It allows to yield a coroutine and then resume it based on an external event (channel message / networking call / etc). You just need an executor to do this (tokio/async-std/etc). |
Ah! Thanks @khvzak, that's very good to know! |
Hello, first thank you for this great crate.
I am currently using your project to implement scripting support in a project using bevy. However, I got the following issue:
AssetIO
override that maps the path to a path into a zip fileSo in all loading, the asset server is involved - and that would include loading dependencies.
Now I got the the issue that e.g. a lua snippet wants to run
and would require to be paused, until the resource is available and the string contents are injected. The lua engine used (Luajit) claims to be fully resumable, so it should be possible to yield across the language barriers, however that exactly is not working with the error:
Is there another approach I should take when lua wants to load a resource that involves async loading from the asset server?
The text was updated successfully, but these errors were encountered: