add example
This commit is contained in:
parent
ca82a8f3a3
commit
7f7943fe84
4 changed files with 40 additions and 1 deletions
|
|
@ -200,6 +200,11 @@ name = "multiple_plugins_ruby"
|
|||
path = "examples/ruby/multiple_plugins.rs"
|
||||
required-features = ["ruby"]
|
||||
|
||||
[[example]]
|
||||
name = "promises_ruby"
|
||||
path = "examples/ruby/promises.rs"
|
||||
required-features = ["ruby"]
|
||||
|
||||
[dev-dependencies]
|
||||
tracing-subscriber = "0.3.18"
|
||||
mlua = { version = "0.9.8", features = ["luajit", "vendored", "send"] }
|
||||
|
|
|
|||
3
assets/examples/ruby/promises.rb
Normal file
3
assets/examples/ruby/promises.rb
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
get_player_name.and_then do |name|
|
||||
puts name
|
||||
end
|
||||
|
|
@ -17,7 +17,7 @@ impl Plugin for PluginA {
|
|||
|
||||
fn plugin_a_startup(mut commands: Commands, assets_server: Res<AssetServer>) {
|
||||
commands.spawn(Script::<RubyScript>::new(
|
||||
assets_server.load("examples/lua/multiple_plugins_plugin_a.lua"),
|
||||
assets_server.load("examples/ruby/multiple_plugins_plugin_a.rb"),
|
||||
));
|
||||
}
|
||||
|
||||
|
|
|
|||
31
examples/ruby/promises.rs
Normal file
31
examples/ruby/promises.rs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
use bevy::prelude::*;
|
||||
use bevy_scriptum::prelude::*;
|
||||
use bevy_scriptum::runtimes::ruby::prelude::*;
|
||||
|
||||
#[derive(Component)]
|
||||
struct Player;
|
||||
|
||||
fn main() {
|
||||
App::new()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_scripting::<RubyRuntime>(|builder| {
|
||||
builder.add_function(
|
||||
String::from("get_player_name"),
|
||||
|player_names: Query<&Name, With<Player>>| {
|
||||
player_names
|
||||
.single()
|
||||
.expect("Missing player_names")
|
||||
.to_string()
|
||||
},
|
||||
);
|
||||
})
|
||||
.add_systems(Startup, startup)
|
||||
.run();
|
||||
}
|
||||
|
||||
fn startup(mut commands: Commands, assets_server: Res<AssetServer>) {
|
||||
commands.spawn((Player, Name::new("John")));
|
||||
commands.spawn(Script::<RubyScript>::new(
|
||||
assets_server.load("examples/ruby/promises.rb"),
|
||||
));
|
||||
}
|
||||
Loading…
Reference in a new issue