Skip to content

Commit bb3e18d

Browse files
committed
add error conversions for rhai
1 parent 7ee53aa commit bb3e18d

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ bevy_mod_scripting_common = { path = "crates/bevy_mod_scripting_common", version
7171
bevy_mod_scripting_functions = { path = "crates/bevy_mod_scripting_functions", version = "0.9.0-alpha.1"}
7272
test_utils = { path = "crates/test_utils" }
7373
mlua = { version = "0.10" }
74+
rhai = { version = "0.20" }
7475

7576
[dev-dependencies]
7677
bevy = { workspace = true, default-features = true }

crates/bevy_mod_scripting_core/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@ doc_always = []
2121

2222
# if enabled enables some common mlua trait implementations
2323
mlua_impls = ["mlua"]
24+
rhai_impls = ["rhai"]
2425

2526
[dependencies]
2627
mlua = { optional = true, workspace = true }
28+
rhai = { optional = true, workspace = true }
29+
2730
bevy = { workspace = true, default-features = false, features = [
2831
"bevy_asset",
2932
"reflect_functions",

crates/bevy_mod_scripting_core/src/error.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,27 @@ impl From<InteropError> for mlua::Error {
184184
}
185185
}
186186

187+
#[cfg(feature = "mlua_impls")]
188+
impl From<mlua::Error> for ScriptError {
189+
fn from(value: mlua::Error) -> Self {
190+
ScriptError::from_mlua_error(value)
191+
}
192+
}
193+
194+
#[cfg(feature = "rhai_impls")]
195+
impl From<rhai::ParseError> for ScriptError {
196+
fn from(value: rhai::ParseError) -> Self {
197+
ScriptError::new_external(value)
198+
}
199+
}
200+
201+
#[cfg(feature = "rhai_impls")]
202+
impl From<Box<rhai::EvalAltResult>> for ScriptError {
203+
fn from(value: Box<rhai::EvalAltResult>) -> Self {
204+
ScriptError::new_external(value)
205+
}
206+
}
207+
187208
#[derive(Debug, Clone, PartialEq, Reflect)]
188209
pub struct InteropError(#[reflect(ignore)] Arc<InteropErrorInner>);
189210

crates/languages/bevy_mod_scripting_rhai/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ path = "src/lib.rs"
1717

1818
[dependencies]
1919
bevy = { workspace = true, default-features = false }
20-
rhai = { version = "1.20.1", features = ["sync"] }
21-
bevy_mod_scripting_core = { workspace = true }
20+
rhai = { workspace = true, features = ["sync"] }
21+
bevy_mod_scripting_core = { workspace = true, features = ["rhai_impls"] }

0 commit comments

Comments
 (0)