diff --git a/assets/tests/ruby/rust_function_gets_called_from_script.rb b/assets/tests/ruby/rust_function_gets_called_from_script.rb index fc70a31..6edee25 100644 --- a/assets/tests/ruby/rust_function_gets_called_from_script.rb +++ b/assets/tests/ruby/rust_function_gets_called_from_script.rb @@ -1,3 +1,3 @@ def test_func() - rust_func() + rust_func end diff --git a/src/lib.rs b/src/lib.rs index 37fcc75..bc72d3e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -308,7 +308,10 @@ pub trait Runtime: Resource + Default { /// Provides immutable reference to raw scripting engine instance. /// Can be used to directly interact with an interpreter to use interfaces /// that bevy_scriptum does not provided adapters for. - fn with_engine(&self, f: impl FnOnce(&Self::RawEngine) -> T) -> T; + fn with_engine( + &self, + f: impl FnOnce(&Self::RawEngine) -> T + Send + 'static, + ) -> T; fn eval( &self, diff --git a/src/runtimes/ruby.rs b/src/runtimes/ruby.rs index ba09728..c9f4568 100644 --- a/src/runtimes/ruby.rs +++ b/src/runtimes/ruby.rs @@ -1,3 +1,4 @@ +// TODO: make sure ruby is statically linked use std::{ sync::LazyLock, thread::{self, JoinHandle}, @@ -115,7 +116,10 @@ impl Runtime for RubyRuntime { f(&mut magnus::Ruby::get().unwrap()) } - fn with_engine(&self, f: impl FnOnce(&Self::RawEngine) -> T) -> T { + fn with_engine( + &self, + f: impl FnOnce(&Self::RawEngine) -> T + Send + 'static, + ) -> T { RUBY_THREAD.execute_in(Box::new(move |ruby| f(&ruby))) } @@ -136,7 +140,7 @@ impl Runtime for RubyRuntime { &mut self, name: String, _arg_types: Vec, - _f: impl Fn( + f: impl Fn( Self::CallContext, Vec, ) -> Result< @@ -146,13 +150,17 @@ impl Runtime for RubyRuntime { + Sync + 'static, ) -> Result<(), crate::ScriptingError> { - fn callback(_val: magnus::Value) -> magnus::Value { + fn callback() -> magnus::Value { let ruby = magnus::Ruby::get().unwrap(); + let method_name: magnus::value::StaticSymbol = + ruby.class_object().funcall("__method__", ()).unwrap(); + let method_name = method_name.to_string(); + dbg!(method_name); ruby.qnil().as_value() } RUBY_THREAD.execute_in(Box::new(move |ruby| { - ruby.define_global_function(&name, function!(callback, 1)); + ruby.define_global_function(&name, function!(callback, 0)); RubyValue(()) })); @@ -168,7 +176,7 @@ impl Runtime for RubyRuntime { ) -> Result { let name = name.to_string(); RUBY_THREAD.execute_in(Box::new(move |ruby| { - let _: Result = ruby.class_object().funcall(name, ()); + let _: magnus::Value = ruby.class_object().funcall(name, ()).unwrap(); RubyValue(()) }));