Ruby support #1
6 changed files with 14 additions and 12 deletions
|
|
@ -1,3 +1,3 @@
|
||||||
def test_func
|
def test_func
|
||||||
print('abc' + 5)
|
raise
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,2 @@
|
||||||
mark_called
|
mark_called
|
||||||
# puts("foo" + 1)
|
raise
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
def test_func
|
def test_func
|
||||||
rust_func.and_then do |x|
|
rust_func.and_then do |x|
|
||||||
print('abc' + 5)
|
raise
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,12 @@ use std::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use ::magnus::value::Opaque;
|
use ::magnus::value::Opaque;
|
||||||
|
use anyhow::anyhow;
|
||||||
use bevy::{
|
use bevy::{
|
||||||
asset::Asset,
|
asset::Asset,
|
||||||
ecs::{component::Component, entity::Entity, resource::Resource, schedule::ScheduleLabel},
|
ecs::{component::Component, entity::Entity, resource::Resource, schedule::ScheduleLabel},
|
||||||
math::Vec3,
|
math::Vec3,
|
||||||
reflect::TypePath,
|
reflect::TypePath,
|
||||||
tasks::futures_lite::io,
|
|
||||||
};
|
};
|
||||||
use magnus::{
|
use magnus::{
|
||||||
DataType, DataTypeFunctions, IntoValue, Object, RClass, RModule, Ruby, TryConvert, TypedData,
|
DataType, DataTypeFunctions, IntoValue, Object, RClass, RModule, Ruby, TryConvert, TypedData,
|
||||||
|
|
@ -223,7 +223,7 @@ impl TryConvert for BevyVec3 {
|
||||||
|
|
||||||
impl From<magnus::Error> for ScriptingError {
|
impl From<magnus::Error> for ScriptingError {
|
||||||
fn from(value: magnus::Error) -> Self {
|
fn from(value: magnus::Error) -> Self {
|
||||||
ScriptingError::RuntimeError(Box::new(io::Error::other(value.to_string())))
|
ScriptingError::RuntimeError(anyhow!(value.to_string()).into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -373,13 +373,15 @@ impl Runtime for RubyRuntime {
|
||||||
|
|
||||||
var.ivar_set("_current", BevyEntity(entity))
|
var.ivar_set("_current", BevyEntity(entity))
|
||||||
.expect("Failed to set current entity handle");
|
.expect("Failed to set current entity handle");
|
||||||
let value = ruby.eval::<magnus::value::Value>(&script).unwrap();
|
|
||||||
|
ruby.eval::<magnus::value::Value>(&script)
|
||||||
|
.map_err(|e| ScriptingError::RuntimeError(anyhow!(e.to_string()).into()))?;
|
||||||
|
|
||||||
var.ivar_set("_current", ruby.qnil().as_value())
|
var.ivar_set("_current", ruby.qnil().as_value())
|
||||||
.expect("Failed to unset current entity handle");
|
.expect("Failed to unset current entity handle");
|
||||||
|
|
||||||
RubyValue::new(value)
|
Ok::<Self::ScriptData, ScriptingError>(RubyScriptData)
|
||||||
}));
|
}))
|
||||||
Ok(RubyScriptData)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn register_fn(
|
fn register_fn(
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
use bevy::{prelude::*, log::tracing};
|
use bevy::{log::tracing, prelude::*};
|
||||||
use std::{
|
use std::{
|
||||||
fmt::Display,
|
fmt::Display,
|
||||||
sync::{Arc, Mutex},
|
sync::{Arc, Mutex},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
Callback, Callbacks, Runtime, ScriptingError,
|
||||||
callback::FunctionCallEvent,
|
callback::FunctionCallEvent,
|
||||||
promise::{Promise, PromiseInner},
|
promise::{Promise, PromiseInner},
|
||||||
Callback, Callbacks, Runtime, ScriptingError,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::components::Script;
|
use super::components::Script;
|
||||||
|
|
|
||||||
|
|
@ -266,7 +266,7 @@ macro_rules! scripting_tests {
|
||||||
|| {},
|
|| {},
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_n_times_called!(app, 1);
|
assert_n_times_called!(app, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue