ruby boilerplate
This commit is contained in:
parent
56fd44062c
commit
096710d118
4 changed files with 212 additions and 1 deletions
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -2,3 +2,5 @@
|
|||
pub mod lua;
|
||||
#[cfg(feature = "rhai")]
|
||||
pub mod rhai;
|
||||
#[cfg(feature = "ruby")]
|
||||
pub mod ruby;
|
||||
|
|
|
|||
178
src/runtimes/ruby.rs
Normal file
178
src/runtimes/ruby.rs
Normal file
|
|
@ -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<String> 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<T>(&mut self, f: impl FnOnce(&mut Self::RawEngine) -> T) -> T {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn with_engine<T>(&self, f: impl FnOnce(&Self::RawEngine) -> T) -> T {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn eval(
|
||||
&self,
|
||||
script: &Self::ScriptAsset,
|
||||
entity: bevy::prelude::Entity,
|
||||
) -> Result<Self::ScriptData, crate::ScriptingError> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn register_fn(
|
||||
&mut self,
|
||||
name: String,
|
||||
arg_types: Vec<std::any::TypeId>,
|
||||
f: impl Fn(
|
||||
Self::CallContext,
|
||||
Vec<Self::Value>,
|
||||
) -> Result<
|
||||
crate::promise::Promise<Self::CallContext, Self::Value>,
|
||||
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<Self::Value, crate::ScriptingError> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn call_fn_from_value(
|
||||
&self,
|
||||
value: &Self::Value,
|
||||
context: &Self::CallContext,
|
||||
args: Vec<Self::Value>,
|
||||
) -> Result<Self::Value, crate::ScriptingError> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
pub mod prelude {
|
||||
pub use super::RubyRuntime;
|
||||
}
|
||||
|
||||
impl<T> FromRuntimeValueWithEngine<'_, RubyRuntime> for T {
|
||||
fn from_runtime_value_with_engine(value: RubyValue, engine: &()) -> Self {
|
||||
todo!();
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> 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<RubyValue> {
|
||||
Vec::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> FuncArgs<'_, RubyValue, RubyRuntime> for Vec<T> {
|
||||
fn parse(self, engine: &()) -> Vec<RubyValue> {
|
||||
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<RubyValue> {
|
||||
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);
|
||||
|
|
@ -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");
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue