Compare commits
No commits in common. "b339283901acf09623f3cb2df918c3fdcc134605" and "469e9aca15dcd2f3bf78dfaceb57761ee4a56751" have entirely different histories.
b339283901
...
469e9aca15
8 changed files with 23 additions and 76 deletions
|
|
@ -120,7 +120,7 @@ Add the following to your `Cargo.toml`:
|
|||
|
||||
```toml
|
||||
[dependencies]
|
||||
bevy_scriptum = { version = "0.8", features = ["lua"] }
|
||||
bevy_scriptum = { version = "0.7", features = ["lua"] }
|
||||
```
|
||||
|
||||
or execute `cargo add bevy_scriptum --features lua` from your project directory.
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
def test_func
|
||||
raise
|
||||
print('abc' + 5)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,2 +0,0 @@
|
|||
mark_called
|
||||
raise
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
def test_func
|
||||
rust_func.and_then do |x|
|
||||
raise
|
||||
print('abc' + 5)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
15
src/lib.rs
15
src/lib.rs
|
|
@ -21,10 +21,8 @@
|
|||
//! ```no_run
|
||||
//! use bevy::prelude::*;
|
||||
//! use bevy_scriptum::prelude::*;
|
||||
//! # #[cfg(feature = "lua")]
|
||||
//! use bevy_scriptum::runtimes::lua::prelude::*;
|
||||
//!
|
||||
//! # #[cfg(feature = "lua")]
|
||||
//! App::new()
|
||||
//! .add_plugins(DefaultPlugins)
|
||||
//! .add_scripting::<LuaRuntime>(|runtime| {
|
||||
|
|
@ -44,13 +42,11 @@
|
|||
//! ```no_run
|
||||
//! use bevy::prelude::*;
|
||||
//! use bevy_scriptum::prelude::*;
|
||||
//! # #[cfg(feature = "lua")]
|
||||
//! use bevy_scriptum::runtimes::lua::prelude::*;
|
||||
//!
|
||||
//! #[derive(Component)]
|
||||
//! struct Player;
|
||||
//!
|
||||
//! # #[cfg(feature = "lua")]
|
||||
//! App::new()
|
||||
//! .add_plugins(DefaultPlugins)
|
||||
//! .add_scripting::<LuaRuntime>(|runtime| {
|
||||
|
|
@ -70,10 +66,8 @@
|
|||
//! ```no_run
|
||||
//! use bevy::prelude::*;
|
||||
//! use bevy_scriptum::prelude::*;
|
||||
//! # #[cfg(feature = "lua")]
|
||||
//! use bevy_scriptum::runtimes::lua::prelude::*;
|
||||
//!
|
||||
//! # #[cfg(feature = "lua")]
|
||||
//! App::new()
|
||||
//! .add_plugins(DefaultPlugins)
|
||||
//! .add_scripting::<LuaRuntime>(|runtime| {
|
||||
|
|
@ -95,11 +89,9 @@
|
|||
//! ```no_run
|
||||
//! use bevy::prelude::*;
|
||||
//! use bevy_scriptum::prelude::*;
|
||||
//! # #[cfg(feature = "lua")]
|
||||
//! use bevy_scriptum::runtimes::lua::prelude::*;
|
||||
//!
|
||||
//! struct MyPlugin;
|
||||
//! # #[cfg(feature = "lua")]
|
||||
//! impl Plugin for MyPlugin {
|
||||
//! fn build(&self, app: &mut App) {
|
||||
//! app.add_scripting_api::<LuaRuntime>(|runtime| {
|
||||
|
|
@ -110,7 +102,6 @@
|
|||
//! }
|
||||
//! }
|
||||
//!
|
||||
//! # #[cfg(feature = "lua")]
|
||||
//! App::new()
|
||||
//! .add_plugins(DefaultPlugins)
|
||||
//! .add_scripting::<LuaRuntime>(|_| {
|
||||
|
|
@ -137,10 +128,8 @@
|
|||
//! ```no_run
|
||||
//! use bevy::prelude::*;
|
||||
//! use bevy_scriptum::prelude::*;
|
||||
//! # #[cfg(feature = "lua")]
|
||||
//! use bevy_scriptum::runtimes::lua::prelude::*;
|
||||
//!
|
||||
//! # #[cfg(feature = "lua")]
|
||||
//! App::new()
|
||||
//! .add_plugins(DefaultPlugins)
|
||||
//! .add_scripting::<LuaRuntime>(|runtime| {
|
||||
|
|
@ -165,10 +154,8 @@
|
|||
//! ```no_run
|
||||
//! use bevy::prelude::*;
|
||||
//! use bevy_scriptum::prelude::*;
|
||||
//! # #[cfg(feature = "lua")]
|
||||
//! use bevy_scriptum::runtimes::lua::prelude::*;
|
||||
//!
|
||||
//! # #[cfg(feature = "lua")]
|
||||
//! App::new()
|
||||
//! .add_plugins(DefaultPlugins)
|
||||
//! .add_scripting::<LuaRuntime>(|runtime| {
|
||||
|
|
@ -222,10 +209,8 @@
|
|||
//! ```
|
||||
//! use bevy::prelude::*;
|
||||
//! use bevy_scriptum::prelude::*;
|
||||
//! # #[cfg(feature = "lua")]
|
||||
//! use bevy_scriptum::runtimes::lua::prelude::*;
|
||||
//!
|
||||
//! # #[cfg(feature = "lua")]
|
||||
//! App::new()
|
||||
//! .add_plugins(DefaultPlugins)
|
||||
//! .add_scripting::<LuaRuntime>(|runtime| {
|
||||
|
|
|
|||
|
|
@ -6,12 +6,12 @@ use std::{
|
|||
};
|
||||
|
||||
use ::magnus::value::Opaque;
|
||||
use anyhow::anyhow;
|
||||
use bevy::{
|
||||
asset::Asset,
|
||||
ecs::{component::Component, entity::Entity, resource::Resource, schedule::ScheduleLabel},
|
||||
math::Vec3,
|
||||
reflect::TypePath,
|
||||
tasks::futures_lite::io,
|
||||
};
|
||||
use magnus::{
|
||||
DataType, DataTypeFunctions, IntoValue, Object, RClass, RModule, Ruby, TryConvert, TypedData,
|
||||
|
|
@ -223,7 +223,7 @@ impl TryConvert for BevyVec3 {
|
|||
|
||||
impl From<magnus::Error> for ScriptingError {
|
||||
fn from(value: magnus::Error) -> Self {
|
||||
ScriptingError::RuntimeError(anyhow!(value.to_string()).into())
|
||||
ScriptingError::RuntimeError(Box::new(io::Error::other(value.to_string())))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -373,15 +373,13 @@ impl Runtime for RubyRuntime {
|
|||
|
||||
var.ivar_set("_current", BevyEntity(entity))
|
||||
.expect("Failed to set current entity handle");
|
||||
|
||||
ruby.eval::<magnus::value::Value>(&script)
|
||||
.map_err(|e| ScriptingError::RuntimeError(anyhow!(e.to_string()).into()))?;
|
||||
|
||||
let value = ruby.eval::<magnus::value::Value>(&script).unwrap();
|
||||
var.ivar_set("_current", ruby.qnil().as_value())
|
||||
.expect("Failed to unset current entity handle");
|
||||
|
||||
Ok::<Self::ScriptData, ScriptingError>(RubyScriptData)
|
||||
}))
|
||||
RubyValue::new(value)
|
||||
}));
|
||||
Ok(RubyScriptData)
|
||||
}
|
||||
|
||||
fn register_fn(
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
use bevy::{log::tracing, prelude::*};
|
||||
use bevy::{prelude::*, log::tracing};
|
||||
use std::{
|
||||
fmt::Display,
|
||||
sync::{Arc, Mutex},
|
||||
};
|
||||
|
||||
use crate::{
|
||||
Callback, Callbacks, Runtime, ScriptingError,
|
||||
callback::FunctionCallEvent,
|
||||
promise::{Promise, PromiseInner},
|
||||
Callback, Callbacks, Runtime, ScriptingError,
|
||||
};
|
||||
|
||||
use super::components::Script;
|
||||
|
|
|
|||
|
|
@ -11,24 +11,6 @@ use bevy_scriptum::{FuncArgs, Runtime, prelude::*};
|
|||
#[cfg(any(feature = "rhai", feature = "lua", feature = "ruby"))]
|
||||
static TRACING_SUBSCRIBER: OnceLock<()> = OnceLock::new();
|
||||
|
||||
#[cfg(any(feature = "rhai", feature = "lua", feature = "ruby"))]
|
||||
#[derive(Default, Resource)]
|
||||
struct TimesCalled {
|
||||
times_called: u8,
|
||||
}
|
||||
|
||||
macro_rules! assert_n_times_called {
|
||||
($app: expr, $count: expr) => {
|
||||
assert_eq!(
|
||||
$app.world()
|
||||
.get_resource::<TimesCalled>()
|
||||
.unwrap()
|
||||
.times_called,
|
||||
$count
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "rhai", feature = "lua", feature = "ruby"))]
|
||||
fn build_test_app() -> App {
|
||||
let mut app = App::new();
|
||||
|
|
@ -242,33 +224,6 @@ macro_rules! scripting_tests {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn eval_that_casues_runtime_error_doesnt_panic() {
|
||||
let mut app = build_test_app();
|
||||
|
||||
app.add_scripting::<$runtime>(|r| {
|
||||
r.add_function(
|
||||
String::from("mark_called"),
|
||||
|mut times_called: ResMut<TimesCalled>| {
|
||||
times_called.times_called += 1;
|
||||
},
|
||||
);
|
||||
})
|
||||
.init_resource::<TimesCalled>();
|
||||
|
||||
run_script::<$runtime, _, _>(
|
||||
&mut app,
|
||||
format!(
|
||||
"tests/{}/eval_that_causes_runtime_error.{}",
|
||||
$script, $extension
|
||||
)
|
||||
.to_string(),
|
||||
|| {},
|
||||
);
|
||||
|
||||
assert_n_times_called!(app, 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn call_script_function_that_casues_runtime_error() {
|
||||
let mut app = build_test_app();
|
||||
|
|
@ -392,6 +347,11 @@ macro_rules! scripting_tests {
|
|||
fn rust_function_gets_called_from_script() {
|
||||
let mut app = build_test_app();
|
||||
|
||||
#[derive(Default, Resource)]
|
||||
struct TimesCalled {
|
||||
times_called: u8,
|
||||
}
|
||||
|
||||
app.world_mut().init_resource::<TimesCalled>();
|
||||
|
||||
app.add_scripting::<$runtime>(|runtime| {
|
||||
|
|
@ -410,7 +370,13 @@ macro_rules! scripting_tests {
|
|||
call_script_on_update_from_rust::<$runtime>,
|
||||
);
|
||||
|
||||
assert_n_times_called!(app, 1);
|
||||
assert_eq!(
|
||||
app.world()
|
||||
.get_resource::<TimesCalled>()
|
||||
.unwrap()
|
||||
.times_called,
|
||||
1
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
Loading…
Reference in a new issue