Skip to content

Commit 548eeb7

Browse files
committed
update docs
1 parent 068e695 commit 548eeb7

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Controlling Script Bindings
2+
3+
In this book we reffer to anything accessible by a script, which allows it to communicate with your Rust code a `binding` (which in previous versions was more generically referred to as a script API).
4+
5+
The "binding" here being used as in: binding `script` code to `rust` code.
6+
7+
## Function Registry
8+
9+
Everything callable by scripts must first be registered in the dynamic function registry. Notably we do not make use of the normal bevy function registry to improve performance and usability. This means you cannot call just any function.
10+
11+
In order for a function to be callable by a script it must adhere to a few requirements:
12+
- Each argument must implement `FromScript`.
13+
- Each return type must implement `IntoScript`.
14+
- Each argument must also implement `GetInnerTypeDependencies`
15+
- Each return type must also implement `GetInnerTypeDependencies`
16+
17+
The into/from requirements allow us to convert these types to `ScriptValue`'s, and each supported scripting language can then marshall these into the script.
18+
19+
Note these types are implemented for primitives, but if you want to interact with one of your `Reflect` implementing types, you will need to use one of `Ref<T>`, `Mut<T>` or `Val<T>` wrappers in place of `&T`, `&mut T` and `T` respectively.
20+
21+
These wrappers enable us to safely interact with bevy, and claim any necessary mutex'es on `Resources`, `Components` or `Allocations`.
22+
23+
The `GetInnerTypeDependencies`, trait is simply a local trait alias for `GetTypeRegistration` with less strict type requirements. It allows us to register all the types necessary for the function calls, so that you don't have to register anything manually. If your type implements `GetTypeRegistration` you should not face any issues on this front.
24+
25+
26+

0 commit comments

Comments
 (0)