You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/controlling-script-bindings.md
+56-1Lines changed: 56 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ In this book we reffer to anything accessible by a script, which allows it to co
4
4
5
5
The "binding" here being used as in: binding `script` code to `rust` code.
6
6
7
-
## Function Registry
7
+
## Dynamic Functions
8
8
9
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
10
@@ -22,5 +22,60 @@ These wrappers enable us to safely interact with bevy, and claim any necessary m
22
22
23
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
24
25
+
## Registering Script Functions
25
26
27
+
Registering functions can be done via the `NamespaceBuilder` like below:
This will allow you to call this function within lua like so:
40
+
41
+
```lua
42
+
hello_world("hi from lua!")
43
+
```
44
+
45
+
## Context Arguments
46
+
47
+
Each script function call always receives 2 context arguments, namely:
48
+
-`CallerContext`
49
+
-`WorldCallbackAccess`
50
+
51
+
The first one is configured by the caller, and contains requests from the caller to your function, such as "I am calling you from a 1-indexed array system, please convert the index first", This argument is only relevant if you're targeting multiple languages.
52
+
53
+
The second argument gives you access to the world from your function.
54
+
55
+
You can opt-in to receive these arguments by adding them to your closure arguments in the above order (either both or just one)
56
+
57
+
## Generic Arguments
58
+
59
+
Sometimes you might want to be generic over the type of argument you're accepting, you can do so by accepting `ScriptValue` arguments like so:
0 commit comments