Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests. #842

Merged
merged 7 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ doc/rhai.json
.idea/
.idea
.idea/*
src/eval/chaining.rs
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Enhancements
* Array/BLOB/string iterators are defined also within the `BasicIteratorPackage` in addition to the regular array/BLOB/string packages.
* `LexError::Runtime` is added for use with `Engine::on_parse_token`.
* Shared values under `sync` are now handled more elegantly -- instead of deadlocking and hanging indefinitely, it spins for a number of tries (waiting one second between each), then errors out.
* `parse_json` is also available without the `metadata` or `serde` feature -- it uses `Engine::parse_json` to parse the JSON text.


Version 1.17.2
Expand Down
2 changes: 1 addition & 1 deletion src/api/call_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ impl Engine {
if self.is_debugger_registered() {
global.debugger_mut().status = crate::eval::DebuggerStatus::Terminate;
let node = &crate::ast::Stmt::Noop(Position::NONE);
self.run_debugger(global, caches, scope, this_ptr, node)?;
self.dbg(global, caches, scope, this_ptr, node)?;
}

#[cfg(not(feature = "no_module"))]
Expand Down
2 changes: 1 addition & 1 deletion src/api/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ impl Engine {
if self.is_debugger_registered() {
global.debugger_mut().status = crate::eval::DebuggerStatus::Terminate;
let node = &crate::ast::Stmt::Noop(Position::NONE);
self.run_debugger(global, caches, scope, None, node)?;
self.dbg(global, caches, scope, None, node)?;
}

Ok(r)
Expand Down
85 changes: 82 additions & 3 deletions src/api/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,13 +348,55 @@ impl Engine {
///
/// ## Raising errors
///
/// Return `Err(...)` if there is an error, usually [`EvalAltResult::ErrorPropertyNotFound`][crate::EvalAltResult::ErrorPropertyNotFound].
/// Return `Err(...)` if there is an error, usually
/// [`EvalAltResult::ErrorPropertyNotFound`][crate::EvalAltResult::ErrorPropertyNotFound].
///
/// # Example
///
/// ```
/// # fn main() -> Result<(), Box<rhai::EvalAltResult>> {
/// # use rhai::{Engine, Dynamic, EvalAltResult, Position};
/// let mut engine = Engine::new();
///
/// engine.on_invalid_array_index(|arr, index, _| match index
/// {
/// -100 => {
/// // The array can be modified in place
/// arr.push((42_i64).into());
/// // Return a mutable reference to an element
/// let value_ref = arr.last_mut().unwrap();
/// Ok(value_ref.into())
/// }
/// 100 => {
/// let value = Dynamic::from(100_i64);
/// // Return a temporary value (not a reference)
/// Ok(value.into())
/// }
/// // Return the standard out-of-bounds error
/// _ => Err(EvalAltResult::ErrorArrayBounds(
/// arr.len(), index, Position::NONE
/// ).into()),
/// });
///
/// let r = engine.eval::<i64>("
/// let a = [1, 2, 3];
/// a[-100] += 1;
/// a[3] + a[100]
/// ")?;
///
/// assert_eq!(r, 143);
/// # Ok(()) }
/// ```
#[cfg(not(feature = "no_index"))]
#[cfg(feature = "internals")]
#[inline(always)]
pub fn on_invalid_array_index(
&mut self,
callback: impl for<'a> Fn(&'a mut crate::Array, crate::INT) -> RhaiResultOf<crate::Target<'a>>
callback: impl for<'a> Fn(
&'a mut crate::Array,
crate::INT,
EvalContext,
) -> RhaiResultOf<crate::Target<'a>>
+ SendSync
+ 'static,
) -> &mut Self {
Expand Down Expand Up @@ -385,12 +427,49 @@ impl Engine {
/// ## Raising errors
///
/// Return `Err(...)` if there is an error, usually [`EvalAltResult::ErrorPropertyNotFound`][crate::EvalAltResult::ErrorPropertyNotFound].
///
/// # Example
///
/// ```
/// # fn main() -> Result<(), Box<rhai::EvalAltResult>> {
/// # use rhai::{Engine, Dynamic, EvalAltResult, Position};
/// let mut engine = Engine::new();
///
/// engine.on_map_missing_property(|map, prop, _| match prop
/// {
/// "x" => {
/// // The object-map can be modified in place
/// map.insert("y".into(), (42_i64).into());
/// // Return a mutable reference to an element
/// let value_ref = map.get_mut("y").unwrap();
/// Ok(value_ref.into())
/// }
/// "z" => {
/// // Return a temporary value (not a reference)
/// let value = Dynamic::from(100_i64);
/// Ok(value.into())
/// }
/// // Return the standard property-not-found error
/// _ => Err(EvalAltResult::ErrorPropertyNotFound(
/// prop.to_string(), Position::NONE
/// ).into()),
/// });
///
/// let r = engine.eval::<i64>("
/// let obj = #{ a:1, b:2 };
/// obj.x += 1;
/// obj.y + obj.z
/// ")?;
///
/// assert_eq!(r, 143);
/// # Ok(()) }
/// ```
#[cfg(not(feature = "no_object"))]
#[cfg(feature = "internals")]
#[inline(always)]
pub fn on_map_missing_property(
&mut self,
callback: impl for<'a> Fn(&'a mut crate::Map, &str) -> RhaiResultOf<crate::Target<'a>>
callback: impl for<'a> Fn(&'a mut crate::Map, &str, EvalContext) -> RhaiResultOf<crate::Target<'a>>
+ SendSync
+ 'static,
) -> &mut Self {
Expand Down
2 changes: 1 addition & 1 deletion src/api/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ impl Engine {
if self.is_debugger_registered() {
global.debugger_mut().status = crate::eval::DebuggerStatus::Terminate;
let node = &crate::ast::Stmt::Noop(crate::Position::NONE);
self.run_debugger(global, caches, scope, None, node)?;
self.dbg(global, caches, scope, None, node)?;
}

Ok(())
Expand Down
Loading
Loading