-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added add_scripting_api function to AppBuilder (#23)
* Added `add_scripting_api` function to builder
- Loading branch information
1 parent
f85dbcf
commit be8a805
Showing
9 changed files
with
225 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
hello_from_plugin_a() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
hello_from_plugin_b_with_parameters("hello", 42) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
hello_from_plugin_a(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
hello_from_plugin_b_with_parameters("hello", 42); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
use bevy::prelude::*; | ||
use bevy_scriptum::prelude::*; | ||
use bevy_scriptum::runtimes::lua::prelude::*; | ||
|
||
// Plugin A | ||
struct PluginA; | ||
impl Plugin for PluginA { | ||
fn build(&self, app: &mut App) { | ||
app.add_scripting_api::<LuaRuntime>(|runtime| { | ||
runtime.add_function(String::from("hello_from_plugin_a"), || { | ||
info!("Hello from Plugin A"); | ||
}); | ||
}) | ||
.add_systems(Startup, plugin_a_startup); | ||
} | ||
} | ||
|
||
fn plugin_a_startup(mut commands: Commands, assets_server: Res<AssetServer>) { | ||
commands.spawn(Script::<LuaScript>::new( | ||
assets_server.load("examples/lua/multiple_plugins_plugin_a.lua"), | ||
)); | ||
} | ||
|
||
// Plugin B | ||
struct PluginB; | ||
impl Plugin for PluginB { | ||
fn build(&self, app: &mut App) { | ||
app.add_scripting_api::<LuaRuntime>(|runtime| { | ||
runtime.add_function( | ||
String::from("hello_from_plugin_b_with_parameters"), | ||
hello_from_b, | ||
); | ||
}) | ||
.add_systems(Startup, plugin_b_startup); | ||
} | ||
} | ||
|
||
fn plugin_b_startup(mut commands: Commands, assets_server: Res<AssetServer>) { | ||
commands.spawn(Script::<LuaScript>::new( | ||
assets_server.load("examples/lua/multiple_plugins_plugin_b.lua"), | ||
)); | ||
} | ||
|
||
fn hello_from_b(In((text, x)): In<(String, i32)>) { | ||
info!("{} from Plugin B: {}", text, x); | ||
} | ||
|
||
// Main | ||
fn main() { | ||
App::new() | ||
.add_plugins(DefaultPlugins) | ||
.add_scripting::<LuaRuntime>(|runtime| { | ||
runtime.add_function(String::from("hello_bevy"), || { | ||
info!("hello bevy, called from script"); | ||
}); | ||
}) | ||
.add_systems(Startup, main_startup) | ||
.add_plugins(PluginA) | ||
.add_plugins(PluginB) | ||
.run(); | ||
} | ||
|
||
fn main_startup(mut commands: Commands, assets_server: Res<AssetServer>) { | ||
commands.spawn(Script::<LuaScript>::new( | ||
assets_server.load("examples/lua/hello_world.lua"), | ||
)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
use bevy::prelude::*; | ||
use bevy_scriptum::prelude::*; | ||
use bevy_scriptum::runtimes::rhai::prelude::*; | ||
use rhai::ImmutableString; | ||
|
||
// Plugin A | ||
struct PluginA; | ||
impl Plugin for PluginA { | ||
fn build(&self, app: &mut App) { | ||
app.add_scripting_api::<RhaiRuntime>(|runtime| { | ||
runtime.add_function(String::from("hello_from_plugin_a"), || { | ||
info!("Hello from Plugin A"); | ||
}); | ||
}) | ||
.add_systems(Startup, plugin_a_startup); | ||
} | ||
} | ||
|
||
fn plugin_a_startup(mut commands: Commands, assets_server: Res<AssetServer>) { | ||
commands.spawn(Script::<RhaiScript>::new( | ||
assets_server.load("examples/rhai/multiple_plugins_plugin_a.rhai"), | ||
)); | ||
} | ||
|
||
// Plugin B | ||
struct PluginB; | ||
impl Plugin for PluginB { | ||
fn build(&self, app: &mut App) { | ||
app.add_scripting_api::<RhaiRuntime>(|runtime| { | ||
runtime.add_function( | ||
String::from("hello_from_plugin_b_with_parameters"), | ||
hello_from_b, | ||
); | ||
}) | ||
.add_systems(Startup, plugin_b_startup); | ||
} | ||
} | ||
|
||
fn plugin_b_startup(mut commands: Commands, assets_server: Res<AssetServer>) { | ||
commands.spawn(Script::<RhaiScript>::new( | ||
assets_server.load("examples/rhai/multiple_plugins_plugin_b.rhai"), | ||
)); | ||
} | ||
|
||
fn hello_from_b(In((text, x)): In<(ImmutableString, i64)>) { | ||
info!("{} from Plugin B: {}", text, x); | ||
} | ||
|
||
// Main | ||
fn main() { | ||
App::new() | ||
.add_plugins(DefaultPlugins) | ||
.add_scripting::<RhaiRuntime>(|runtime| { | ||
runtime.add_function(String::from("hello_bevy"), || { | ||
info!("hello bevy, called from script"); | ||
}); | ||
}) | ||
.add_systems(Startup, main_startup) | ||
.add_plugins(PluginA) | ||
.add_plugins(PluginB) | ||
.run(); | ||
} | ||
|
||
fn main_startup(mut commands: Commands, assets_server: Res<AssetServer>) { | ||
commands.spawn(Script::<RhaiScript>::new( | ||
assets_server.load("examples/rhai/hello_world.rhai"), | ||
)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters