add example
This commit is contained in:
parent
7f7943fe84
commit
20bf7121ff
3 changed files with 47 additions and 0 deletions
|
|
@ -205,6 +205,11 @@ name = "promises_ruby"
|
||||||
path = "examples/ruby/promises.rs"
|
path = "examples/ruby/promises.rs"
|
||||||
required-features = ["ruby"]
|
required-features = ["ruby"]
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "side_effects_ruby"
|
||||||
|
path = "examples/ruby/side_effects.rs"
|
||||||
|
required-features = ["ruby"]
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
tracing-subscriber = "0.3.18"
|
tracing-subscriber = "0.3.18"
|
||||||
mlua = { version = "0.9.8", features = ["luajit", "vendored", "send"] }
|
mlua = { version = "0.9.8", features = ["luajit", "vendored", "send"] }
|
||||||
|
|
|
||||||
1
assets/examples/ruby/side_effects.rb
Normal file
1
assets/examples/ruby/side_effects.rb
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
spawn_entity()
|
||||||
41
examples/ruby/side_effects.rs
Normal file
41
examples/ruby/side_effects.rs
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
use bevy::{app::AppExit, prelude::*};
|
||||||
|
use bevy_scriptum::prelude::*;
|
||||||
|
use bevy_scriptum::runtimes::ruby::prelude::*;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
App::new()
|
||||||
|
// This is just needed for headless console app, not needed for a regular bevy game
|
||||||
|
// that uses a winit window
|
||||||
|
.set_runner(move |mut app: App| loop {
|
||||||
|
app.update();
|
||||||
|
if let Some(exit) = app.should_exit() {
|
||||||
|
return exit;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.add_plugins(DefaultPlugins)
|
||||||
|
.add_systems(Startup, startup)
|
||||||
|
.add_systems(Update, print_entity_names_and_quit)
|
||||||
|
.add_scripting::<RubyRuntime>(|runtime| {
|
||||||
|
runtime.add_function(String::from("spawn_entity"), spawn_entity);
|
||||||
|
})
|
||||||
|
.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn spawn_entity(mut commands: Commands) {
|
||||||
|
commands.spawn(Name::new("SpawnedEntity"));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn startup(mut commands: Commands, assets_server: Res<AssetServer>) {
|
||||||
|
commands.spawn((Script::<RubyScript>::new(
|
||||||
|
assets_server.load("examples/ruby/side_effects.rb"),
|
||||||
|
),));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn print_entity_names_and_quit(query: Query<&Name>, mut exit: EventWriter<AppExit>) {
|
||||||
|
if !query.is_empty() {
|
||||||
|
for e in &query {
|
||||||
|
println!("{}", e);
|
||||||
|
}
|
||||||
|
exit.write(AppExit::Success);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue