Ruby support #1

Open
jaroslaw wants to merge 165 commits from ruby into main
Showing only changes of commit 8e7f15ed73 - Show all commits

View file

@ -23,8 +23,8 @@ use bevy::{
tasks::futures_lite::io, tasks::futures_lite::io,
}; };
use magnus::{ use magnus::{
data_type_builder, function, method::ReturnValue, try_convert, value::Lazy, DataType, block::Proc, data_type_builder, function, method::ReturnValue, try_convert, value::Lazy,
DataTypeFunctions, IntoValue, RClass, RObject, Ruby, TryConvert, TypedData, DataType, DataTypeFunctions, IntoValue, RClass, RObject, Ruby, TryConvert, TypedData,
}; };
use magnus::{prelude::*, rb_sys::FromRawValue}; use magnus::{prelude::*, rb_sys::FromRawValue};
use rb_sys::{rb_define_global_function, rb_scan_args, VALUE}; use rb_sys::{rb_define_global_function, rb_scan_args, VALUE};
@ -129,7 +129,6 @@ unsafe impl TypedData for Promise<(), RubyValue> {
fn then(r_self: magnus::Value, callback: magnus::Value) -> magnus::Value { fn then(r_self: magnus::Value, callback: magnus::Value) -> magnus::Value {
let promise: &Promise<(), RubyValue> = TryConvert::try_convert(r_self).unwrap(); let promise: &Promise<(), RubyValue> = TryConvert::try_convert(r_self).unwrap();
let ruby = Ruby::get().unwrap();
promise.clone().then(RubyValue::new(callback)).into_value() promise.clone().then(RubyValue::new(callback)).into_value()
} }
@ -356,17 +355,21 @@ impl Runtime for RubyRuntime {
_context: &Self::CallContext, _context: &Self::CallContext,
args: Vec<Self::Value>, args: Vec<Self::Value>,
) -> Result<Self::Value, crate::ScriptingError> { ) -> Result<Self::Value, crate::ScriptingError> {
let ruby = Ruby::get().unwrap(); let value = value.clone(); // TODO: maybe just clone/wrap where we added Send + static
// currently?>
self.ruby_thread
.as_ref()
.unwrap()
.execute(Box::new(move |ruby| {
let f: Proc = TryConvert::try_convert(ruby.get_inner(value.0)).unwrap();
let f: RObject = TryConvert::try_convert(ruby.get_inner(value.0)).unwrap(); let args: Vec<_> = args
let result: magnus::Value = f.funcall("call", ()).unwrap(); .into_iter()
Ok(RubyValue::new(result)) .map(|x| ruby.get_inner(x.0).as_value())
// self.ruby_thread .collect();
// .as_ref() let result: magnus::Value = f.funcall("call", args.as_slice()).unwrap();
// .unwrap() Ok(RubyValue::new(result))
// .execute(Box::new(move |ruby| { }))
// todo!();
// }))
} }
fn is_current_thread() -> bool { fn is_current_thread() -> bool {