Skip to content

Conversation

makspll
Copy link
Owner

@makspll makspll commented Oct 12, 2025

Summary

Adds register_callback low level global binding, which let's you create, pre-registered or "frozen" callbacks. These allow scripts in shared contexts to persist their callbacks regardless of the "current" top level function state.

This also allows scripts to "switch" callbacks at runtime easilly if they so desire.

This PR also adds a DummyScriptFunctionsRegistry and modifies the derive macro, to allow naturally writing docs for low level functions like this one in the future.

Migration Guide

  • ScriptAttachment is moved to the bevy_mod_scripting::script namespace and new crate.
  • Old callbacks behave exactly how they used to, no changes required in callback logic

Copy link

semanticdiff-com bot commented Oct 12, 2025

Review changes with  SemanticDiff

Changed Files
File Status
  crates/bevy_mod_scripting_bindings/src/allocator.rs  84% smaller
  crates/languages/bevy_mod_scripting_lua/src/bindings/reference.rs  80% smaller
  crates/languages/bevy_mod_scripting_rhai/src/bindings/reference.rs  80% smaller
  crates/bevy_mod_scripting_bindings/src/reference.rs  77% smaller
  crates/bevy_mod_scripting_core/src/pipeline/start.rs  74% smaller
  crates/ladfile_builder/src/plugin.rs  62% smaller
  crates/bevy_mod_scripting_core/src/context.rs  54% smaller
  crates/bevy_mod_scripting_core/src/lib.rs  50% smaller
  crates/bevy_mod_scripting_bindings/src/function/script_function.rs  50% smaller
  crates/testing_crates/script_integration_test_harness/src/lib.rs  43% smaller
  crates/bevy_mod_scripting_core/src/script_system.rs  34% smaller
  crates/bevy_mod_scripting_core/src/handler.rs  33% smaller
  crates/bevy_mod_scripting_bindings/src/world.rs  21% smaller
  crates/bevy_mod_scripting_core/src/commands.rs  17% smaller
  crates/languages/bevy_mod_scripting_lua/src/lib.rs  12% smaller
  crates/bevy_mod_scripting_bindings/src/function/namespace.rs  11% smaller
  crates/bevy_mod_scripting_functions/src/core.rs  9% smaller
  crates/bevy_mod_scripting_core/src/extractors.rs  8% smaller
  crates/testing_crates/test_utils/src/test_plugin.rs  4% smaller
  crates/bevy_mod_scripting_display/src/lib.rs  3% smaller
  crates/bevy_mod_scripting_core/src/event.rs  3% smaller
  crates/testing_crates/script_integration_test_harness/src/scenario.rs  2% smaller
  crates/bevy_mod_scripting_core/src/pipeline/mod.rs  1% smaller
  crates/languages/bevy_mod_scripting_rhai/src/lib.rs  1% smaller
  crates/bevy_mod_scripting_core/src/script/mod.rs  1% smaller
  crates/bevy_mod_scripting_bindings/src/docgen/typed_through.rs  1% smaller
  Cargo.toml Unsupported file format
  assets/tests/register_callback/lua/dynamic_on_test.lua  0% smaller
  assets/tests/register_callback/lua/empty.lua  0% smaller
  assets/tests/register_callback/lua/scenario.txt Unsupported file format
  assets/tests/register_callback/rhai/dynamic_on_test.rhai Unsupported file format
  assets/tests/register_callback/rhai/empty.rhai Unsupported file format
  assets/tests/register_callback/rhai/scenario.txt Unsupported file format
  crates/bevy_mod_scripting_bindings/Cargo.toml Unsupported file format
  crates/bevy_mod_scripting_bindings/src/function/from.rs  0% smaller
  crates/bevy_mod_scripting_bindings/src/function/into_ref.rs  0% smaller
  crates/bevy_mod_scripting_core/Cargo.toml Unsupported file format
  crates/bevy_mod_scripting_core/src/callbacks.rs  0% smaller
  crates/bevy_mod_scripting_core/src/pipeline/hooks.rs  0% smaller
  crates/bevy_mod_scripting_core/src/pipeline/machines.rs  0% smaller
  crates/bevy_mod_scripting_core/src/script/context_key.rs  0% smaller
  crates/bevy_mod_scripting_core/src/script/script_context.rs  0% smaller
  crates/bevy_mod_scripting_derive/src/derive/script_bindings.rs  0% smaller
  crates/bevy_mod_scripting_derive/src/lib.rs  0% smaller
  crates/bevy_mod_scripting_display/src/handle.rs  0% smaller
  crates/bevy_mod_scripting_functions/Cargo.toml Unsupported file format
  crates/bevy_mod_scripting_script/Cargo.toml Unsupported file format
  crates/bevy_mod_scripting_script/src/lib.rs  0% smaller
  crates/lad_backends/mdbook_lad_preprocessor/src/markdown.rs  0% smaller
  crates/ladfile_builder/src/lib.rs  0% smaller
  crates/languages/bevy_mod_scripting_lua/Cargo.toml Unsupported file format
  crates/languages/bevy_mod_scripting_rhai/Cargo.toml Unsupported file format
  crates/testing_crates/script_integration_test_harness/Cargo.toml Unsupported file format
  crates/testing_crates/script_integration_test_harness/src/parse.rs  0% smaller
  docs/src/SUMMARY.md Unsupported file format
  docs/src/ScriptingReference/core-callbacks.md Unsupported file format
  docs/src/Summary/callbacks.md Unsupported file format
  docs/src/Summary/contexts.md Unsupported file format
  examples/docgen.rs  0% smaller
  examples/game_of_life.rs  0% smaller
  src/lib.rs  0% smaller
  src/prelude.rs  0% smaller

