Skip to content

Commit c9a6ffa

Browse files
authored
docs: Update docs for refactor (#221)
update docs
1 parent 9b9dd57 commit c9a6ffa

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

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

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,28 @@ hello_world("hi from lua!")
4444

4545
## Context Arguments
4646

47-
Each script function call always receives 2 context arguments, namely:
48-
- `CallerContext`
49-
- `WorldCallbackAccess`
47+
Each script function call always receives an additional context argument: `FunctionCallContext`.
48+
You can opt-in to receive this argument in your own function definitions by adding it as the first argument.
5049

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.
50+
The context 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.
5251

53-
The second argument gives you access to the world from your function.
52+
It also allows you to retrieve the world via `FunctionCallContext::world()`.
5453

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)
54+
You can use this as follows:
55+
56+
```rust,ignore
57+
NamespaceBuilder::<ReflectReference>::new(&mut world)
58+
.register(
59+
"hello_world",
60+
|ctx: FunctionCallContext, s: String| {
61+
let world = ctx.world()?;
62+
let should_use_0_indexing = ctx.convert_to_0_indexed;
63+
println!(should_use_0_indexing);
64+
println!(s)
65+
Ok(())
66+
},
67+
);
68+
```
5669

5770
## Generic Arguments
5871

0 commit comments

Comments
 (0)