Ruby support #1

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

View file

@ -72,7 +72,7 @@ impl RubyThread {
let handle = thread::spawn(move || { let handle = thread::spawn(move || {
let _cleanup = unsafe { magnus::embed::init() }; let _cleanup = unsafe { magnus::embed::init() };
while let Ok(f) = receiver.recv() { while let Ok(f) = receiver.recv() {
let ruby = Ruby::get().unwrap(); let ruby = Ruby::get().expect("Failed to get a handle to Ruby API");
f(ruby); f(ruby);
} }
}); });
@ -87,17 +87,21 @@ impl RubyThread {
let (return_sender, return_receiver) = crossbeam_channel::bounded(0); let (return_sender, return_receiver) = crossbeam_channel::bounded(0);
self.sender self.sender
.send(Box::new(move |ruby| { .send(Box::new(move |ruby| {
return_sender.send(f(ruby)).unwrap(); return_sender
.send(f(ruby))
.expect("Failed to send callback return value");
})) }))
.unwrap(); .unwrap();
return_receiver.recv().unwrap() return_receiver
.recv()
.expect("Faild to send execution unit to Ruby thread")
} }
} }
impl Drop for RubyThread { impl Drop for RubyThread {
fn drop(&mut self) { fn drop(&mut self) {
let handle = self.handle.take().unwrap(); let handle = self.handle.take().unwrap();
handle.join().unwrap(); handle.join().expect("Failed to join Ruby thread");
} }
} }
@ -377,7 +381,7 @@ impl Runtime for RubyRuntime {
} }
pub mod prelude { pub mod prelude {
pub use super::RubyRuntime; pub use super::{RubyRuntime, RubyScript, RubyScriptData};
} }
impl<T: TryConvert> FromRuntimeValueWithEngine<'_, RubyRuntime> for T { impl<T: TryConvert> FromRuntimeValueWithEngine<'_, RubyRuntime> for T {