Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ Multi-language scripting for Bevy (Lua, Rune). Scripts are Bevy assets; they acc
* Languages dispatch every script operation through `bindings::dispatch` (indexing, operators, static members, printing, iteration) and only convert values and deliver method receivers; see `docs/src/Development/AddingLanguages/necessary-features.md`.
* Functions available on every type (e.g. the shared `new` constructor) are registered on `StaticTypeRef` (`FunctionScope::all_types()`) and bound to the type at lookup by currying a `ScriptValue::Type` (no allocation). Enum variants (`EnumVariantRef`) are resolved the same way, lazily.
* There are no script globals besides the builtins, hardcoded in `bindings::builtins` (`import_namespace`, `export_namespace`) plus the language's `register_callback`; the function registry is keyed by type only. `world` is the `bms.world` namespace value. Functions which don't belong to a type are members of a namespace (`#[script_bindings(namespace = "...")] impl NamespaceMembers`, stored in `AppScriptNamespaceMembers`), i.e. `import_namespace("bms").log_info`; the running script's entity and handle are `bms.current_entity()` / `bms.current_script()`, looked up only when called.
* Every type known to scripts lives in a namespace: the crate defining it, unless overridden with `ScriptNamespace` type data (`script_bindings(namespace = ...)`); BMS' own types are in `bms`. Scripts register components and events only into `script.*` namespaces. `import_namespace(path)` returns a namespace's types (and exported functions), from the shared, lazily rebuilt `AppScriptTypeCatalogue` (`bindings/src/globals/catalogue.rs`).
* `export_namespace` exposes a callback of the calling script as a function in a `script.*` namespace; calls run through the callback runners in the exporting script. A script's exports and observers are removed when it unloads (`remove_script_registrations`).
* Every type known to scripts lives in a namespace: the crate defining it, unless overridden with `ScriptNamespace` type data (`script_bindings(namespace = ...)`); BMS' own types are in `bms`. Scripts register components, events and system sets only into `script.*` namespaces; Rust system sets are namespace members (`ScriptSystemSetAppExt`). `import_namespace(path)` returns a namespace's types (and exported functions), from the shared, lazily rebuilt `AppScriptTypeCatalogue` (`bindings/src/globals/catalogue.rs`).
* `export_namespace` exposes a callback of the calling script as a function in a `script.*` namespace; calls run through the callback runners in the exporting script. A script's exports, system sets (from their namespace only) and observers are removed when it unloads (`remove_script_registrations`).
* Script observers (`world.add_observer`) run their callbacks from a command through `AppScriptCallbackRunners::run_or_queue`, never re-entering a busy context.
* The Rune backend (`crates/languages/bevy_mod_scripting_rune`) differs from Lua in how members are reached (names are registered up front, the context is rebuilt when new ones appear), has no top level code (`pub fn main()` runs on load), no shared globals (`state()`), and catches errors with `catch(|| ..)`; see its crate docs. Rune scripts (`.rn`) have tests next to the Lua ones, run with the `rune` feature.
* Feature flags select language and which Bevy crate bindings are compiled in; exactly one Lua variant must be chosen.
Expand Down
Loading
Loading