feat: Use the Handles, Luke! #427
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I was only planning to file issue #426 tonight, which states the problems I was having. I thought if I poked around I'd find the implementation reason for why what I suggest there wouldn't work. So I made a branch and rolled up my sleeves, and I was able to pretty quickly get exactly what I wanted.
Handles
In the issue I suggest doing away with
ScriptId
. As I worked with the implementation, it became clear I actually wanted to redefine it.Beyond that I made it so
ScriptComponent
holdsHandle<ScriptAsset>
s. The nice thing about this is you can use this pattern:No need to store a strong handle somewhere so your script isn't unloaded. However, if you rely on that behavior you can still do that like you do with any other asset-based item using weak handles.
This preserves the semantics of the current release.
ScriptAsset loading versus evaluation
In this PR the static scripts are handled essentially the same as before except they can retain handles (both strong and weak).
The non-static scripts are not evaluated until they are added to a
ScriptComponent
. Then they are evaluated in order, sequentially.ScriptAsset change
I suggested a change to
ScriptAsset
and that survived this refactoring.I also provided a
ScriptSettings
where one can provide a definite language.None
will use the file's extension.One downside about
ScriptSettings
is it required adding "serde" with the "deriv" feature as a dependency.Example
I updated the Game of Life to work with Lua and Rhai and all its console options.
Remaining work
I have not tried to exercise any other languages or even do much with the tests. But I'd be happy to move this forward to handle the rest with some consensus that that's the right direction.