diff --git a/book/src/SUMMARY.md b/book/src/SUMMARY.md index cfaddce..16b173a 100644 --- a/book/src/SUMMARY.md +++ b/book/src/SUMMARY.md @@ -14,6 +14,7 @@ - [Rhai](./rhai/rhai.md) - [Installation](./rhai/installation.md) - [Hello World(TBD)]() +- [Multiple plugins](./multiple_plugins.md) - [Multiple runtimes(TBD)]() - [Implementing custom runtimes(TBD)]() - [Workflow](./workflow/workflow.md) diff --git a/book/src/introduction.md b/book/src/introduction.md index b4a1dcb..c47b40a 100644 --- a/book/src/introduction.md +++ b/book/src/introduction.md @@ -97,36 +97,6 @@ which you can then call in your script like this: fun_with_string_param("Hello world!") ``` -It is also possible to split the definition of your callback functions up over multiple plugins. This enables you to split up your code by subject and keep the main initialization light and clean. -This can be accomplished by using `add_scripting_api`. Be careful though, `add_scripting` has to be called before adding plugins. -```rust -use bevy::prelude::*; -use bevy_scriptum::prelude::*; -use bevy_scriptum::runtimes::lua::prelude::*; - -struct MyPlugin; -impl Plugin for MyPlugin { - fn build(&self, app: &mut App) { - app.add_scripting_api::(|runtime| { - runtime.add_function(String::from("hello_from_my_plugin"), || { - info!("Hello from MyPlugin"); - }); - }); - } -} - -// Main -fn main() { - App::new() - .add_plugins(DefaultPlugins) - .add_scripting::(|_| { - // nice and clean - }) - .add_plugins(MyPlugin) - .run(); -} -``` - ### Usage Add the following to your `Cargo.toml`: diff --git a/book/src/multiple_plugins.md b/book/src/multiple_plugins.md new file mode 100644 index 0000000..c840490 --- /dev/null +++ b/book/src/multiple_plugins.md @@ -0,0 +1,31 @@ +# Multiple plugins + +It is possible to split the definition of your callback functions up over multiple plugins. This enables you to split up your code by subject and keep the main initialization light and clean. +This can be accomplished by using `add_scripting_api`. Be careful though, `add_scripting` has to be called before adding plugins. +```rust +use bevy::prelude::*; +use bevy_scriptum::prelude::*; +use bevy_scriptum::runtimes::lua::prelude::*; + +struct MyPlugin; +impl Plugin for MyPlugin { + fn build(&self, app: &mut App) { + app.add_scripting_api::(|runtime| { + runtime.add_function(String::from("hello_from_my_plugin"), || { + info!("Hello from MyPlugin"); + }); + }); + } +} + +// Main +fn main() { + App::new() + .add_plugins(DefaultPlugins) + .add_scripting::(|_| { + // nice and clean + }) + .add_plugins(MyPlugin) + .run(); +} +```