-
-
Notifications
You must be signed in to change notification settings - Fork 45
feat: Add on_script_reloaded callback, allow retaining state between reloads #421
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
Changes from 4 commits
c2087b1
7cda178
d59839e
d630376
2d83d1e
f70b5c9
c355a34
3cf7d09
7d6392b
0039ec6
f776374
3f3fa28
975df3b
764641e
aa80873
efbd9b9
54c90d0
4a71671
0c0ec4a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,6 +75,7 @@ macro_rules! callback_labels { | |
callback_labels!( | ||
OnScriptLoaded => "on_script_loaded", | ||
OnScriptUnloaded => "on_script_unloaded", | ||
OnScriptReloaded => "on_script_reloaded", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Split into unloaded and reloaded |
||
); | ||
|
||
/// A trait for types that can be converted into a callback label | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,10 @@ | |
|
||
On top of callbacks which are registered by your application, BMS provides a set of core callbacks which are always available. | ||
|
||
The two core callbacks are: | ||
The three core callbacks are: | ||
- `on_script_loaded` | ||
- `on_script_unloaded` | ||
- `on_script_reloaded` | ||
|
||
## `on_script_loaded` | ||
|
||
|
@@ -30,3 +31,24 @@ function on_script_unloaded() | |
print("Goodbye world") | ||
end | ||
``` | ||
|
||
## `on_script_reloaded` | ||
|
||
This will be called twice: right before and after a script is reloaded. | ||
|
||
The first parameter `save` informs you whether it is time to save a value or restore it. | ||
|
||
Before the reload, it is called with one argument: `true`. After the script is reloaded, it is called with two parameters: the first is `false` and the second is value returned from before. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as of now this seems to be misleading for non-shared contexts, in which case only the second half of the callback would happen There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is misleading. The second callback though will never happen because it's dependent on the first callback happening. Sorry, I wrote it before I realized it didn't cover non-shared context. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ohh, I didn't catch the second conditional |
||
|
||
```lua | ||
mode = 1 | ||
function on_script_reloaded(save, value) | ||
if save then | ||
print("Before I go, take this.") | ||
return mode | ||
else | ||
print("I'm back. Where was I?") | ||
mode = value | ||
end | ||
end | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
None
for the missing argumentThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I did not know that. Yes, let me make it arity invariant then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Always provides
vec![ScriptValue::Bool(true), ScriptValue::Unit]
for the "save" case. Is that good for rhai?