Copy link
Contributor

github-actions bot commented Oct 12, 2025

🐰 Bencher Report

Branchfeat/registered-callbacks
Testbedlinux-gha
Click to view all benchmark results
BenchmarkLatencyBenchmark Result
nanoseconds (ns)
(Result Δ%)
Upper Boundary
nanoseconds (ns)
(Limit %)
component/access Lua📈 view plot
🚷 view threshold
3,737.70 ns
(-7.61%)Baseline: 4,045.44 ns
4,432.04 ns
(84.33%)
component/access Rhai📈 view plot
🚷 view threshold
5,660.30 ns
(-4.95%)Baseline: 5,954.79 ns
6,273.14 ns
(90.23%)
component/get Lua📈 view plot
🚷 view threshold
2,361.20 ns
(-3.27%)Baseline: 2,440.91 ns
2,644.54 ns
(89.29%)
component/get Rhai📈 view plot
🚷 view threshold
4,549.80 ns
(+1.08%)Baseline: 4,501.13 ns
4,802.79 ns
(94.73%)
conversions/Mut::from📈 view plot
🚷 view threshold
79.44 ns
(-8.89%)Baseline: 87.20 ns
95.99 ns
(82.76%)
conversions/Ref::from📈 view plot
🚷 view threshold
76.18 ns
(-10.92%)Baseline: 85.52 ns
98.00 ns
(77.74%)
conversions/ScriptValue::List📈 view plot
🚷 view threshold
370.44 ns
(+10.25%)Baseline: 336.01 ns
458.03 ns
(80.88%)
conversions/ScriptValue::Map📈 view plot
🚷 view threshold
981.34 ns
(-8.62%)Baseline: 1,073.93 ns
1,216.04 ns
(80.70%)
conversions/ScriptValue::Reference::from_into📈 view plot
🚷 view threshold
24.05 ns
(-8.54%)Baseline: 26.29 ns
30.72 ns
(78.30%)
conversions/Val::from_into📈 view plot
🚷 view threshold
252.56 ns
(-14.67%)Baseline: 295.99 ns
351.45 ns
(71.86%)
function/call 4 args Lua📈 view plot
🚷 view threshold
1,605.60 ns
(-13.64%)Baseline: 1,859.26 ns
2,130.68 ns
(75.36%)
function/call 4 args Rhai📈 view plot
🚷 view threshold
1,297.90 ns
(-13.49%)Baseline: 1,500.28 ns
1,722.71 ns
(75.34%)
function/call Lua📈 view plot
🚷 view threshold
236.28 ns
(-4.06%)Baseline: 246.29 ns
273.57 ns
(86.37%)
function/call Rhai📈 view plot
🚷 view threshold
496.04 ns
(+8.30%)Baseline: 458.02 ns
543.70 ns
(91.23%)
loading/empty Lua📈 view plot
🚷 view threshold
1,010,000.00 ns
(+151.10%)Baseline: 402,232.30 ns
1,574,539.48 ns
(64.15%)
loading/empty Rhai📈 view plot
🚷 view threshold
938,030.00 ns
(+47.31%)Baseline: 636,768.00 ns
1,483,400.67 ns
(63.24%)
math/vec mat ops Lua📈 view plot
🚷 view threshold
6,706.60 ns
(-14.30%)Baseline: 7,825.43 ns
9,350.01 ns
(71.73%)
math/vec mat ops Rhai📈 view plot
🚷 view threshold
6,216.60 ns
(-8.24%)Baseline: 6,774.74 ns
7,636.12 ns
(81.41%)
query/10 entities Lua📈 view plot
🚷 view threshold
18,763.00 ns
(-9.62%)Baseline: 20,759.90 ns
23,035.43 ns
(81.45%)
query/10 entities Rhai📈 view plot
🚷 view threshold
19,037.00 ns
(-8.84%)Baseline: 20,882.30 ns
22,767.03 ns
(83.62%)
query/100 entities Lua📈 view plot
🚷 view threshold
38,670.00 ns
(-9.71%)Baseline: 42,828.90 ns
47,344.72 ns
(81.68%)
query/100 entities Rhai📈 view plot
🚷 view threshold
31,032.00 ns
(-9.65%)Baseline: 34,347.50 ns
37,763.47 ns
(82.17%)
query/1000 entities Lua📈 view plot
🚷 view threshold
240,940.00 ns
(-13.82%)Baseline: 279,575.00 ns
325,525.53 ns
(74.02%)
query/1000 entities Rhai📈 view plot
🚷 view threshold
158,950.00 ns
(-6.62%)Baseline: 170,222.00 ns
185,583.55 ns
(85.65%)
reflection/10 Lua📈 view plot
🚷 view threshold
5,394.60 ns
(-14.22%)Baseline: 6,288.93 ns
7,174.18 ns
(75.19%)
reflection/10 Rhai📈 view plot
🚷 view threshold
14,981.00 ns
(-5.70%)Baseline: 15,886.20 ns
16,783.21 ns
(89.26%)
reflection/100 Lua📈 view plot
🚷 view threshold
46,237.00 ns
(-12.47%)Baseline: 52,821.50 ns
59,667.75 ns
(77.49%)
reflection/100 Rhai📈 view plot
🚷 view threshold
699,450.00 ns
(-10.32%)Baseline: 779,952.00 ns
864,023.76 ns
(80.95%)
resource/access Lua📈 view plot
🚷 view threshold
3,237.00 ns
(-9.94%)Baseline: 3,594.18 ns
4,012.09 ns
(80.68%)
resource/access Rhai📈 view plot
🚷 view threshold
5,120.00 ns
(-5.69%)Baseline: 5,428.96 ns
5,769.06 ns
(88.75%)
resource/get Lua📈 view plot
🚷 view threshold
1,912.50 ns
(-7.21%)Baseline: 2,061.20 ns
2,268.63 ns
(84.30%)
resource/get Rhai📈 view plot
🚷 view threshold
3,771.20 ns
(-5.19%)Baseline: 3,977.79 ns
4,287.66 ns
(87.95%)
🐰 View full continuous benchmarking report in Bencher

@makspll makspll changed the title feat: registered callbacks feat: registered callbacks via register_callback, and bevy_mod_scripting_script crate. Oct 12, 2025
@makspll makspll enabled auto-merge (squash) October 12, 2025 19:16
@makspll makspll changed the title feat: registered callbacks via register_callback, and bevy_mod_scripting_script crate. feat: registered callbacks via register_callback, and bevy_mod_scripting_script crate + dummy functions Oct 12, 2025
@makspll makspll merged commit 8b596c8 into main Oct 12, 2025
26 of 28 checks passed
@makspll makspll deleted the feat/registered-callbacks branch October 12, 2025 20:02
@github-actions github-actions bot mentioned this pull request Oct 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant