Skip to content

Commit a03ec73

Browse files
committed
update docs
1 parent 9629224 commit a03ec73

File tree

5 files changed

+68
-6
lines changed

5 files changed

+68
-6
lines changed

docs/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- [Controlling Script Bindings](./Summary/controlling-script-bindings.md)
1010
- [Modifying Script Contexts](./Summary/customizing-script-contexts.md)
1111
- [Shared Contexts](./Summary/sharing-contexts-between-scripts.md)
12+
- [Script ID Mapping](./Summary/script-id-mapping.md)
1213

1314
# Scripting Reference
1415

docs/src/ScriptingReference/reflect-reference.md

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# ReflectReference
22

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
77

88
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.
99

@@ -220,3 +220,20 @@ for val in pairs(ref) do
220220
print(val)
221221
end
222222
```
223+
224+
## functions
225+
Returns a list of functions that can be called on the reference.
226+
227+
Returns:
228+
229+
| Return | Description |
230+
| --- | --- |
231+
| `Vec<FunctionInfo>` | The list of functions |
232+
233+
```lua
234+
local functions = ref:functions()
235+
for _, func in ipairs(functions) do
236+
print(func.name)
237+
238+
end
239+
```

docs/src/Summary/controlling-script-bindings.md

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ In this book we reffer to anything accessible by a script, which allows it to co
44

55
The "binding" here being used as in: binding `script` code to `rust` code.
66

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+
713
## Dynamic Functions
814

915
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:
3440
println!(s)
3541
},
3642
);
43+
44+
NamespaceBuilder::<GlobalNamespace>::new_unregistered(&mut world)
45+
.register(
46+
"hello_world2",
47+
|s: String| {
48+
println!(s)
49+
},
50+
);
3751
```
3852

3953
This will allow you to call this function within lua like so:
4054

4155
```lua
42-
hello_world("hi from lua!")
56+
some_type:hello_world("hi from method!");
57+
hello_world2("hi from global!");
4358
```
4459

4560
## Context Arguments
@@ -92,3 +107,25 @@ Your script functions can return errors either by:
92107
- Returning `Result<T: IntoScript, InteropError>`
93108
- Returning `ScriptValue` and manually creating the `ScriptValue::Error(into_interop_erorr.into())` variant.
94109

110+
## Reserved Functions
111+
112+
There are a few reserved functions that you can override by registering them on a specific type:
113+
114+
| Function Name | Description | Overridable? | Has Default Implementation? |
115+
|---------------|-------------| ------------ | --------------------------- |
116+
| 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.

docs/src/Summary/customizing-script-contexts.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ You can access the world in these initializers by using the thread local: `Threa
5252
5353
let plugin = LuaScriptingPlugin::default();
5454
plugin.add_context_initializer(|script_id: &str, context: &mut Lua| {
55-
let world = ThreadWorldContainer::get_world();
55+
let world = ThreadWorldContainer.try_get_world().unwrap();
5656
world.with_resource::<MyResource>(|res| println!("My resource: {:?}", res));
5757
Ok(())
5858
});

docs/src/Summary/script-id-mapping.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Script ID mapping
2+
3+
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

Comments
 (0)