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/ScriptingReference/reflect-reference.md
+21-4Lines changed: 21 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,9 @@
1
1
# ReflectReference
2
2
3
-
ReflectReferences are simply references to date living either:
4
-
-In a component
5
-
-In a resource
6
-
-In the allocator
3
+
ReflectReferences are simply references to data living either in:
4
+
-A component
5
+
-A resource
6
+
-The allocator
7
7
8
8
Reflect references contain a standard interface which operates over the reflection layer exposed by `Bevy` and also provides a way to call various dynamic functions registered on the underlying pointed to data.
9
9
@@ -220,3 +220,20 @@ for val in pairs(ref) do
220
220
print(val)
221
221
end
222
222
```
223
+
224
+
## functions
225
+
Returns a list of functions that can be called on the reference.
Copy file name to clipboardExpand all lines: docs/src/Summary/controlling-script-bindings.md
+38-1Lines changed: 38 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,12 @@ 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
+
## Namespaces
8
+
9
+
Namespaces are a way to group functions together, and are used to prevent naming conflicts. You can have multiple namespaces, and each namespace can have multiple functions.
10
+
11
+
Language implementations will also look for specific functions registered on your type first before looking at the generic `ReflectReference` namespace.
12
+
7
13
## Dynamic Functions
8
14
9
15
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.
@@ -34,12 +40,21 @@ Registering functions can be done via the `NamespaceBuilder` like below:
| get | a getter function, used for indexing into a type | ✅ | ✅ |
117
+
| set | a setter function, used for setting a value on a type | ✅ | ✅ |
118
+
| sub | a subtraction function, used for subtracting two values | ✅ | ❌ |
119
+
| add | an addition function, used for adding two values | ✅ | ❌ |
120
+
| mul | a multiplication function, used for multiplying two values | ✅ | ❌ |
121
+
| div | a division function, used for dividing two values | ✅ | ❌ |
122
+
| rem | a remainder function, used for getting the remainder of two values | ✅ | ❌ |
123
+
| neg | a negation function, used for negating a value | ✅ | ❌ |
124
+
| pow | a power function, used for raising a value to a power | ✅ | ❌ |
125
+
| eq | an equality function, used for checking if two values are equal | ✅ | ❌ |
126
+
| lt | a less than function, used for checking if a value is less than another | ✅ | ❌ |
127
+
| iter | an iterator function, used for iterating over a value | ❌ | ✅ |
128
+
| display_ref | a display function, used for displaying a reference to a value | ❌ | ✅ |
129
+
| display_value | a display function, used for displaying a mutable reference to a value | ❌ | ✅ |
130
+
131
+
In this context `overridable` indicates whether language implementations will look for a specific function on your type before looking at the generic `ReflectReference` namespace. You can still remove the existing registration for these functions on the `ReflectReference` namespace if you want to replace them with your own implementation.
Every script is currently identified by a unique ID.
4
+
5
+
ID's are derived from the script asset path for scripts loaded via the asset system.
6
+
7
+
By default this is an identity mapping, but you can override this by modifying the `AssetPathToScriptIdMapper` inside the `ScriptAssetSettings` resource before loading the script.
0 commit comments