Skip to content

Commit d5f1873

Browse files
committed
add information on world containers
1 parent f59067c commit d5f1873

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ plugin.add_context_initializer(|script_id: &str, context: &mut Lua| {
1717
for i in 0..10 {
1818
globals.set(i, i);
1919
}
20+
Ok(())
2021
});
2122
2223
app.add_plugins(plugin)
@@ -32,6 +33,7 @@ let plugin = LuaScriptingPlugin::default();
3233
plugin.add_context_pre_handling_initializer(|script_id: &str, entity: Entity, context: &mut Lua| {
3334
let globals = context.globals();
3435
globals.set("script_name", script_id.to_owned());
36+
Ok(())
3537
});
3638
```
3739
## Runtime Initializers
@@ -41,5 +43,19 @@ Some scripting languages, have the concept of a `runtime`. This is a global obje
4143
let plugin = SomeScriptingPlugin::default();
4244
plugin.add_runtime_initializer(|runtime: &mut Runtime| {
4345
runtime.set_max_stack_size(1000);
46+
Ok(())
47+
});
48+
```
49+
50+
## Accessing the World in Initializers
51+
52+
You can access the world in these initializers by using the thread local: `ThreadWorldContainer`:
53+
```rust,ignore
54+
55+
let plugin = LuaScriptingPlugin::default();
56+
plugin.add_context_initializer(|script_id: &str, context: &mut Lua| {
57+
let world = ThreadWorldContainer::get_world();
58+
world.with_resource::<MyResource>(|res| println!("My resource: {:?}", res));
59+
Ok(())
4460
});
4561
```

0 commit comments

Comments
 (0)