diff --git a/Cargo.toml b/Cargo.toml index 5eb7042..34eb2db 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,7 @@ keywords = ["bevy", "rhai", "scripting", "game", "gamedev"] [features] lua = ["mlua/luajit"] rhai = ["dep:rhai"] +ruby = ["dep:magnus"] [dependencies] bevy = { default-features = false, version = "0.16", features = ["bevy_asset", "bevy_log"] } @@ -25,11 +26,12 @@ rhai = { version = "1.14.0", features = [ thiserror = "1.0.40" anyhow = "1.0.82" tracing = "0.1.40" -mlua = { version = "0.9.8", features = [ +lua = { version = "0.9.8", features = [ "luajit", "vendored", "send", ], optional = true } +magnus = { version = "0.6.4", optional = true } [[example]] name = "call_function_from_rust_rhai" diff --git a/src/runtimes/mod.rs b/src/runtimes/mod.rs index c01166f..96bf325 100644 --- a/src/runtimes/mod.rs +++ b/src/runtimes/mod.rs @@ -2,3 +2,5 @@ pub mod lua; #[cfg(feature = "rhai")] pub mod rhai; +#[cfg(feature = "ruby")] +pub mod ruby; diff --git a/src/runtimes/ruby.rs b/src/runtimes/ruby.rs new file mode 100644 index 0000000..15b9a18 --- /dev/null +++ b/src/runtimes/ruby.rs @@ -0,0 +1,178 @@ +use bevy::{ + asset::Asset, + ecs::{component::Component, schedule::ScheduleLabel, system::Resource}, + reflect::TypePath, +}; +use serde::Deserialize; + +use crate::{ + assets::GetExtensions, + callback::{FromRuntimeValueWithEngine, IntoRuntimeValueWithEngine}, + FuncArgs, Runtime, +}; + +#[derive(Resource)] +pub struct RubyRuntime {} + +#[derive(ScheduleLabel, Clone, PartialEq, Eq, Debug, Hash, Default)] +pub struct RubySchedule; + +#[derive(Asset, Debug, Deserialize, TypePath)] +pub struct RubyScript(pub String); + +#[derive(Component)] +pub struct RubyScriptData; + +impl GetExtensions for RubyScript { + fn extensions() -> &'static [&'static str] { + todo!() + } +} + +impl From for RubyScript { + fn from(value: String) -> Self { + todo!() + } +} + +impl Default for RubyRuntime { + fn default() -> Self { + Self {} + } +} + +#[derive(Clone)] +pub struct RubyValue(()); + +impl Runtime for RubyRuntime { + type Schedule = RubySchedule; + + type ScriptAsset = RubyScript; + + type ScriptData = RubyScriptData; + + type CallContext = (); + + type Value = RubyValue; + + type RawEngine = (); + + fn with_engine_mut(&mut self, f: impl FnOnce(&mut Self::RawEngine) -> T) -> T { + todo!() + } + + fn with_engine(&self, f: impl FnOnce(&Self::RawEngine) -> T) -> T { + todo!() + } + + fn eval( + &self, + script: &Self::ScriptAsset, + entity: bevy::prelude::Entity, + ) -> Result { + todo!() + } + + fn register_fn( + &mut self, + name: String, + arg_types: Vec, + f: impl Fn( + Self::CallContext, + Vec, + ) -> Result< + crate::promise::Promise, + crate::ScriptingError, + > + Send + + Sync + + 'static, + ) -> Result<(), crate::ScriptingError> { + todo!() + } + + fn call_fn( + &self, + name: &str, + script_data: &mut Self::ScriptData, + entity: bevy::prelude::Entity, + args: impl for<'a> crate::FuncArgs<'a, Self::Value, Self>, + ) -> Result { + todo!() + } + + fn call_fn_from_value( + &self, + value: &Self::Value, + context: &Self::CallContext, + args: Vec, + ) -> Result { + todo!() + } +} + +pub mod prelude { + pub use super::RubyRuntime; +} + +impl FromRuntimeValueWithEngine<'_, RubyRuntime> for T { + fn from_runtime_value_with_engine(value: RubyValue, engine: &()) -> Self { + todo!(); + } +} + +impl IntoRuntimeValueWithEngine<'_, T, RubyRuntime> for T { + fn into_runtime_value_with_engine(value: T, engine: &()) -> RubyValue { + todo!(); + } +} + +impl FuncArgs<'_, RubyValue, RubyRuntime> for () { + fn parse(self, _engine: &()) -> Vec { + Vec::new() + } +} + +impl FuncArgs<'_, RubyValue, RubyRuntime> for Vec { + fn parse(self, engine: &()) -> Vec { + self.into_iter().map(|x| RubyValue(())).collect() + } +} + +macro_rules! impl_tuple { + ($($idx:tt $t:tt),+) => { + impl<'a, $($t,)+> FuncArgs<'a, RubyValue, RubyRuntime> + for ($($t,)+) + { + fn parse(self, engine: &'a ()) -> Vec { + todo!(); + } + } + }; +} + +impl_tuple!(0 A, 1 B, 2 C, 3 D, 4 E, 5 F, 6 G, 7 H, 8 I, 9 J, 10 K, 11 L, 12 M, 13 N, 14 O, 15 P, 16 Q, 17 R, 18 S, 19 T, 20 U, 21 V, 22 W, 23 X, 24 Y, 25 Z); +impl_tuple!(0 A, 1 B, 2 C, 3 D, 4 E, 5 F, 6 G, 7 H, 8 I, 9 J, 10 K, 11 L, 12 M, 13 N, 14 O, 15 P, 16 Q, 17 R, 18 S, 19 T, 20 U, 21 V, 22 W, 23 X, 24 Y); +impl_tuple!(0 A, 1 B, 2 C, 3 D, 4 E, 5 F, 6 G, 7 H, 8 I, 9 J, 10 K, 11 L, 12 M, 13 N, 14 O, 15 P, 16 Q, 17 R, 18 S, 19 T, 20 U, 21 V, 22 W, 23 X); +impl_tuple!(0 A, 1 B, 2 C, 3 D, 4 E, 5 F, 6 G, 7 H, 8 I, 9 J, 10 K, 11 L, 12 M, 13 N, 14 O, 15 P, 16 Q, 17 R, 18 S, 19 T, 20 U, 21 V, 22 W); +impl_tuple!(0 A, 1 B, 2 C, 3 D, 4 E, 5 F, 6 G, 7 H, 8 I, 9 J, 10 K, 11 L, 12 M, 13 N, 14 O, 15 P, 16 Q, 17 R, 18 S, 19 T, 20 U, 21 V); +impl_tuple!(0 A, 1 B, 2 C, 3 D, 4 E, 5 F, 6 G, 7 H, 8 I, 9 J, 10 K, 11 L, 12 M, 13 N, 14 O, 15 P, 16 Q, 17 R, 18 S, 19 T, 20 U); +impl_tuple!(0 A, 1 B, 2 C, 3 D, 4 E, 5 F, 6 G, 7 H, 8 I, 9 J, 10 K, 11 L, 12 M, 13 N, 14 O, 15 P, 16 Q, 17 R, 18 S, 19 T); +impl_tuple!(0 A, 1 B, 2 C, 3 D, 4 E, 5 F, 6 G, 7 H, 8 I, 9 J, 10 K, 11 L, 12 M, 13 N, 14 O, 15 P, 16 Q, 17 R, 18 S); +impl_tuple!(0 A, 1 B, 2 C, 3 D, 4 E, 5 F, 6 G, 7 H, 8 I, 9 J, 10 K, 11 L, 12 M, 13 N, 14 O, 15 P, 16 Q, 17 R); +impl_tuple!(0 A, 1 B, 2 C, 3 D, 4 E, 5 F, 6 G, 7 H, 8 I, 9 J, 10 K, 11 L, 12 M, 13 N, 14 O, 15 P, 16 Q); +impl_tuple!(0 A, 1 B, 2 C, 3 D, 4 E, 5 F, 6 G, 7 H, 8 I, 9 J, 10 K, 11 L, 12 M, 13 N, 14 O, 15 P); +impl_tuple!(0 A, 1 B, 2 C, 3 D, 4 E, 5 F, 6 G, 7 H, 8 I, 9 J, 10 K, 11 L, 12 M, 13 N, 14 O); +impl_tuple!(0 A, 1 B, 2 C, 3 D, 4 E, 5 F, 6 G, 7 H, 8 I, 9 J, 10 K, 11 L, 12 M, 13 N); +impl_tuple!(0 A, 1 B, 2 C, 3 D, 4 E, 5 F, 6 G, 7 H, 8 I, 9 J, 10 K, 11 L, 12 M); +impl_tuple!(0 A, 1 B, 2 C, 3 D, 4 E, 5 F, 6 G, 7 H, 8 I, 9 J, 10 K, 11 L); +impl_tuple!(0 A, 1 B, 2 C, 3 D, 4 E, 5 F, 6 G, 7 H, 8 I, 9 J, 10 K); +impl_tuple!(0 A, 1 B, 2 C, 3 D, 4 E, 5 F, 6 G, 7 H, 8 I, 9 J); +impl_tuple!(0 A, 1 B, 2 C, 3 D, 4 E, 5 F, 6 G, 7 H, 8 I); +impl_tuple!(0 A, 1 B, 2 C, 3 D, 4 E, 5 F, 6 G, 7 H); +impl_tuple!(0 A, 1 B, 2 C, 3 D, 4 E, 5 F, 6 G); +impl_tuple!(0 A, 1 B, 2 C, 3 D, 4 E, 5 F); +impl_tuple!(0 A, 1 B, 2 C, 3 D, 4 E); +impl_tuple!(0 A, 1 B, 2 C, 3 D); +impl_tuple!(0 A, 1 B, 2 C); +impl_tuple!(0 A, 1 B); +impl_tuple!(0 A); diff --git a/tests/tests.rs b/tests/tests.rs index 7dcf443..825e6ec 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -482,3 +482,32 @@ mod lua_tests { scripting_tests!(LuaRuntime, "lua", "lua"); } + +#[cfg(feature = "ruby")] +mod ruby_tests { + use bevy::prelude::*; + use bevy_scriptum::runtimes::ruby::{prelude::*, RubyScriptData}; + + impl AssertStateKeyValue for RubyRuntime { + type ScriptData = RubyScriptData; + + fn assert_state_key_value_i64(world: &World, _entity_id: Entity, key: &str, value: i64) { + todo!(); + } + + fn assert_state_key_value_i32(world: &World, _entity_id: Entity, key: &str, value: i32) { + todo!(); + } + + fn assert_state_key_value_string( + world: &World, + _entity_id: Entity, + key: &str, + value: &str, + ) { + todo!(); + } + } + + scripting_tests!(RubyRuntime, "ruby", "rb"); +}