Ruby support #1
4 changed files with 40 additions and 1 deletions
|
|
@ -200,6 +200,11 @@ name = "multiple_plugins_ruby"
|
||||||
path = "examples/ruby/multiple_plugins.rs"
|
path = "examples/ruby/multiple_plugins.rs"
|
||||||
required-features = ["ruby"]
|
required-features = ["ruby"]
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "promises_ruby"
|
||||||
|
path = "examples/ruby/promises.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"] }
|
||||||
|
|
|
||||||
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>) {
|
fn plugin_a_startup(mut commands: Commands, assets_server: Res<AssetServer>) {
|
||||||
commands.spawn(Script::<RubyScript>::new(
|
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