diff --git a/CHANGELOG.md b/CHANGELOG.md index cd6a6e1a..556b22fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,16 +7,12 @@ Version 1.3.0 Compiler requirement -------------------- -* Minimum compiler version is bumped to 1.51. - -Bug fixes ---------- - -* BLOB's no longer panic when accessed with an out-of-bounds index. +* Minimum compiler version is now 1.51. New features ------------ +* `BLOB` (essentially a byte array) is added as a supported primitive value type parallel to arrays. * New options for `Engine` which allows disabling `if`-expressions, `switch`-expressions, statement expressions, anonymous functions and/or looping (i.e. `while`, `loop`, `do` and `for` statements): * `Engine::set_allow_if_expression` * `Engine::set_allow_switch_expression` @@ -30,7 +26,6 @@ Enhancements * Added `into_array` and `into_typed_array` for `Dynamic`. * Added `FnPtr::call` and `FnPtr::call_within_context` to simplify calling a function pointer. -* BLob's can now be deserialized (using `from_dynamic`) into `Vec` via [`serde_bytes`](https://crates.io/crates/serde_bytes). * A function's hashes are included in its JSON metadata to assist in debugging. Each function's `hashBase` field in the JSON object should map directly to the pre-calculated hash in the function call. * `Expression` now derefs to `Expr`. diff --git a/src/engine.rs b/src/engine.rs index 512aa7b0..47dcade6 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -637,7 +637,7 @@ impl<'a> Target<'a> { let index = *index; if index < value.len() { - value[index] = (new_byte & 0x000f) as u8; + value[index] = (new_byte & 0x00ff) as u8; } else { unreachable!("blob index out of bounds: {}", index); } diff --git a/src/packages/blob_basic.rs b/src/packages/blob_basic.rs index dde3d60f..a0dcd40c 100644 --- a/src/packages/blob_basic.rs +++ b/src/packages/blob_basic.rs @@ -48,7 +48,7 @@ mod blob_functions { } let mut blob = Blob::new(); - blob.resize(len, (value & 0x000f) as u8); + blob.resize(len, (value & 0x00ff) as u8); Ok(blob) } #[rhai_fn(name = "len", get = "len", pure)] @@ -57,7 +57,7 @@ mod blob_functions { } #[rhai_fn(name = "push", name = "+=")] pub fn push(blob: &mut Blob, item: INT) { - let item = (item & 0x000f) as u8; + let item = (item & 0x00ff) as u8; blob.push(item); } #[rhai_fn(name = "append", name = "+=")] @@ -82,7 +82,7 @@ mod blob_functions { blob } pub fn insert(blob: &mut Blob, position: INT, item: INT) { - let item = (item & 0x000f) as u8; + let item = (item & 0x00ff) as u8; if blob.is_empty() { blob.push(item); @@ -113,7 +113,7 @@ mod blob_functions { return Ok(()); } - let item = (item & 0x000f) as u8; + let item = (item & 0x00ff) as u8; let _ctx = ctx; // Check if blob will be over max size limit diff --git a/tests/blobs.rs b/tests/blobs.rs index 8f42eb56..f350b26a 100644 --- a/tests/blobs.rs +++ b/tests/blobs.rs @@ -63,6 +63,14 @@ fn test_blobs() -> Result<(), Box> { engine.eval_with_scope::(&mut orig_scope.clone(), "x + x")?, [1, 2, 3, 1, 2, 3] ); + assert_eq!( + engine.eval_with_scope::(&mut orig_scope.clone(), "x += 999; x")?, + [1, 2, 3, 0xe7] + ); + assert_eq!( + engine.eval_with_scope::(&mut orig_scope.clone(), "x[2] = 999; x")?, + [1, 2, 0xe7] + ); Ok(()) }