From 0c4063880897eb5041f16da873fbf5871f40ec4b Mon Sep 17 00:00:00 2001 From: Duy Do Date: Sat, 25 Nov 2023 23:59:21 +0700 Subject: [PATCH 1/9] indexmap --- Cargo.toml | 3 +++ src/lib.rs | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index fa867df0f..e929efebb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,6 +38,7 @@ getrandom = { version = "0.2.0", optional = true } rustyline = { version = "12.0.0", optional = true } document-features = { version = "0.2.0", optional = true } arbitrary = { version = "1.3.2", optional = true, features = ["derive"] } +indexmap = { version = "2.1.0", optional = true } [dev-dependencies] rmp-serde = "1.1.0" @@ -54,6 +55,8 @@ std = ["once_cell/std", "ahash/std", "num-traits/std", "smartstring/std"] ## Require that all data types implement `Send + Sync` (for multi-threaded usage). sync = [] +## Use IndexMap as Map type +indexmap = ["dep:indexmap"] ## Add support for the [`Decimal`](https://crates.io/crates/rust_decimal) data type (acts as the system floating-point type under `no_float`). decimal = ["rust_decimal"] ## Enable serialization/deserialization of Rhai data types via [`serde`](https://crates.io/crates/serde). diff --git a/src/lib.rs b/src/lib.rs index 1c58fc4a1..31831ed1e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -313,6 +313,17 @@ pub type Blob = Vec; /// [`SmartString`](https://crates.io/crates/smartstring) is used as the key type because most /// property names are ASCII and short, fewer than 23 characters, so they can be stored inline. #[cfg(not(feature = "no_object"))] +#[cfg(feature = "indexmap")] +pub type Map = std::collections::BTreeMap; + +/// A dictionary of [`Dynamic`] values with string keys. +/// +/// Not available under `no_object`. +/// +/// [`SmartString`](https://crates.io/crates/smartstring) is used as the key type because most +/// property names are ASCII and short, fewer than 23 characters, so they can be stored inline. +#[cfg(not(feature = "no_object"))] +#[cfg(not(feature = "indexmap"))] pub type Map = std::collections::BTreeMap; #[cfg(not(feature = "no_object"))] From 1fce1c538a6a7c0bf1cffd1a1809aec906b43c21 Mon Sep 17 00:00:00 2001 From: Duy Do Date: Sun, 26 Nov 2023 00:49:30 +0700 Subject: [PATCH 2/9] implement IndexMap --- src/ast/expr.rs | 13 +++++++++++++ src/eval/expr.rs | 32 ++++++++++++++++++++++++++++++++ src/lib.rs | 2 +- src/types/dynamic.rs | 29 +++++++++++++++++++++++++++++ 4 files changed, 75 insertions(+), 1 deletion(-) diff --git a/src/ast/expr.rs b/src/ast/expr.rs index 4fc172288..568582de2 100644 --- a/src/ast/expr.rs +++ b/src/ast/expr.rs @@ -476,6 +476,7 @@ impl Expr { } #[cfg(not(feature = "no_object"))] + #[cfg(not(feature = "indexmap"))] Self::Map(x, ..) if self.is_constant() => { let mut map = x.1.clone(); @@ -486,6 +487,18 @@ impl Expr { Dynamic::from_map(map) } + #[cfg(not(feature = "no_object"))] + #[cfg(feature = "indexmap")] + Self::Map(x, ..) if self.is_constant() => { + let mut map = crate::Map::with_capacity(x.0.len()); + + for (k, v) in &x.0 { + map.insert(k.as_str().into(), v.get_literal_value().unwrap()); + } + + Dynamic::from_map(map) + } + // Interpolated string Self::InterpolatedString(x, ..) if self.is_constant() => { let mut s = SmartString::new_const(); diff --git a/src/eval/expr.rs b/src/eval/expr.rs index 444e690e5..a56b36da6 100644 --- a/src/eval/expr.rs +++ b/src/eval/expr.rs @@ -315,6 +315,7 @@ impl Engine { } #[cfg(not(feature = "no_object"))] + #[cfg(not(feature = "indexmap"))] Expr::Map(x, ..) => { let mut map = x.1.clone(); @@ -344,6 +345,37 @@ impl Engine { Ok(Dynamic::from_map(map)) } + #[cfg(not(feature = "no_object"))] + #[cfg(feature = "indexmap")] + Expr::Map(x, ..) => { + let mut map = crate::Map::with_capacity(x.0.len()); + + #[cfg(not(feature = "unchecked"))] + let mut total_data_sizes = (0, 0, 0); + + for (key, value_expr) in &x.0 { + let value = self + .eval_expr(global, caches, scope, this_ptr.as_deref_mut(), value_expr)? + .flatten(); + + #[cfg(not(feature = "unchecked"))] + if self.has_data_size_limit() { + let delta = crate::eval::calc_data_sizes(&value, true); + total_data_sizes = ( + total_data_sizes.0 + delta.0, + total_data_sizes.1 + delta.1 + 1, + total_data_sizes.2 + delta.2, + ); + self.throw_on_size(total_data_sizes) + .map_err(|err| err.fill_position(value_expr.position()))?; + } + + map.insert(key.as_str().into(), value); + } + + Ok(Dynamic::from_map(map)) + } + Expr::And(x, ..) => Ok((self .eval_expr(global, caches, scope, this_ptr.as_deref_mut(), &x.lhs)? .as_bool() diff --git a/src/lib.rs b/src/lib.rs index 31831ed1e..670a295ed 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -314,7 +314,7 @@ pub type Blob = Vec; /// property names are ASCII and short, fewer than 23 characters, so they can be stored inline. #[cfg(not(feature = "no_object"))] #[cfg(feature = "indexmap")] -pub type Map = std::collections::BTreeMap; +pub type Map = indexmap::IndexMap; /// A dictionary of [`Dynamic`] values with string keys. /// diff --git a/src/types/dynamic.rs b/src/types/dynamic.rs index b6c33151e..66ce1ffed 100644 --- a/src/types/dynamic.rs +++ b/src/types/dynamic.rs @@ -386,6 +386,14 @@ impl Dynamic { } } +fn hash_indexmap(m: &Box, state: &mut H) { + let mut m = m.iter().collect::>(); + m.sort_unstable_by_key(|x| x.0); + for kv in m.into_iter() { + kv.hash(state); + } +} + impl Hash for Dynamic { /// Hash the [`Dynamic`] value. /// @@ -410,7 +418,11 @@ impl Hash for Dynamic { #[cfg(not(feature = "no_index"))] Union::Blob(ref a, ..) => a.hash(state), #[cfg(not(feature = "no_object"))] + #[cfg(not(feature = "indexmap"))] Union::Map(ref m, ..) => m.hash(state), + #[cfg(not(feature = "no_object"))] + #[cfg(feature = "indexmap")] + Union::Map(ref m, ..) => hash_indexmap(m, state), Union::FnPtr(ref f, ..) => f.hash(state), #[cfg(not(feature = "no_closure"))] @@ -2217,6 +2229,23 @@ impl, T: Variant + Clone> From, T: Variant + Clone> From> for Dynamic { + #[inline] + fn from(value: indexmap::IndexMap) -> Self { + Self(Union::Map( + Box::new( + value + .into_iter() + .map(|(k, v)| (k.into(), Self::from(v))) + .collect(), + ), + DEFAULT_TAG_VALUE, + ReadWrite, + )) + } +} +#[cfg(not(feature = "no_object"))] impl> From> for Dynamic { #[inline] fn from(value: std::collections::BTreeSet) -> Self { From 6532d848084474cb067b6bb28ab9187d9222c302 Mon Sep 17 00:00:00 2001 From: Duy Do Date: Wed, 14 Feb 2024 15:54:27 +0700 Subject: [PATCH 3/9] Fix --- Cargo.toml | 8 ++++---- benches/engine.rs | 4 ++-- benches/eval_array.rs | 2 +- benches/eval_expression.rs | 2 +- benches/eval_map.rs | 2 +- benches/eval_module.rs | 2 +- benches/eval_scope.rs | 2 +- benches/eval_type.rs | 2 +- benches/iterations.rs | 2 +- benches/parsing.rs | 2 +- benches/primes.rs | 2 +- codegen/Cargo.toml | 4 ++-- examples/arrays_and_structs.rs | 2 +- examples/callback.rs | 2 +- examples/custom_types.rs | 2 +- examples/custom_types_and_methods.rs | 2 +- examples/definitions/main.rs | 4 ++-- examples/event_handler_js/main.rs | 2 +- examples/event_handler_main/main.rs | 2 +- examples/event_handler_map/main.rs | 2 +- examples/hello.rs | 2 +- examples/pause_and_resume.rs | 2 +- examples/reuse_scope.rs | 2 +- examples/serde.rs | 4 ++-- examples/simple_fn.rs | 2 +- examples/strings.rs | 2 +- examples/threading.rs | 2 +- src/bin/rhai-dbg.rs | 4 ++-- src/bin/rhai-repl.rs | 4 ++-- src/bin/rhai-run.rs | 4 ++-- src/packages/map_basic.rs | 10 +++++++++- src/types/dynamic.rs | 5 +++++ tests/arrays.rs | 2 +- tests/assignments.rs | 2 +- tests/binary_ops.rs | 4 ++-- tests/bit_fields.rs | 2 +- tests/blobs.rs | 2 +- tests/bool_op.rs | 2 +- tests/build_type.rs | 2 +- tests/call_fn.rs | 2 +- tests/chars.rs | 2 +- tests/closures.rs | 4 ++-- tests/comments.rs | 2 +- tests/compound_equality.rs | 2 +- tests/constants.rs | 2 +- tests/custom_syntax.rs | 2 +- tests/data_size.rs | 6 +++--- tests/debugging.rs | 6 +++--- tests/decrement.rs | 2 +- tests/eval.rs | 2 +- tests/expressions.rs | 2 +- tests/float.rs | 2 +- tests/fn_ptr.rs | 2 +- tests/for.rs | 4 ++-- tests/functions.rs | 4 ++-- tests/get_set.rs | 4 ++-- tests/if_block.rs | 2 +- tests/increment.rs | 2 +- tests/looping.rs | 2 +- tests/maps.rs | 2 +- tests/math.rs | 4 ++-- tests/method_call.rs | 4 ++-- tests/mismatched_op.rs | 2 +- tests/modules.rs | 18 +++++++++--------- tests/native.rs | 2 +- tests/not.rs | 2 +- tests/number_literals.rs | 2 +- tests/operations.rs | 8 ++++---- tests/ops.rs | 2 +- tests/optimizer.rs | 2 +- tests/options.rs | 2 +- tests/packages.rs | 4 ++-- tests/plugins.rs | 8 ++++---- tests/plugins_register.rs | 4 ++-- tests/plugins_unroll.rs | 6 +++--- tests/power_of.rs | 4 ++-- tests/print.rs | 2 +- tests/serde.rs | 8 ++++---- tests/side_effects.rs | 2 +- tests/stack.rs | 2 +- tests/string.rs | 2 +- tests/switch.rs | 4 ++-- tests/throw.rs | 2 +- tests/time.rs | 6 +++--- tests/tokens.rs | 2 +- tests/types.rs | 2 +- tests/unary_after_binary.rs | 2 +- tests/unary_minus.rs | 2 +- tests/unit.rs | 2 +- tests/var_scope.rs | 2 +- tests/while_loop.rs | 2 +- 91 files changed, 149 insertions(+), 136 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 42e828ca5..c26ec8aca 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ members = [".", "codegen"] [package] -name = "rhai" +name = "spo-rhai" version = "1.17.1" rust-version = "1.66.0" edition = "2018" @@ -25,7 +25,7 @@ num-traits = { version = "0.2.0", default-features = false } once_cell = { version = "1.7.0", default-features = false, features = ["race"] } bitflags = { version = "2.0.0", default-features = false } smartstring = { version = "1.0.0", default-features = false } -rhai_codegen = { version = "2.0.0", path = "codegen" } +rhai_codegen = { version = "2.0.0", path = "codegen", package = "spo-rhai_codegen" } no-std-compat = { git = "https://gitlab.com/jD91mZM2/no-std-compat", version = "0.4.1", default-features = false, features = ["alloc"], optional = true } libm = { version = "0.2.0", default-features = false, optional = true } @@ -39,7 +39,7 @@ getrandom = { version = "0.2.0", optional = true } rustyline = { version = "13.0.0", optional = true } document-features = { version = "0.2.0", optional = true } arbitrary = { version = "1.3.2", optional = true, features = ["derive"] } -indexmap = { version = "2.1.0", optional = true } +indexmap = { version = "2.2.3", optional = true, features = ["serde"] } [dev-dependencies] rmp-serde = "1.1.0" @@ -48,7 +48,7 @@ serde_json = { version = "1.0.45", default-features = false, features = ["alloc" [features] ## Default features: `std`, uses runtime random numbers for hashing. -default = ["std", "ahash/runtime-rng"] # ahash/runtime-rng trumps ahash/compile-time-rng +default = ["std", "ahash/runtime-rng", "indexmap"] # ahash/runtime-rng trumps ahash/compile-time-rng ## Standard features: uses compile-time random number for hashing. std = ["once_cell/std", "ahash/std", "num-traits/std", "smartstring/std"] diff --git a/benches/engine.rs b/benches/engine.rs index d725699a7..1f13a17c8 100644 --- a/benches/engine.rs +++ b/benches/engine.rs @@ -3,7 +3,7 @@ ///! Test evaluating expressions extern crate test; -use rhai::{Array, Engine, Map, INT}; +use spo_rhai::{Array, Engine, Map, INT}; use test::Bencher; #[bench] @@ -18,7 +18,7 @@ fn bench_engine_new_raw(bench: &mut Bencher) { #[bench] fn bench_engine_new_raw_core(bench: &mut Bencher) { - use rhai::packages::*; + use spo_rhai::packages::*; let package = CorePackage::new(); bench.iter(|| { diff --git a/benches/eval_array.rs b/benches/eval_array.rs index 7287f2224..9a6e99052 100644 --- a/benches/eval_array.rs +++ b/benches/eval_array.rs @@ -3,7 +3,7 @@ ///! Test evaluating expressions extern crate test; -use rhai::{Engine, OptimizationLevel}; +use spo_rhai::{Engine, OptimizationLevel}; use test::Bencher; #[bench] diff --git a/benches/eval_expression.rs b/benches/eval_expression.rs index dfcdbb06e..b460b831c 100644 --- a/benches/eval_expression.rs +++ b/benches/eval_expression.rs @@ -3,7 +3,7 @@ ///! Test evaluating expressions extern crate test; -use rhai::{Engine, OptimizationLevel}; +use spo_rhai::{Engine, OptimizationLevel}; use test::Bencher; #[bench] diff --git a/benches/eval_map.rs b/benches/eval_map.rs index df49dcdfc..20f01de08 100644 --- a/benches/eval_map.rs +++ b/benches/eval_map.rs @@ -3,7 +3,7 @@ ///! Test evaluating expressions extern crate test; -use rhai::{Engine, OptimizationLevel}; +use spo_rhai::{Engine, OptimizationLevel}; use test::Bencher; #[bench] diff --git a/benches/eval_module.rs b/benches/eval_module.rs index 55fb0fb49..71bc1c34d 100644 --- a/benches/eval_module.rs +++ b/benches/eval_module.rs @@ -3,7 +3,7 @@ ///! Test evaluating with scope extern crate test; -use rhai::{Engine, Module, OptimizationLevel, Scope}; +use spo_rhai::{Engine, Module, OptimizationLevel, Scope}; use test::Bencher; #[bench] diff --git a/benches/eval_scope.rs b/benches/eval_scope.rs index 2237fa8a6..d408c6a9d 100644 --- a/benches/eval_scope.rs +++ b/benches/eval_scope.rs @@ -3,7 +3,7 @@ ///! Test evaluating with scope extern crate test; -use rhai::{Engine, OptimizationLevel, Scope, INT}; +use spo_rhai::{Engine, OptimizationLevel, Scope, INT}; use test::Bencher; #[bench] diff --git a/benches/eval_type.rs b/benches/eval_type.rs index 7cee4394e..8ee74d97d 100644 --- a/benches/eval_type.rs +++ b/benches/eval_type.rs @@ -3,7 +3,7 @@ ///! Test evaluating expressions extern crate test; -use rhai::{Engine, OptimizationLevel, Scope, INT}; +use spo_rhai::{Engine, OptimizationLevel, Scope, INT}; use test::Bencher; #[derive(Debug, Clone)] diff --git a/benches/iterations.rs b/benches/iterations.rs index 33ac414f4..4e6f6ac41 100644 --- a/benches/iterations.rs +++ b/benches/iterations.rs @@ -3,7 +3,7 @@ ///! Test 1,000 iterations extern crate test; -use rhai::{Engine, OptimizationLevel, INT}; +use spo_rhai::{Engine, OptimizationLevel, INT}; use test::Bencher; #[bench] diff --git a/benches/parsing.rs b/benches/parsing.rs index d45b22529..1ce0077d9 100644 --- a/benches/parsing.rs +++ b/benches/parsing.rs @@ -3,7 +3,7 @@ ///! Test parsing expressions extern crate test; -use rhai::{Engine, OptimizationLevel}; +use spo_rhai::{Engine, OptimizationLevel}; use test::Bencher; #[bench] diff --git a/benches/primes.rs b/benches/primes.rs index 40c047a05..708d1d368 100644 --- a/benches/primes.rs +++ b/benches/primes.rs @@ -3,7 +3,7 @@ ///! Test evaluating expressions extern crate test; -use rhai::{Engine, OptimizationLevel}; +use spo_rhai::{Engine, OptimizationLevel}; use test::Bencher; // This script uses the Sieve of Eratosthenes to calculate prime numbers. diff --git a/codegen/Cargo.toml b/codegen/Cargo.toml index cb4d1342a..feaa71d28 100644 --- a/codegen/Cargo.toml +++ b/codegen/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "rhai_codegen" +name = "spo-rhai_codegen" version = "2.0.0" edition = "2018" resolver = "2" @@ -24,5 +24,5 @@ syn = { version = "2.0.0", features = ["full", "parsing", "printing", "proc-macr quote = "1.0.0" [dev-dependencies] -rhai = { path = "..", version = "1.17.0", features = ["metadata"] } +rhai = { path = "..", features = ["metadata"], package = "spo-rhai" } trybuild = "1.0.0" diff --git a/examples/arrays_and_structs.rs b/examples/arrays_and_structs.rs index b5a7889a7..3ba0e5e5b 100644 --- a/examples/arrays_and_structs.rs +++ b/examples/arrays_and_structs.rs @@ -5,7 +5,7 @@ fn main() { panic!("This example does not run under 'no_index' or 'no_object'.") } -use rhai::{Engine, EvalAltResult}; +use spo_rhai::{Engine, EvalAltResult}; #[cfg(not(feature = "no_index"))] #[cfg(not(feature = "no_object"))] diff --git a/examples/callback.rs b/examples/callback.rs index 999846910..ffcea0594 100644 --- a/examples/callback.rs +++ b/examples/callback.rs @@ -1,6 +1,6 @@ //! This example stores a Rhai closure for later use as a callback. -use rhai::{Engine, EvalAltResult, FnPtr}; +use spo_rhai::{Engine, EvalAltResult, FnPtr}; // To call a Rhai closure at a later time, you'd need three things: // 1) an `Engine` (with all needed functions registered), diff --git a/examples/custom_types.rs b/examples/custom_types.rs index c4d7804fa..44d9c4f3a 100644 --- a/examples/custom_types.rs +++ b/examples/custom_types.rs @@ -5,7 +5,7 @@ fn main() { panic!("This example does not run under 'no_object'."); } -use rhai::{CustomType, Engine, EvalAltResult, TypeBuilder}; +use spo_rhai::{CustomType, Engine, EvalAltResult, TypeBuilder}; #[cfg(not(feature = "no_object"))] fn main() -> Result<(), Box> { diff --git a/examples/custom_types_and_methods.rs b/examples/custom_types_and_methods.rs index 4dd0f5618..27c24147f 100644 --- a/examples/custom_types_and_methods.rs +++ b/examples/custom_types_and_methods.rs @@ -5,7 +5,7 @@ fn main() { panic!("This example does not run under 'no_object'."); } -use rhai::{CustomType, Engine, EvalAltResult, TypeBuilder}; +use spo_rhai::{CustomType, Engine, EvalAltResult, TypeBuilder}; #[cfg(not(feature = "no_object"))] fn main() -> Result<(), Box> { diff --git a/examples/definitions/main.rs b/examples/definitions/main.rs index 7648ec89d..f0bf52add 100644 --- a/examples/definitions/main.rs +++ b/examples/definitions/main.rs @@ -1,5 +1,5 @@ -use rhai::plugin::*; -use rhai::{Engine, EvalAltResult, Scope}; +use spo_rhai::plugin::*; +use spo_rhai::{Engine, EvalAltResult, Scope}; #[export_module] pub mod general_kenobi { diff --git a/examples/event_handler_js/main.rs b/examples/event_handler_js/main.rs index efed0107f..942088a4d 100644 --- a/examples/event_handler_js/main.rs +++ b/examples/event_handler_js/main.rs @@ -8,7 +8,7 @@ pub fn main() { #[cfg(not(feature = "no_function"))] #[cfg(not(feature = "no_object"))] pub fn main() { - use rhai::{CallFnOptions, Dynamic, Engine, Map, Scope, AST}; + use spo_rhai::{CallFnOptions, Dynamic, Engine, Map, Scope, AST}; use std::io::{stdin, stdout, Write}; const SCRIPT_FILE: &str = "event_handler_js/script.rhai"; diff --git a/examples/event_handler_main/main.rs b/examples/event_handler_main/main.rs index 2a1d8f797..b4be54c22 100644 --- a/examples/event_handler_main/main.rs +++ b/examples/event_handler_main/main.rs @@ -7,7 +7,7 @@ pub fn main() { #[cfg(not(feature = "no_function"))] pub fn main() { - use rhai::{CallFnOptions, Dynamic, Engine, Scope, AST}; + use spo_rhai::{CallFnOptions, Dynamic, Engine, Scope, AST}; use std::io::{stdin, stdout, Write}; const SCRIPT_FILE: &str = "event_handler_main/script.rhai"; diff --git a/examples/event_handler_map/main.rs b/examples/event_handler_map/main.rs index dc9c2ff7c..72d89830b 100644 --- a/examples/event_handler_map/main.rs +++ b/examples/event_handler_map/main.rs @@ -8,7 +8,7 @@ pub fn main() { #[cfg(not(feature = "no_function"))] #[cfg(not(feature = "no_object"))] pub fn main() { - use rhai::{Dynamic, Engine, Map, Scope, AST}; + use spo_rhai::{Dynamic, Engine, Map, Scope, AST}; use std::io::{stdin, stdout, Write}; const SCRIPT_FILE: &str = "event_handler_map/script.rhai"; diff --git a/examples/hello.rs b/examples/hello.rs index dba66e5b2..d6eaaf913 100644 --- a/examples/hello.rs +++ b/examples/hello.rs @@ -1,6 +1,6 @@ //! A simple example that evaluates an expression and prints the result. -use rhai::{Engine, EvalAltResult}; +use spo_rhai::{Engine, EvalAltResult}; fn main() -> Result<(), Box> { let engine = Engine::new(); diff --git a/examples/pause_and_resume.rs b/examples/pause_and_resume.rs index 8b336d637..1595a9f88 100644 --- a/examples/pause_and_resume.rs +++ b/examples/pause_and_resume.rs @@ -5,7 +5,7 @@ fn main() { panic!("This example does not run under 'unchecked'."); } -use rhai::{Dynamic, Engine}; +use spo_rhai::{Dynamic, Engine}; #[cfg(feature = "sync")] use std::sync::Mutex; diff --git a/examples/reuse_scope.rs b/examples/reuse_scope.rs index 486382a24..b7a9a6aaf 100644 --- a/examples/reuse_scope.rs +++ b/examples/reuse_scope.rs @@ -1,6 +1,6 @@ //! An example that evaluates two pieces of code in separate runs, but using a common `Scope`. -use rhai::{Engine, EvalAltResult, Scope}; +use spo_rhai::{Engine, EvalAltResult, Scope}; fn main() -> Result<(), Box> { let engine = Engine::new(); diff --git a/examples/serde.rs b/examples/serde.rs index cbdab2b2d..f6f9da711 100644 --- a/examples/serde.rs +++ b/examples/serde.rs @@ -7,8 +7,8 @@ fn main() { #[cfg(not(feature = "no_object"))] fn main() { - use rhai::serde::{from_dynamic, to_dynamic}; - use rhai::{Dynamic, Engine, Map}; + use spo_rhai::serde::{from_dynamic, to_dynamic}; + use spo_rhai::{Dynamic, Engine, Map}; use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] diff --git a/examples/simple_fn.rs b/examples/simple_fn.rs index 887cad30b..3f862d988 100644 --- a/examples/simple_fn.rs +++ b/examples/simple_fn.rs @@ -1,6 +1,6 @@ //! An example showing how to register a simple Rust function. -use rhai::{Engine, EvalAltResult}; +use spo_rhai::{Engine, EvalAltResult}; fn add(x: i64, y: i64) -> i64 { x + y diff --git a/examples/strings.rs b/examples/strings.rs index b9c7285ad..db969d616 100644 --- a/examples/strings.rs +++ b/examples/strings.rs @@ -1,7 +1,7 @@ //! An example that registers a variety of functions that operate on strings. //! Remember to use `ImmutableString` or `&str` instead of `String` as parameters. -use rhai::{Engine, EvalAltResult, ImmutableString, Scope}; +use spo_rhai::{Engine, EvalAltResult, ImmutableString, Scope}; use std::io::{stdin, stdout, Write}; /// Trim whitespace from a string. The original string argument is changed. diff --git a/examples/threading.rs b/examples/threading.rs index adcf9bea2..f974c46ac 100644 --- a/examples/threading.rs +++ b/examples/threading.rs @@ -1,7 +1,7 @@ //! An advanced example showing how to communicate with an `Engine` running in a separate thread via //! an MPSC channel. -use rhai::Engine; +use spo_rhai::Engine; #[cfg(feature = "sync")] use std::sync::Mutex; diff --git a/src/bin/rhai-dbg.rs b/src/bin/rhai-dbg.rs index cecb2ad5c..37b8a889c 100644 --- a/src/bin/rhai-dbg.rs +++ b/src/bin/rhai-dbg.rs @@ -1,5 +1,5 @@ -use rhai::debugger::{BreakPoint, DebuggerCommand, DebuggerEvent}; -use rhai::{Dynamic, Engine, EvalAltResult, ImmutableString, Position, Scope, INT}; +use spo_rhai::debugger::{BreakPoint, DebuggerCommand, DebuggerEvent}; +use spo_rhai::{Dynamic, Engine, EvalAltResult, ImmutableString, Position, Scope, INT}; use std::{ env, diff --git a/src/bin/rhai-repl.rs b/src/bin/rhai-repl.rs index a8df52a95..96e89bb70 100644 --- a/src/bin/rhai-repl.rs +++ b/src/bin/rhai-repl.rs @@ -1,5 +1,5 @@ -use rhai::plugin::*; -use rhai::{Dynamic, Engine, EvalAltResult, Module, Scope, AST, INT}; +use spo_rhai::plugin::*; +use spo_rhai::{Dynamic, Engine, EvalAltResult, Module, Scope, AST, INT}; use rustyline::config::Builder; use rustyline::error::ReadlineError; use rustyline::history::{History, SearchDirection}; diff --git a/src/bin/rhai-run.rs b/src/bin/rhai-run.rs index b8503db0f..31cacf369 100644 --- a/src/bin/rhai-run.rs +++ b/src/bin/rhai-run.rs @@ -1,4 +1,4 @@ -use rhai::{Engine, EvalAltResult, Position}; +use spo_rhai::{Engine, EvalAltResult, Position}; use std::{env, fs::File, io::Read, path::Path, process::exit}; @@ -55,7 +55,7 @@ fn main() { let mut engine = Engine::new(); #[cfg(not(feature = "no_optimize"))] - engine.set_optimization_level(rhai::OptimizationLevel::Simple); + engine.set_optimization_level(spo_rhai::OptimizationLevel::Simple); let mut f = match File::open(&filename) { Err(err) => { diff --git a/src/packages/map_basic.rs b/src/packages/map_basic.rs index ca24bf356..9d20525cf 100644 --- a/src/packages/map_basic.rs +++ b/src/packages/map_basic.rs @@ -118,7 +118,15 @@ mod map_functions { return Dynamic::UNIT; } - map.remove(property).unwrap_or(Dynamic::UNIT) + #[cfg(not(feature = "indexmap"))] + { + map.remove(property).unwrap_or(Dynamic::UNIT) + } + + #[cfg(feature = "indexmap")] + { + map.swap_remove(property).unwrap_or(Dynamic::UNIT) + } } /// Add all property values of another object map into the object map. /// Existing property values of the same names are replaced. diff --git a/src/types/dynamic.rs b/src/types/dynamic.rs index b995d95a9..a692607f5 100644 --- a/src/types/dynamic.rs +++ b/src/types/dynamic.rs @@ -375,6 +375,7 @@ impl Dynamic { } } +#[cfg(feature = "indexmap")] fn hash_indexmap(m: &Box, state: &mut H) { let mut m = m.iter().collect::>(); m.sort_unstable_by_key(|x| x.0); @@ -406,8 +407,12 @@ impl Hash for Dynamic { Union::Array(ref a, ..) => a.hash(state), #[cfg(not(feature = "no_index"))] Union::Blob(ref a, ..) => a.hash(state), + #[cfg(not(feature = "no_object"))] #[cfg(not(feature = "indexmap"))] + Union::Map(ref m, ..) => m.hash(state), + #[cfg(not(feature = "no_object"))] + #[cfg(feature = "indexmap")] Union::Map(ref m, ..) => hash_indexmap(m, state), Union::FnPtr(ref f, ..) if f.environ.is_some() => { diff --git a/tests/arrays.rs b/tests/arrays.rs index 2563bfca6..ca3a9d720 100644 --- a/tests/arrays.rs +++ b/tests/arrays.rs @@ -1,5 +1,5 @@ #![cfg(not(feature = "no_index"))] -use rhai::{Array, Dynamic, Engine, ParseErrorType, INT}; +use spo_rhai::{Array, Dynamic, Engine, ParseErrorType, INT}; use std::iter::FromIterator; #[test] diff --git a/tests/assignments.rs b/tests/assignments.rs index c8803bb9a..70387c163 100644 --- a/tests/assignments.rs +++ b/tests/assignments.rs @@ -1,4 +1,4 @@ -use rhai::{Engine, ParseErrorType, INT}; +use spo_rhai::{Engine, ParseErrorType, INT}; #[test] fn test_assignments() { diff --git a/tests/binary_ops.rs b/tests/binary_ops.rs index e63bd78ec..907bd7ec7 100644 --- a/tests/binary_ops.rs +++ b/tests/binary_ops.rs @@ -1,4 +1,4 @@ -use rhai::{Engine, INT}; +use spo_rhai::{Engine, INT}; #[test] fn test_binary_ops() { @@ -39,7 +39,7 @@ fn test_binary_ops() { #[cfg(not(feature = "no_float"))] { - use rhai::FLOAT; + use spo_rhai::FLOAT; assert_eq!(engine.eval::("10.0 + 4.0").unwrap(), 14.0); assert_eq!(engine.eval::("10.0 - 4.0").unwrap(), 6.0); diff --git a/tests/bit_fields.rs b/tests/bit_fields.rs index 4802c24b9..9dd7b4435 100644 --- a/tests/bit_fields.rs +++ b/tests/bit_fields.rs @@ -1,4 +1,4 @@ -use rhai::{Engine, INT}; +use spo_rhai::{Engine, INT}; #[test] fn test_left_shift() { diff --git a/tests/blobs.rs b/tests/blobs.rs index d739ad61b..4b97c30ee 100644 --- a/tests/blobs.rs +++ b/tests/blobs.rs @@ -1,5 +1,5 @@ #![cfg(not(feature = "no_index"))] -use rhai::{Blob, Engine, Scope, INT}; +use spo_rhai::{Blob, Engine, Scope, INT}; use std::iter::FromIterator; #[test] diff --git a/tests/bool_op.rs b/tests/bool_op.rs index c938beaa9..53e7106dd 100644 --- a/tests/bool_op.rs +++ b/tests/bool_op.rs @@ -1,4 +1,4 @@ -use rhai::Engine; +use spo_rhai::Engine; #[test] fn test_bool_op1() { diff --git a/tests/build_type.rs b/tests/build_type.rs index 4c7190cd3..9bd0db59f 100644 --- a/tests/build_type.rs +++ b/tests/build_type.rs @@ -1,5 +1,5 @@ #![cfg(not(feature = "no_object"))] -use rhai::{CustomType, Engine, EvalAltResult, Position, TypeBuilder, INT}; +use spo_rhai::{CustomType, Engine, EvalAltResult, Position, TypeBuilder, INT}; #[test] fn test_build_type() { diff --git a/tests/call_fn.rs b/tests/call_fn.rs index 23273dcd0..b07ff0708 100644 --- a/tests/call_fn.rs +++ b/tests/call_fn.rs @@ -1,5 +1,5 @@ #![cfg(not(feature = "no_function"))] -use rhai::{CallFnOptions, Dynamic, Engine, EvalAltResult, FnPtr, Func, FuncArgs, Scope, AST, INT}; +use spo_rhai::{CallFnOptions, Dynamic, Engine, EvalAltResult, FnPtr, Func, FuncArgs, Scope, AST, INT}; use std::any::TypeId; #[test] diff --git a/tests/chars.rs b/tests/chars.rs index 772a58d90..aa3c75e51 100644 --- a/tests/chars.rs +++ b/tests/chars.rs @@ -1,4 +1,4 @@ -use rhai::Engine; +use spo_rhai::Engine; #[test] fn test_chars() { diff --git a/tests/closures.rs b/tests/closures.rs index 89585d8ff..37e30610e 100644 --- a/tests/closures.rs +++ b/tests/closures.rs @@ -1,12 +1,12 @@ #![cfg(not(feature = "no_function"))] -use rhai::{Dynamic, Engine, EvalAltResult, FnPtr, ParseErrorType, Scope, INT}; +use spo_rhai::{Dynamic, Engine, EvalAltResult, FnPtr, ParseErrorType, Scope, INT}; use std::any::TypeId; use std::cell::RefCell; use std::mem::take; use std::rc::Rc; #[cfg(not(feature = "no_object"))] -use rhai::Map; +use spo_rhai::Map; #[test] fn test_fn_ptr_curry_call() { diff --git a/tests/comments.rs b/tests/comments.rs index 1a7a23b9f..29ea643a1 100644 --- a/tests/comments.rs +++ b/tests/comments.rs @@ -1,4 +1,4 @@ -use rhai::{Engine, INT}; +use spo_rhai::{Engine, INT}; #[test] fn test_comments() { diff --git a/tests/compound_equality.rs b/tests/compound_equality.rs index d21f19821..767cd1885 100644 --- a/tests/compound_equality.rs +++ b/tests/compound_equality.rs @@ -1,4 +1,4 @@ -use rhai::{Engine, INT}; +use spo_rhai::{Engine, INT}; #[test] fn test_or_equals() { diff --git a/tests/constants.rs b/tests/constants.rs index cb8c810b2..46f27a38d 100644 --- a/tests/constants.rs +++ b/tests/constants.rs @@ -1,4 +1,4 @@ -use rhai::{Engine, EvalAltResult, ParseErrorType, Scope, INT}; +use spo_rhai::{Engine, EvalAltResult, ParseErrorType, Scope, INT}; #[test] fn test_constant() { diff --git a/tests/custom_syntax.rs b/tests/custom_syntax.rs index 42fc637ca..3025c738a 100644 --- a/tests/custom_syntax.rs +++ b/tests/custom_syntax.rs @@ -1,6 +1,6 @@ #![cfg(not(feature = "no_custom_syntax"))] -use rhai::{Dynamic, Engine, EvalAltResult, ImmutableString, LexError, ParseErrorType, Position, Scope, INT}; +use spo_rhai::{Dynamic, Engine, EvalAltResult, ImmutableString, LexError, ParseErrorType, Position, Scope, INT}; #[test] fn test_custom_syntax() { diff --git a/tests/data_size.rs b/tests/data_size.rs index 4285def0c..76620af3e 100644 --- a/tests/data_size.rs +++ b/tests/data_size.rs @@ -1,11 +1,11 @@ #![cfg(not(feature = "unchecked"))] -use rhai::{Engine, EvalAltResult, ParseErrorType, INT}; +use spo_rhai::{Engine, EvalAltResult, ParseErrorType, INT}; #[cfg(not(feature = "no_index"))] -use rhai::Array; +use spo_rhai::Array; #[cfg(not(feature = "no_object"))] -use rhai::Map; +use spo_rhai::Map; #[test] fn test_max_string_size() { diff --git a/tests/debugging.rs b/tests/debugging.rs index 811666e8f..af730be3e 100644 --- a/tests/debugging.rs +++ b/tests/debugging.rs @@ -1,11 +1,11 @@ #![cfg(feature = "debugging")] -use rhai::{Engine, INT}; +use spo_rhai::{Engine, INT}; #[cfg(not(feature = "no_index"))] -use rhai::Array; +use spo_rhai::Array; #[cfg(not(feature = "no_object"))] -use rhai::Map; +use spo_rhai::Map; #[test] fn test_debugging() { diff --git a/tests/decrement.rs b/tests/decrement.rs index 7a3109967..3227331cc 100644 --- a/tests/decrement.rs +++ b/tests/decrement.rs @@ -1,4 +1,4 @@ -use rhai::{Engine, INT}; +use spo_rhai::{Engine, INT}; #[test] fn test_decrement() { diff --git a/tests/eval.rs b/tests/eval.rs index 91e86ae97..fe7e21eb5 100644 --- a/tests/eval.rs +++ b/tests/eval.rs @@ -1,4 +1,4 @@ -use rhai::{Engine, LexError, ParseErrorType, Scope, INT}; +use spo_rhai::{Engine, LexError, ParseErrorType, Scope, INT}; #[test] fn test_eval() { diff --git a/tests/expressions.rs b/tests/expressions.rs index 99c43875e..0de965078 100644 --- a/tests/expressions.rs +++ b/tests/expressions.rs @@ -1,4 +1,4 @@ -use rhai::{Engine, Scope, INT}; +use spo_rhai::{Engine, Scope, INT}; #[test] fn test_expressions() { diff --git a/tests/float.rs b/tests/float.rs index 8796b296b..b0cd9ea0f 100644 --- a/tests/float.rs +++ b/tests/float.rs @@ -1,5 +1,5 @@ #![cfg(not(feature = "no_float"))] -use rhai::{Engine, FLOAT}; +use spo_rhai::{Engine, FLOAT}; const EPSILON: FLOAT = 0.000_000_000_1; diff --git a/tests/fn_ptr.rs b/tests/fn_ptr.rs index f18c63386..985bb3baa 100644 --- a/tests/fn_ptr.rs +++ b/tests/fn_ptr.rs @@ -1,4 +1,4 @@ -use rhai::{Engine, EvalAltResult, FnPtr, INT}; +use spo_rhai::{Engine, EvalAltResult, FnPtr, INT}; #[test] fn test_fn_ptr() { diff --git a/tests/for.rs b/tests/for.rs index 1d30c352a..896d07c2b 100644 --- a/tests/for.rs +++ b/tests/for.rs @@ -1,7 +1,7 @@ -use rhai::{Engine, Module, INT}; +use spo_rhai::{Engine, Module, INT}; #[cfg(not(feature = "no_float"))] -use rhai::FLOAT; +use spo_rhai::FLOAT; #[cfg(feature = "decimal")] #[cfg(not(feature = "no_float"))] diff --git a/tests/functions.rs b/tests/functions.rs index 8089abf93..a9994641e 100644 --- a/tests/functions.rs +++ b/tests/functions.rs @@ -1,5 +1,5 @@ #![cfg(not(feature = "no_function"))] -use rhai::{Dynamic, Engine, EvalAltResult, FnNamespace, FuncRegistration, Module, NativeCallContext, ParseErrorType, Shared, INT}; +use spo_rhai::{Dynamic, Engine, EvalAltResult, FnNamespace, FuncRegistration, Module, NativeCallContext, ParseErrorType, Shared, INT}; #[test] fn test_functions() { @@ -135,7 +135,7 @@ fn test_functions_global_module() { if matches!(&*err, EvalAltResult::ErrorVariableNotFound(v, ..) if v == "global::ANSWER") )); - engine.register_fn("do_stuff", |context: NativeCallContext, callback: rhai::FnPtr| -> Result { callback.call_within_context(&context, ()) }); + engine.register_fn("do_stuff", |context: NativeCallContext, callback: spo_rhai::FnPtr| -> Result { callback.call_within_context(&context, ()) }); #[cfg(not(feature = "no_closure"))] assert!(matches!(*engine.run( diff --git a/tests/get_set.rs b/tests/get_set.rs index d5d7e591f..2fd22c4e4 100644 --- a/tests/get_set.rs +++ b/tests/get_set.rs @@ -1,5 +1,5 @@ #![cfg(not(feature = "no_object"))] -use rhai::{Engine, EvalAltResult, NativeCallContext, Scope, INT}; +use spo_rhai::{Engine, EvalAltResult, NativeCallContext, Scope, INT}; #[test] fn test_get_set() { @@ -239,7 +239,7 @@ fn test_get_set_indexer() { engine .register_type_with_name::("MyMap") .register_fn("new_map", MyMap::new) - .register_indexer_get(|map: &mut MyMap, index: &str| -> Result<_, Box> { map.get(index).cloned().ok_or_else(|| EvalAltResult::ErrorIndexNotFound(index.into(), rhai::Position::NONE).into()) }) + .register_indexer_get(|map: &mut MyMap, index: &str| -> Result<_, Box> { map.get(index).cloned().ok_or_else(|| EvalAltResult::ErrorIndexNotFound(index.into(), spo_rhai::Position::NONE).into()) }) .register_indexer_set(|map: &mut MyMap, index: &str, value: INT| { map.insert(index.to_string(), value); }); diff --git a/tests/if_block.rs b/tests/if_block.rs index 754bc1adf..a3ab96a75 100644 --- a/tests/if_block.rs +++ b/tests/if_block.rs @@ -1,4 +1,4 @@ -use rhai::{Engine, INT}; +use spo_rhai::{Engine, INT}; #[test] fn test_if() { diff --git a/tests/increment.rs b/tests/increment.rs index 4dee82aea..6c4ee88c4 100644 --- a/tests/increment.rs +++ b/tests/increment.rs @@ -1,4 +1,4 @@ -use rhai::{Engine, INT}; +use spo_rhai::{Engine, INT}; #[test] fn test_increment() { diff --git a/tests/looping.rs b/tests/looping.rs index dc142ee8d..296b7cb39 100644 --- a/tests/looping.rs +++ b/tests/looping.rs @@ -1,4 +1,4 @@ -use rhai::{Engine, ParseErrorType, INT}; +use spo_rhai::{Engine, ParseErrorType, INT}; #[test] fn test_loop() { diff --git a/tests/maps.rs b/tests/maps.rs index 23e4f7a85..d04592d40 100644 --- a/tests/maps.rs +++ b/tests/maps.rs @@ -1,5 +1,5 @@ #![cfg(not(feature = "no_object"))] -use rhai::{Engine, EvalAltResult, Map, ParseErrorType, Scope, INT}; +use spo_rhai::{Engine, EvalAltResult, Map, ParseErrorType, Scope, INT}; #[test] fn test_map_indexing() { diff --git a/tests/math.rs b/tests/math.rs index a1f1b155a..d95c249a7 100644 --- a/tests/math.rs +++ b/tests/math.rs @@ -1,7 +1,7 @@ -use rhai::{Engine, EvalAltResult, INT}; +use spo_rhai::{Engine, EvalAltResult, INT}; #[cfg(not(feature = "no_float"))] -use rhai::FLOAT; +use spo_rhai::FLOAT; #[test] fn test_math() { diff --git a/tests/method_call.rs b/tests/method_call.rs index 46013a919..c16b5816d 100644 --- a/tests/method_call.rs +++ b/tests/method_call.rs @@ -1,5 +1,5 @@ #![cfg(not(feature = "no_object"))] -use rhai::{Engine, EvalAltResult, INT}; +use spo_rhai::{Engine, EvalAltResult, INT}; #[derive(Debug, Clone, Eq, PartialEq)] struct TestStruct { @@ -38,7 +38,7 @@ fn test_method_call_style() { fn test_method_call_with_full_optimization() { let mut engine = Engine::new(); - engine.set_optimization_level(rhai::OptimizationLevel::Full); + engine.set_optimization_level(spo_rhai::OptimizationLevel::Full); engine .register_fn("new_ts", TestStruct::new) diff --git a/tests/mismatched_op.rs b/tests/mismatched_op.rs index 6a692613e..0a4312345 100644 --- a/tests/mismatched_op.rs +++ b/tests/mismatched_op.rs @@ -1,4 +1,4 @@ -use rhai::{Engine, EvalAltResult, INT}; +use spo_rhai::{Engine, EvalAltResult, INT}; #[test] fn test_mismatched_op() { diff --git a/tests/modules.rs b/tests/modules.rs index c06bf14c4..dd17ce926 100644 --- a/tests/modules.rs +++ b/tests/modules.rs @@ -1,11 +1,11 @@ #![cfg(not(feature = "no_module"))] -use rhai::{ +use spo_rhai::{ module_resolvers::{DummyModuleResolver, StaticModuleResolver}, Dynamic, Engine, EvalAltResult, FnNamespace, FuncRegistration, ImmutableString, Module, ParseError, ParseErrorType, Scope, INT, }; // #[cfg(all(not(feature = "no_function"), feature = "internals"))] -use rhai::{FnPtr, NativeCallContext}; +use spo_rhai::{FnPtr, NativeCallContext}; #[test] fn test_module() { @@ -96,7 +96,7 @@ fn test_module_resolver() { FuncRegistration::new("double").with_namespace(FnNamespace::Global).set_into_module(&mut module, f); #[cfg(not(feature = "no_float"))] - module.set_native_fn("sum_of_three_args", |target: &mut INT, a: INT, b: INT, c: rhai::FLOAT| { + module.set_native_fn("sum_of_three_args", |target: &mut INT, a: INT, b: INT, c: spo_rhai::FLOAT| { *target = a + b + c as INT; Ok(()) }); @@ -405,13 +405,13 @@ fn test_module_str() { Ok(input.len() as INT) } - let mut engine = rhai::Engine::new(); + let mut engine = spo_rhai::Engine::new(); let mut module = Module::new(); module.set_native_fn("test", test_fn); module.set_native_fn("test2", test_fn2); module.set_native_fn("test3", test_fn3); - let mut static_modules = rhai::module_resolvers::StaticModuleResolver::new(); + let mut static_modules = spo_rhai::module_resolvers::StaticModuleResolver::new(); static_modules.insert("test", module); engine.set_module_resolver(static_modules); @@ -447,7 +447,7 @@ fn test_module_ast_namespace() { #[cfg(not(feature = "no_function"))] #[test] fn test_module_ast_namespace2() { - use rhai::{Engine, Module, Scope}; + use spo_rhai::{Engine, Module, Scope}; const MODULE_TEXT: &str = " fn run_function(function) { @@ -468,7 +468,7 @@ fn test_module_ast_namespace2() { let mut engine = Engine::new(); let module_ast = engine.compile(MODULE_TEXT).unwrap(); let module = Module::eval_ast_as_new(Scope::new(), &module_ast, &engine).unwrap(); - let mut static_modules = rhai::module_resolvers::StaticModuleResolver::new(); + let mut static_modules = spo_rhai::module_resolvers::StaticModuleResolver::new(); static_modules.insert("test_module", module); engine.set_module_resolver(static_modules); @@ -572,11 +572,11 @@ fn test_module_dynamic() { Ok(s.len() as INT + x) } - let mut engine = rhai::Engine::new(); + let mut engine = spo_rhai::Engine::new(); let mut module = Module::new(); module.set_native_fn("test", test_fn); - let mut static_modules = rhai::module_resolvers::StaticModuleResolver::new(); + let mut static_modules = spo_rhai::module_resolvers::StaticModuleResolver::new(); static_modules.insert("test", module); engine.set_module_resolver(static_modules); engine.register_fn("test2", test_fn); diff --git a/tests/native.rs b/tests/native.rs index e2579482c..37e535442 100644 --- a/tests/native.rs +++ b/tests/native.rs @@ -1,4 +1,4 @@ -use rhai::{Dynamic, Engine, EvalAltResult, ImmutableString, NativeCallContext, INT}; +use spo_rhai::{Dynamic, Engine, EvalAltResult, ImmutableString, NativeCallContext, INT}; use std::any::TypeId; #[cfg(not(feature = "no_module"))] diff --git a/tests/not.rs b/tests/not.rs index 2eb299d2f..397ee2633 100644 --- a/tests/not.rs +++ b/tests/not.rs @@ -1,4 +1,4 @@ -use rhai::Engine; +use spo_rhai::Engine; #[test] fn test_not() { diff --git a/tests/number_literals.rs b/tests/number_literals.rs index e222dea46..be0a443bd 100644 --- a/tests/number_literals.rs +++ b/tests/number_literals.rs @@ -1,4 +1,4 @@ -use rhai::{Engine, INT}; +use spo_rhai::{Engine, INT}; #[test] fn test_number_literal() { diff --git a/tests/operations.rs b/tests/operations.rs index 2657b9a1c..14d60e8e7 100644 --- a/tests/operations.rs +++ b/tests/operations.rs @@ -1,11 +1,11 @@ #![cfg(not(feature = "unchecked"))] -use rhai::{Engine, EvalAltResult, INT}; +use spo_rhai::{Engine, EvalAltResult, INT}; #[test] fn test_max_operations() { let mut engine = Engine::new(); #[cfg(not(feature = "no_optimize"))] - engine.set_optimization_level(rhai::OptimizationLevel::None); + engine.set_optimization_level(spo_rhai::OptimizationLevel::None); engine.set_max_operations(500); engine.on_progress(|count| { @@ -28,7 +28,7 @@ fn test_max_operations() { fn test_max_operations_literal() { let mut engine = Engine::new(); #[cfg(not(feature = "no_optimize"))] - engine.set_optimization_level(rhai::OptimizationLevel::None); + engine.set_optimization_level(spo_rhai::OptimizationLevel::None); engine.set_max_operations(10); #[cfg(not(feature = "no_index"))] @@ -131,7 +131,7 @@ fn test_max_operations_eval() { fn test_max_operations_progress() { let mut engine = Engine::new(); #[cfg(not(feature = "no_optimize"))] - engine.set_optimization_level(rhai::OptimizationLevel::None); + engine.set_optimization_level(spo_rhai::OptimizationLevel::None); engine.set_max_operations(500); engine.on_progress(|count| if count < 100 { None } else { Some((42 as INT).into()) }); diff --git a/tests/ops.rs b/tests/ops.rs index af0d6dafe..8b7ee5559 100644 --- a/tests/ops.rs +++ b/tests/ops.rs @@ -1,4 +1,4 @@ -use rhai::{Engine, EvalAltResult, Scope, INT}; +use spo_rhai::{Engine, EvalAltResult, Scope, INT}; #[test] fn test_ops() { diff --git a/tests/optimizer.rs b/tests/optimizer.rs index e51ced358..dd3e9b789 100644 --- a/tests/optimizer.rs +++ b/tests/optimizer.rs @@ -1,5 +1,5 @@ #![cfg(not(feature = "no_optimize"))] -use rhai::{Engine, FuncRegistration, Module, OptimizationLevel, Scope, INT}; +use spo_rhai::{Engine, FuncRegistration, Module, OptimizationLevel, Scope, INT}; #[test] fn test_optimizer() { diff --git a/tests/options.rs b/tests/options.rs index fe330574c..0f2790ee5 100644 --- a/tests/options.rs +++ b/tests/options.rs @@ -1,4 +1,4 @@ -use rhai::{Engine, Scope, INT}; +use spo_rhai::{Engine, Scope, INT}; #[test] fn test_options_allow() { diff --git a/tests/packages.rs b/tests/packages.rs index 99055164d..da659de1e 100644 --- a/tests/packages.rs +++ b/tests/packages.rs @@ -1,5 +1,5 @@ -use rhai::packages::{Package, StandardPackage as SSS}; -use rhai::{def_package, Engine, Module, Scope, INT}; +use spo_rhai::packages::{Package, StandardPackage as SSS}; +use spo_rhai::{def_package, Engine, Module, Scope, INT}; #[cfg(not(feature = "no_module"))] #[cfg(not(feature = "no_custom_syntax"))] diff --git a/tests/plugins.rs b/tests/plugins.rs index 2ba8d2f51..c2c503a33 100644 --- a/tests/plugins.rs +++ b/tests/plugins.rs @@ -1,20 +1,20 @@ #![cfg(not(feature = "no_index"))] #![cfg(not(feature = "no_module"))] -use rhai::plugin::*; -use rhai::{Engine, Scope, INT}; +use spo_rhai::plugin::*; +use spo_rhai::{Engine, Scope, INT}; mod test { use super::*; #[export_module] pub mod special_array_package { - use rhai::{Array, INT}; + use spo_rhai::{Array, INT}; pub const MYSTIC_NUMBER: INT = 42; #[cfg(not(feature = "no_object"))] pub mod feature { - use rhai::{Array, Dynamic, EvalAltResult}; + use spo_rhai::{Array, Dynamic, EvalAltResult}; #[rhai_fn(get = "foo", return_raw)] #[inline(always)] diff --git a/tests/plugins_register.rs b/tests/plugins_register.rs index cd580e1aa..27e26c326 100644 --- a/tests/plugins_register.rs +++ b/tests/plugins_register.rs @@ -1,5 +1,5 @@ -use rhai::plugin::*; -use rhai::{Engine, INT}; +use spo_rhai::plugin::*; +use spo_rhai::{Engine, INT}; #[export_fn] pub fn add_together(x: INT, y: INT) -> INT { diff --git a/tests/plugins_unroll.rs b/tests/plugins_unroll.rs index 8e612ab05..cbab21ae4 100644 --- a/tests/plugins_unroll.rs +++ b/tests/plugins_unroll.rs @@ -1,7 +1,7 @@ #![cfg(not(feature = "no_index"))] #![cfg(not(feature = "no_module"))] -use rhai::plugin::*; -use rhai::{Engine, Module, INT}; +use spo_rhai::plugin::*; +use spo_rhai::{Engine, Module, INT}; pub fn add_generic>(x: T, y: T) -> T { x + y @@ -16,7 +16,7 @@ macro_rules! generate_ops { pub mod $op_name { $( pub mod $type_names { - use rhai::plugin::*; + use spo_rhai::plugin::*; use super::super::$op_fn; #[export_fn] pub fn op(x: $type_names, y: $type_names) -> $type_names { diff --git a/tests/power_of.rs b/tests/power_of.rs index 2d80b0778..1f3e637ce 100644 --- a/tests/power_of.rs +++ b/tests/power_of.rs @@ -1,7 +1,7 @@ -use rhai::{Engine, INT}; +use spo_rhai::{Engine, INT}; #[cfg(not(feature = "no_float"))] -use rhai::FLOAT; +use spo_rhai::FLOAT; #[cfg(not(feature = "no_float"))] const EPSILON: FLOAT = FLOAT::EPSILON; diff --git a/tests/print.rs b/tests/print.rs index 21657ab31..d2f06138c 100644 --- a/tests/print.rs +++ b/tests/print.rs @@ -1,4 +1,4 @@ -use rhai::{Engine, Scope, INT}; +use spo_rhai::{Engine, Scope, INT}; use std::sync::{Arc, RwLock}; #[cfg(not(feature = "only_i32"))] diff --git a/tests/serde.rs b/tests/serde.rs index 66ba67c22..56ce3ede0 100644 --- a/tests/serde.rs +++ b/tests/serde.rs @@ -1,6 +1,6 @@ #![cfg(feature = "serde")] -use rhai::{ +use spo_rhai::{ serde::{from_dynamic, to_dynamic}, Dynamic, Engine, ImmutableString, Scope, INT, }; @@ -9,11 +9,11 @@ use serde_json::json; use std::sync::Arc; #[cfg(not(feature = "no_index"))] -use rhai::Array; +use spo_rhai::Array; #[cfg(not(feature = "no_object"))] -use rhai::Map; +use spo_rhai::Map; #[cfg(not(feature = "no_float"))] -use rhai::FLOAT; +use spo_rhai::FLOAT; #[cfg(feature = "decimal")] use rust_decimal::Decimal; diff --git a/tests/side_effects.rs b/tests/side_effects.rs index 31e55bbfa..189d84c0a 100644 --- a/tests/side_effects.rs +++ b/tests/side_effects.rs @@ -1,5 +1,5 @@ ///! This test simulates an external command object that is driven by a script. -use rhai::{Engine, Scope, INT}; +use spo_rhai::{Engine, Scope, INT}; use std::sync::{Arc, Mutex, RwLock}; /// Simulate a command object. diff --git a/tests/stack.rs b/tests/stack.rs index 1128d2544..cf052098e 100644 --- a/tests/stack.rs +++ b/tests/stack.rs @@ -1,5 +1,5 @@ #![cfg(not(feature = "unchecked"))] -use rhai::{Dynamic, Engine, EvalAltResult, ParseErrorType, INT}; +use spo_rhai::{Dynamic, Engine, EvalAltResult, ParseErrorType, INT}; #[test] #[cfg(not(feature = "no_function"))] diff --git a/tests/string.rs b/tests/string.rs index 1af0083d2..8736f0d8e 100644 --- a/tests/string.rs +++ b/tests/string.rs @@ -1,4 +1,4 @@ -use rhai::{Engine, EvalAltResult, ImmutableString, Scope, INT}; +use spo_rhai::{Engine, EvalAltResult, ImmutableString, Scope, INT}; #[test] fn test_string() { diff --git a/tests/switch.rs b/tests/switch.rs index 94915713c..7bc07b37c 100644 --- a/tests/switch.rs +++ b/tests/switch.rs @@ -1,4 +1,4 @@ -use rhai::{Engine, ParseErrorType, Scope, INT}; +use spo_rhai::{Engine, ParseErrorType, Scope, INT}; #[test] fn test_switch() { @@ -136,7 +136,7 @@ fn test_switch_condition() { #[cfg(not(feature = "no_object"))] mod test_switch_enum { use super::*; - use rhai::Array; + use spo_rhai::Array; #[derive(Debug, Clone)] #[allow(dead_code)] enum MyEnum { diff --git a/tests/throw.rs b/tests/throw.rs index 1580eee51..29d3db0e9 100644 --- a/tests/throw.rs +++ b/tests/throw.rs @@ -1,4 +1,4 @@ -use rhai::{Engine, EvalAltResult, INT}; +use spo_rhai::{Engine, EvalAltResult, INT}; #[test] fn test_throw() { diff --git a/tests/time.rs b/tests/time.rs index d10258d21..9d82c95bb 100644 --- a/tests/time.rs +++ b/tests/time.rs @@ -1,9 +1,9 @@ #![cfg(not(feature = "no_time"))] -use rhai::Engine; +use spo_rhai::Engine; #[cfg(not(feature = "no_float"))] -use rhai::FLOAT; +use spo_rhai::FLOAT; #[cfg(feature = "no_float")] -use rhai::INT; +use spo_rhai::INT; #[test] fn test_timestamp() { diff --git a/tests/tokens.rs b/tests/tokens.rs index 5c74fb239..c97a85225 100644 --- a/tests/tokens.rs +++ b/tests/tokens.rs @@ -1,4 +1,4 @@ -use rhai::{Engine, ParseErrorType, INT}; +use spo_rhai::{Engine, ParseErrorType, INT}; #[test] fn test_tokens_disabled() { diff --git a/tests/types.rs b/tests/types.rs index 820f2eb19..39293f6ae 100644 --- a/tests/types.rs +++ b/tests/types.rs @@ -1,4 +1,4 @@ -use rhai::{Engine, INT}; +use spo_rhai::{Engine, INT}; #[test] fn test_type_of() { diff --git a/tests/unary_after_binary.rs b/tests/unary_after_binary.rs index 518d0d509..0470ac886 100644 --- a/tests/unary_after_binary.rs +++ b/tests/unary_after_binary.rs @@ -1,4 +1,4 @@ -use rhai::{Engine, INT}; +use spo_rhai::{Engine, INT}; #[test] // TODO also add test case for unary after compound diff --git a/tests/unary_minus.rs b/tests/unary_minus.rs index c6f6e9a6b..a5957ba7b 100644 --- a/tests/unary_minus.rs +++ b/tests/unary_minus.rs @@ -1,4 +1,4 @@ -use rhai::{Engine, INT}; +use spo_rhai::{Engine, INT}; #[test] fn test_unary_minus() { diff --git a/tests/unit.rs b/tests/unit.rs index aafb64243..170d16ed0 100644 --- a/tests/unit.rs +++ b/tests/unit.rs @@ -1,4 +1,4 @@ -use rhai::Engine; +use spo_rhai::Engine; #[test] fn test_unit() { diff --git a/tests/var_scope.rs b/tests/var_scope.rs index 1ea3a5f2f..45133ecad 100644 --- a/tests/var_scope.rs +++ b/tests/var_scope.rs @@ -1,4 +1,4 @@ -use rhai::{Dynamic, Engine, EvalAltResult, Module, ParseErrorType, Position, Scope, INT}; +use spo_rhai::{Dynamic, Engine, EvalAltResult, Module, ParseErrorType, Position, Scope, INT}; #[test] fn test_var_scope() { diff --git a/tests/while_loop.rs b/tests/while_loop.rs index 301ade660..0f394b199 100644 --- a/tests/while_loop.rs +++ b/tests/while_loop.rs @@ -1,4 +1,4 @@ -use rhai::{Engine, INT}; +use spo_rhai::{Engine, INT}; #[test] fn test_while() { From 25c5c01bb0849e27e259b5ecc14117f4ad1dfbcf Mon Sep 17 00:00:00 2001 From: Duy Do Date: Wed, 14 Feb 2024 16:01:25 +0700 Subject: [PATCH 4/9] remove example --- Cargo.toml | 4 - tests/serde.rs | 758 ------------------------------------------------- 2 files changed, 762 deletions(-) delete mode 100644 tests/serde.rs diff --git a/Cargo.toml b/Cargo.toml index c26ec8aca..78b6acd39 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -144,10 +144,6 @@ name = "rhai-run" name = "rhai-dbg" required-features = ["debugging"] -[[example]] -name = "serde" -required-features = ["serde"] - [[example]] name = "definitions" required-features = ["metadata", "internals"] diff --git a/tests/serde.rs b/tests/serde.rs deleted file mode 100644 index 56ce3ede0..000000000 --- a/tests/serde.rs +++ /dev/null @@ -1,758 +0,0 @@ -#![cfg(feature = "serde")] - -use spo_rhai::{ - serde::{from_dynamic, to_dynamic}, - Dynamic, Engine, ImmutableString, Scope, INT, -}; -use serde::{Deserialize, Deserializer, Serialize}; -use serde_json::json; -use std::sync::Arc; - -#[cfg(not(feature = "no_index"))] -use spo_rhai::Array; -#[cfg(not(feature = "no_object"))] -use spo_rhai::Map; -#[cfg(not(feature = "no_float"))] -use spo_rhai::FLOAT; -#[cfg(feature = "decimal")] -use rust_decimal::Decimal; - -#[test] -fn test_serde_ser_primary_types() { - assert!(to_dynamic(42_u64).unwrap().is_int()); - assert!(to_dynamic(42 as INT).unwrap().is_int()); - assert!(to_dynamic(true).unwrap().is_bool()); - assert!(to_dynamic(()).unwrap().is_unit()); - - #[cfg(not(feature = "no_float"))] - assert!(to_dynamic(123.456_f64).unwrap().is::()); - - #[cfg(not(feature = "no_float"))] - assert!(to_dynamic(123.456_f32).unwrap().is::()); - - #[cfg(feature = "no_float")] - #[cfg(feature = "decimal")] - assert!(to_dynamic(123.456_f64).unwrap().is::()); - - #[cfg(feature = "no_float")] - #[cfg(feature = "decimal")] - assert!(to_dynamic(123.456_f32).unwrap().is::()); - - assert!(to_dynamic("hello".to_string()).unwrap().is::()); -} - -#[test] -fn test_serde_ser_integer_types() { - assert!(to_dynamic(42_i8).unwrap().is_int()); - assert!(to_dynamic(42_i16).unwrap().is_int()); - assert!(to_dynamic(42_i32).unwrap().is_int()); - assert!(to_dynamic(42_i64).unwrap().is_int()); - assert!(to_dynamic(42_u8).unwrap().is_int()); - assert!(to_dynamic(42_u16).unwrap().is_int()); - assert!(to_dynamic(42_u32).unwrap().is_int()); - assert!(to_dynamic(42_u64).unwrap().is_int()); -} - -#[test] -#[cfg(not(feature = "no_index"))] -fn test_serde_ser_array() { - let arr: Vec = vec![123, 456, 42, 999]; - - let d = to_dynamic(arr).unwrap(); - assert!(d.is_array()); - assert_eq!(4, d.cast::().len()); -} - -#[test] -#[cfg(not(feature = "no_index"))] -#[cfg(not(feature = "no_object"))] -fn test_serde_ser_struct() { - #[derive(Debug, Serialize, PartialEq)] - struct Hello { - a: INT, - b: bool, - } - - #[derive(Debug, Serialize, PartialEq)] - struct Test { - int: u32, - seq: Vec, - obj: Hello, - } - - let x = Test { - int: 42, - seq: vec!["hello".into(), "kitty".into(), "world".into()], - obj: Hello { a: 123, b: true }, - }; - - let d = to_dynamic(x).unwrap(); - - assert!(d.is_map()); - - let mut map = d.cast::(); - let obj = map.remove("obj").unwrap().cast::(); - let mut seq = map.remove("seq").unwrap().cast::(); - - assert_eq!(Ok(123), obj["a"].as_int()); - assert!(obj["b"].as_bool().unwrap()); - assert_eq!(Ok(42), map["int"].as_int()); - assert_eq!(seq.len(), 3); - assert_eq!("kitty", seq.remove(1).into_string().unwrap()); -} - -#[test] -fn test_serde_ser_unit_enum() { - #[derive(Serialize)] - enum MyEnum { - VariantFoo, - VariantBar, - } - - let d = to_dynamic(MyEnum::VariantFoo).unwrap(); - assert_eq!("VariantFoo", d.into_string().unwrap()); - - let d = to_dynamic(MyEnum::VariantBar).unwrap(); - assert_eq!("VariantBar", d.into_string().unwrap()); -} - -#[test] -#[cfg(not(feature = "no_object"))] -fn test_serde_ser_externally_tagged_enum() { - #[allow(clippy::enum_variant_names)] - #[derive(Serialize)] - enum MyEnum { - VariantUnit, - #[cfg(not(feature = "no_index"))] - VariantUnitTuple(), - VariantNewtype(i32), - #[cfg(not(feature = "no_index"))] - VariantTuple(i32, i32), - VariantEmptyStruct {}, - VariantStruct { - a: i32, - }, - } - - { - assert_eq!("VariantUnit", to_dynamic(MyEnum::VariantUnit).unwrap().into_immutable_string().unwrap().as_str()); - } - - #[cfg(not(feature = "no_index"))] - { - let mut map = to_dynamic(MyEnum::VariantUnitTuple()).unwrap().cast::(); - let content = map.remove("VariantUnitTuple").unwrap().cast::(); - assert!(map.is_empty()); - assert!(content.is_empty()); - } - - let mut map = to_dynamic(MyEnum::VariantNewtype(123)).unwrap().cast::(); - let content = map.remove("VariantNewtype").unwrap(); - assert!(map.is_empty()); - assert_eq!(Ok(123), content.as_int()); - - #[cfg(not(feature = "no_index"))] - { - let mut map = to_dynamic(MyEnum::VariantTuple(123, 456)).unwrap().cast::(); - let content = map.remove("VariantTuple").unwrap().cast::(); - assert!(map.is_empty()); - assert_eq!(2, content.len()); - assert_eq!(Ok(123), content[0].as_int()); - assert_eq!(Ok(456), content[1].as_int()); - } - - let mut map = to_dynamic(MyEnum::VariantEmptyStruct {}).unwrap().cast::(); - let map_inner = map.remove("VariantEmptyStruct").unwrap().cast::(); - assert!(map.is_empty()); - assert!(map_inner.is_empty()); - - let mut map = to_dynamic(MyEnum::VariantStruct { a: 123 }).unwrap().cast::(); - let mut map_inner = map.remove("VariantStruct").unwrap().cast::(); - assert!(map.is_empty()); - assert_eq!(Ok(123), map_inner.remove("a").unwrap().as_int()); - assert!(map_inner.is_empty()); -} - -#[test] -#[cfg(not(feature = "no_object"))] -fn test_serde_ser_internally_tagged_enum() { - #[derive(Serialize)] - #[serde(tag = "tag")] - enum MyEnum { - VariantEmptyStruct {}, - VariantStruct { a: i32 }, - } - - let mut map = to_dynamic(MyEnum::VariantEmptyStruct {}).unwrap().cast::(); - assert_eq!("VariantEmptyStruct", map.remove("tag").unwrap().into_immutable_string().unwrap().as_str()); - assert!(map.is_empty()); - - let mut map = to_dynamic(MyEnum::VariantStruct { a: 123 }).unwrap().cast::(); - assert_eq!("VariantStruct", map.remove("tag").unwrap().into_immutable_string().unwrap().as_str()); - assert_eq!(Ok(123), map.remove("a").unwrap().as_int()); - assert!(map.is_empty()); -} - -#[test] -#[cfg(not(feature = "no_object"))] -fn test_serde_ser_adjacently_tagged_enum() { - #[allow(clippy::enum_variant_names)] - #[derive(Serialize)] - #[serde(tag = "tag", content = "content")] - enum MyEnum { - VariantUnit, - #[cfg(not(feature = "no_index"))] - VariantUnitTuple(), - VariantNewtype(i32), - #[cfg(not(feature = "no_index"))] - VariantTuple(i32, i32), - VariantEmptyStruct {}, - VariantStruct { - a: i32, - }, - } - - let mut map = to_dynamic(MyEnum::VariantUnit).unwrap().cast::(); - assert_eq!("VariantUnit", map.remove("tag").unwrap().into_immutable_string().unwrap().as_str()); - assert!(map.is_empty()); - - #[cfg(not(feature = "no_index"))] - { - let mut map = to_dynamic(MyEnum::VariantUnitTuple()).unwrap().cast::(); - assert_eq!("VariantUnitTuple", map.remove("tag").unwrap().into_immutable_string().unwrap().as_str()); - let content = map.remove("content").unwrap().cast::(); - assert!(map.is_empty()); - assert!(content.is_empty()); - } - - let mut map = to_dynamic(MyEnum::VariantNewtype(123)).unwrap().cast::(); - assert_eq!("VariantNewtype", map.remove("tag").unwrap().into_immutable_string().unwrap().as_str()); - let content = map.remove("content").unwrap(); - assert!(map.is_empty()); - assert_eq!(Ok(123), content.as_int()); - - #[cfg(not(feature = "no_index"))] - { - let mut map = to_dynamic(MyEnum::VariantTuple(123, 456)).unwrap().cast::(); - assert_eq!("VariantTuple", map.remove("tag").unwrap().into_immutable_string().unwrap().as_str()); - let content = map.remove("content").unwrap().cast::(); - assert!(map.is_empty()); - assert_eq!(2, content.len()); - assert_eq!(Ok(123), content[0].as_int()); - assert_eq!(Ok(456), content[1].as_int()); - } - - let mut map = to_dynamic(MyEnum::VariantEmptyStruct {}).unwrap().cast::(); - assert_eq!("VariantEmptyStruct", map.remove("tag").unwrap().into_immutable_string().unwrap().as_str()); - let map_inner = map.remove("content").unwrap().cast::(); - assert!(map.is_empty()); - assert!(map_inner.is_empty()); - - let mut map = to_dynamic(MyEnum::VariantStruct { a: 123 }).unwrap().cast::(); - assert_eq!("VariantStruct", map.remove("tag").unwrap().into_string().unwrap()); - let mut map_inner = map.remove("content").unwrap().cast::(); - assert!(map.is_empty()); - assert_eq!(Ok(123), map_inner.remove("a").unwrap().as_int()); - assert!(map_inner.is_empty()); -} - -#[test] -#[cfg(not(feature = "no_object"))] -fn test_serde_ser_untagged_enum() { - #[derive(Serialize)] - #[serde(untagged)] - enum MyEnum { - VariantEmptyStruct {}, - VariantStruct1 { a: i32 }, - VariantStruct2 { b: i32 }, - } - - let map = to_dynamic(MyEnum::VariantEmptyStruct {}).unwrap().cast::(); - assert!(map.is_empty()); - - let mut map = to_dynamic(MyEnum::VariantStruct1 { a: 123 }).unwrap().cast::(); - assert_eq!(Ok(123), map.remove("a").unwrap().as_int()); - assert!(map.is_empty()); - - let mut map = to_dynamic(MyEnum::VariantStruct2 { b: 123 }).unwrap().cast::(); - assert_eq!(Ok(123), map.remove("b").unwrap().as_int()); - assert!(map.is_empty()); -} - -#[test] -fn test_serde_de_primary_types() { - assert_eq!(42, from_dynamic::(&Dynamic::from(42_u16)).unwrap()); - assert_eq!(42, from_dynamic::(&(42 as INT).into()).unwrap()); - assert!(from_dynamic::(&true.into()).unwrap()); - let _: () = from_dynamic::<()>(&().into()).unwrap(); - - #[cfg(not(feature = "no_float"))] - assert_eq!(123.456, from_dynamic::(&123.456.into()).unwrap()); - - #[cfg(not(feature = "no_float"))] - assert_eq!(123.456, from_dynamic::(&Dynamic::from(123.456_f32)).unwrap()); - - #[cfg(feature = "no_float")] - #[cfg(feature = "decimal")] - { - let d: Dynamic = Decimal::from_str("123.456").unwrap().into(); - - assert_eq!(123.456, from_dynamic::(&d).unwrap()); - assert_eq!(123.456, from_dynamic::(&d).unwrap()); - } - - assert_eq!("hello", from_dynamic::(&"hello".to_string().into()).unwrap()); -} - -#[cfg(not(feature = "no_object"))] -#[test] -fn test_serde_de_variants() { - #[derive(Debug)] - struct Foo; - - #[derive(Debug, Deserialize)] - struct Bar { - #[serde(deserialize_with = "deserialize_foo")] - value: Arc, - } - - fn deserialize_foo<'de, D: Deserializer<'de>>(deserializer: D) -> Result, D::Error> { - let value = ::deserialize(deserializer).unwrap(); - - value.try_cast::>().ok_or_else(|| serde::de::Error::custom("type error")) - } - - let value = Arc::new(Foo); - let mut map = Map::new(); - map.insert("value".into(), Dynamic::from(value.clone())); - let x = Dynamic::from(map); - let bar = from_dynamic::(&x).unwrap(); - - assert!(Arc::ptr_eq(&bar.value, &value)); -} - -#[test] -fn test_serde_de_integer_types() { - assert_eq!(42, from_dynamic::(&Dynamic::from(42 as INT)).unwrap()); - assert_eq!(42, from_dynamic::(&Dynamic::from(42 as INT)).unwrap()); - assert_eq!(42, from_dynamic::(&Dynamic::from(42 as INT)).unwrap()); - assert_eq!(42, from_dynamic::(&Dynamic::from(42 as INT)).unwrap()); - assert_eq!(42, from_dynamic::(&Dynamic::from(42 as INT)).unwrap()); - assert_eq!(42, from_dynamic::(&Dynamic::from(42 as INT)).unwrap()); - assert_eq!(42, from_dynamic::(&Dynamic::from(42 as INT)).unwrap()); - assert_eq!(42, from_dynamic::(&Dynamic::from(42 as INT)).unwrap()); -} - -#[test] -#[cfg(not(feature = "no_index"))] -fn test_serde_de_array() { - let arr: Vec = vec![123, 456, 42, 999]; - assert_eq!(arr, from_dynamic::>(&arr.clone().into()).unwrap()); -} - -#[test] -#[cfg(not(feature = "no_index"))] -#[cfg(not(feature = "no_object"))] -fn test_serde_de_struct() { - #[derive(Debug, Deserialize, PartialEq)] - struct Hello { - a: INT, - b: bool, - } - - #[derive(Debug, Deserialize, PartialEq)] - struct Test { - int: u32, - seq: Vec, - obj: Hello, - } - - let mut map = Map::new(); - map.insert("int".into(), Dynamic::from(42_u32)); - - let mut map2 = Map::new(); - map2.insert("a".into(), (123 as INT).into()); - map2.insert("b".into(), true.into()); - - map.insert("obj".into(), map2.into()); - - let arr: Array = vec!["hello".into(), "kitty".into(), "world".into()]; - map.insert("seq".into(), arr.into()); - - let expected = Test { - int: 42, - seq: vec!["hello".into(), "kitty".into(), "world".into()], - obj: Hello { a: 123, b: true }, - }; - assert_eq!(expected, from_dynamic(&map.into()).unwrap()); -} - -#[test] -#[cfg(not(feature = "no_index"))] -#[cfg(not(feature = "no_object"))] -#[cfg(not(feature = "no_float"))] -fn test_serde_de_script() { - #[allow(dead_code)] - #[derive(Debug, Deserialize)] - struct Point { - x: FLOAT, - y: FLOAT, - } - - #[allow(dead_code)] - #[derive(Debug, Deserialize)] - struct MyStruct { - a: i64, - b: Vec, - c: bool, - d: Point, - } - - let engine = Engine::new(); - - let result: Dynamic = engine - .eval( - r#" - #{ - a: 42, - b: [ "hello", "world" ], - c: true, - d: #{ x: 123.456, y: 999.0 } - } - "#, - ) - .unwrap(); - - // Convert the 'Dynamic' object map into 'MyStruct' - let _: MyStruct = from_dynamic(&result).unwrap(); -} - -#[test] -fn test_serde_de_unit_enum() { - #[derive(Debug, PartialEq, Deserialize)] - enum MyEnum { - VariantFoo, - VariantBar, - } - - let d = Dynamic::from("VariantFoo".to_string()); - assert_eq!(MyEnum::VariantFoo, from_dynamic(&d).unwrap()); - - let d = Dynamic::from("VariantBar".to_string()); - assert_eq!(MyEnum::VariantBar, from_dynamic(&d).unwrap()); -} - -#[test] -#[cfg(not(feature = "no_object"))] -fn test_serde_de_externally_tagged_enum() { - #[allow(clippy::enum_variant_names)] - #[derive(Debug, PartialEq, Deserialize)] - #[serde(deny_unknown_fields)] - enum MyEnum { - VariantUnit, - #[cfg(not(feature = "no_index"))] - VariantUnitTuple(), - VariantNewtype(i32), - #[cfg(not(feature = "no_index"))] - VariantTuple(i32, i32), - VariantEmptyStruct {}, - VariantStruct { - a: i32, - }, - } - - let d = Dynamic::from("VariantUnit".to_string()); - assert_eq!(MyEnum::VariantUnit, from_dynamic(&d).unwrap()); - - #[cfg(not(feature = "no_index"))] - { - let array: Array = vec![]; - let mut map_outer = Map::new(); - map_outer.insert("VariantUnitTuple".into(), array.into()); - assert_eq!(MyEnum::VariantUnitTuple(), from_dynamic(&map_outer.into()).unwrap()); - } - - let mut map_outer = Map::new(); - map_outer.insert("VariantNewtype".into(), (123 as INT).into()); - assert_eq!(MyEnum::VariantNewtype(123), from_dynamic(&map_outer.into()).unwrap()); - - #[cfg(not(feature = "no_index"))] - { - let array: Array = vec![(123 as INT).into(), (456 as INT).into()]; - let mut map_outer = Map::new(); - map_outer.insert("VariantTuple".into(), array.into()); - assert_eq!(MyEnum::VariantTuple(123, 456), from_dynamic(&map_outer.into()).unwrap()); - } - - let map_inner = Map::new(); - let mut map_outer = Map::new(); - map_outer.insert("VariantEmptyStruct".into(), map_inner.into()); - assert_eq!(MyEnum::VariantEmptyStruct {}, from_dynamic(&map_outer.into()).unwrap()); - - let mut map_inner = Map::new(); - map_inner.insert("a".into(), (123 as INT).into()); - let mut map_outer = Map::new(); - map_outer.insert("VariantStruct".into(), map_inner.into()); - assert_eq!(MyEnum::VariantStruct { a: 123 }, from_dynamic(&map_outer.into()).unwrap()); -} - -#[test] -#[cfg(not(feature = "no_object"))] -fn test_serde_de_internally_tagged_enum() { - #[derive(Debug, PartialEq, Deserialize)] - #[serde(tag = "tag", deny_unknown_fields)] - enum MyEnum { - VariantEmptyStruct {}, - VariantStruct { a: i32 }, - } - - let mut map = Map::new(); - map.insert("tag".into(), "VariantStruct".into()); - map.insert("a".into(), (123 as INT).into()); - assert_eq!(MyEnum::VariantStruct { a: 123 }, from_dynamic(&map.into()).unwrap()); - - let mut map = Map::new(); - map.insert("tag".into(), "VariantEmptyStruct".into()); - assert_eq!(MyEnum::VariantEmptyStruct {}, from_dynamic(&map.into()).unwrap()); -} - -#[test] -#[cfg(not(feature = "no_object"))] -fn test_serde_de_adjacently_tagged_enum() { - #[allow(clippy::enum_variant_names)] - #[derive(Debug, PartialEq, Deserialize)] - #[serde(tag = "tag", content = "content", deny_unknown_fields)] - enum MyEnum { - VariantUnit, - #[cfg(not(feature = "no_index"))] - VariantUnitTuple(), - VariantNewtype(i32), - #[cfg(not(feature = "no_index"))] - VariantTuple(i32, i32), - VariantEmptyStruct {}, - VariantStruct { - a: i32, - }, - } - - let mut map_outer = Map::new(); - map_outer.insert("tag".into(), "VariantUnit".into()); - assert_eq!(MyEnum::VariantUnit, from_dynamic(&map_outer.into()).unwrap()); - - #[cfg(not(feature = "no_index"))] - { - let array: Array = vec![]; - let mut map_outer = Map::new(); - map_outer.insert("tag".into(), "VariantUnitTuple".into()); - map_outer.insert("content".into(), array.into()); - assert_eq!(MyEnum::VariantUnitTuple(), from_dynamic(&map_outer.into()).unwrap()); - } - - let mut map_outer = Map::new(); - map_outer.insert("tag".into(), "VariantNewtype".into()); - map_outer.insert("content".into(), (123 as INT).into()); - assert_eq!(MyEnum::VariantNewtype(123), from_dynamic(&map_outer.into()).unwrap()); - - #[cfg(not(feature = "no_index"))] - { - let array: Array = vec![(123 as INT).into(), (456 as INT).into()]; - let mut map_outer = Map::new(); - map_outer.insert("tag".into(), "VariantTuple".into()); - map_outer.insert("content".into(), array.into()); - assert_eq!(MyEnum::VariantTuple(123, 456), from_dynamic(&map_outer.into()).unwrap()); - } - - let map_inner = Map::new(); - let mut map_outer = Map::new(); - map_outer.insert("tag".into(), "VariantEmptyStruct".into()); - map_outer.insert("content".into(), map_inner.into()); - assert_eq!(MyEnum::VariantEmptyStruct {}, from_dynamic(&map_outer.into()).unwrap()); - - let mut map_inner = Map::new(); - map_inner.insert("a".into(), (123 as INT).into()); - let mut map_outer = Map::new(); - map_outer.insert("tag".into(), "VariantStruct".into()); - map_outer.insert("content".into(), map_inner.into()); - assert_eq!(MyEnum::VariantStruct { a: 123 }, from_dynamic(&map_outer.into()).unwrap()); -} - -#[test] -#[cfg(not(feature = "no_object"))] -fn test_serde_de_untagged_enum() { - #[derive(Debug, PartialEq, Deserialize)] - #[serde(untagged, deny_unknown_fields)] - enum MyEnum { - VariantEmptyStruct {}, - VariantStruct1 { a: i32 }, - VariantStruct2 { b: i32 }, - } - - let map = Map::new(); - assert_eq!(MyEnum::VariantEmptyStruct {}, from_dynamic(&map.into()).unwrap()); - - let mut map = Map::new(); - map.insert("a".into(), (123 as INT).into()); - assert_eq!(MyEnum::VariantStruct1 { a: 123 }, from_dynamic(&map.into()).unwrap()); - - let mut map = Map::new(); - map.insert("b".into(), (123 as INT).into()); - assert_eq!(MyEnum::VariantStruct2 { b: 123 }, from_dynamic(&map.into()).unwrap()); -} - -#[test] -#[cfg(feature = "metadata")] -#[cfg(not(feature = "no_object"))] -#[cfg(not(feature = "no_index"))] -fn test_serde_json() -> serde_json::Result<()> { - let s: ImmutableString = "hello".into(); - assert_eq!(serde_json::to_string(&s).unwrap(), r#""hello""#); - - let mut map = Map::new(); - map.insert("a".into(), (123 as INT).into()); - - let arr: Array = vec![(1 as INT).into(), (2 as INT).into(), (3 as INT).into()]; - map.insert("b".into(), arr.into()); - map.insert("c".into(), true.into()); - let d: Dynamic = map.into(); - - let json = serde_json::to_string(&d).unwrap(); - - assert!(json.contains("\"a\":123")); - assert!(json.contains("\"b\":[1,2,3]")); - assert!(json.contains("\"c\":true")); - - let d2: Dynamic = serde_json::from_str(&json).unwrap(); - - assert!(d2.is_map()); - - let mut m = d2.cast::(); - - assert_eq!(m["a"].as_int().unwrap(), 123); - assert!(m["c"].as_bool().unwrap()); - - let a = m.remove("b").unwrap().cast::(); - - assert_eq!(a.len(), 3); - assert_eq!(format!("{a:?}"), "[1, 2, 3]"); - - Ok(()) -} - -#[test] -#[cfg(feature = "metadata")] -#[cfg(feature = "decimal")] -#[cfg(not(feature = "no_float"))] -fn test_serde_json_numbers() -> serde_json::Result<()> { - use std::str::FromStr; - - let d: Dynamic = serde_json::from_str("100000000000").unwrap(); - assert!(d.is::()); - assert_eq!(d.as_int().unwrap(), 100000000000); - - let d: Dynamic = serde_json::from_str("10000000000000000000").unwrap(); - assert!(d.is::()); - assert_eq!(d.as_decimal().unwrap(), Decimal::from_str("10000000000000000000").unwrap()); - - let d: Dynamic = serde_json::from_str("10000000000000000000000000").unwrap(); - assert!(d.is::()); - assert_eq!(d.as_float().unwrap(), 10000000000000000000000000.0); - - Ok(()) -} - -#[test] -#[cfg(not(feature = "no_object"))] -fn test_serde_optional() { - #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] - struct TestStruct { - foo: Option, - } - - let mut engine = Engine::new(); - engine.register_type_with_name::("TestStruct"); - - let r = engine.eval::("#{ foo: 'a' }").unwrap(); - assert_eq!(from_dynamic::(&r).unwrap(), TestStruct { foo: Some('a') }); - - let r = engine.eval::("#{ foo: () }").unwrap(); - assert_eq!(from_dynamic::(&r).unwrap(), TestStruct { foo: None }); - - let r = engine.eval::("#{ }").unwrap(); - assert_eq!(from_dynamic::(&r).unwrap(), TestStruct { foo: None }); - - let ts = TestStruct { foo: Some('a') }; - let r = to_dynamic(&ts).unwrap(); - let map = r.cast::(); - assert_eq!(map.len(), 1); - assert_eq!(map.get("foo").unwrap().as_char().unwrap(), 'a'); - - let ts = TestStruct { foo: None }; - let r = to_dynamic(&ts).unwrap(); - let map = r.cast::(); - assert_eq!(map.len(), 1); - let _: () = map.get("foo").unwrap().as_unit().unwrap(); -} - -#[test] -#[cfg(not(feature = "no_index"))] -#[cfg(not(feature = "no_object"))] -fn test_serde_blob() { - let engine = Engine::new(); - - let r = engine - .eval::( - " - let x = blob(10); - for i in 0..10 { x[i] = i; } - #{ x: x } - ", - ) - .unwrap(); - - let data = format!("{r:?}"); - - let encoded = rmp_serde::to_vec(&r).unwrap(); - let decoded: Dynamic = rmp_serde::from_slice(&encoded).unwrap(); - - assert_eq!(format!("{decoded:?}"), data); -} - -#[test] -#[cfg(not(feature = "no_object"))] -fn test_serde_json_borrowed_string() { - let value = json!({ "a": "b" }); - println!("value: {value:?}"); - - let result: Dynamic = serde_json::from_value(value.clone()).unwrap(); - println!("result: {result:?}"); - - let value2 = serde_json::to_value(&result).unwrap(); - println!("value2: {value2:?}"); - - assert_eq!(value, value2); -} - -#[test] -#[cfg(not(feature = "no_object"))] -fn test_serde_scope() { - #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] - struct TestStruct { - foo: Option, - } - - let mut scope = Scope::new(); - scope.push("x", 42 as INT); - scope.push_constant("y", true); - scope.push("z", TestStruct { foo: None }); - - let json = serde_json::to_string(&scope).unwrap(); - - assert_eq!(json, r#"[{"name":"x","value":42},{"name":"y","value":true,"is_constant":true},{"name":"z","value":"serde::test_serde_scope::TestStruct"}]"#); - - scope = serde_json::from_str(&json).unwrap(); - - assert_eq!(scope.len(), 3); - assert_eq!(scope.get_value::("x").unwrap(), 42); - assert!(scope.get_value::("y").unwrap()); - assert_eq!(scope.get_value::("z").unwrap(), "serde::test_serde_scope::TestStruct"); -} From c18fd6a4e8591448fe9f6997e3432efb7c2cdd8f Mon Sep 17 00:00:00 2001 From: Duy Do Date: Wed, 14 Feb 2024 16:04:56 +0700 Subject: [PATCH 5/9] Remove example --- examples/definitions/.rhai/all_in_one.d.rhai | 6378 ----------------- .../.rhai/all_in_one_without_standard.d.rhai | 14 - .../definitions/__builtin-operators__.d.rhai | 259 - .../.rhai/definitions/__builtin__.d.rhai | 261 - .../.rhai/definitions/__scope__.d.rhai | 5 - .../.rhai/definitions/__static__.d.rhai | 5849 --------------- .../.rhai/definitions/general_kenobi.d.rhai | 6 - examples/definitions/.rhai/defs.json | 49 - examples/definitions/main.rs | 70 - examples/definitions/script.rhai | 3 - 10 files changed, 12894 deletions(-) delete mode 100644 examples/definitions/.rhai/all_in_one.d.rhai delete mode 100644 examples/definitions/.rhai/all_in_one_without_standard.d.rhai delete mode 100644 examples/definitions/.rhai/definitions/__builtin-operators__.d.rhai delete mode 100644 examples/definitions/.rhai/definitions/__builtin__.d.rhai delete mode 100644 examples/definitions/.rhai/definitions/__scope__.d.rhai delete mode 100644 examples/definitions/.rhai/definitions/__static__.d.rhai delete mode 100644 examples/definitions/.rhai/definitions/general_kenobi.d.rhai delete mode 100644 examples/definitions/.rhai/defs.json delete mode 100644 examples/definitions/main.rs delete mode 100644 examples/definitions/script.rhai diff --git a/examples/definitions/.rhai/all_in_one.d.rhai b/examples/definitions/.rhai/all_in_one.d.rhai deleted file mode 100644 index 4ec27f7f5..000000000 --- a/examples/definitions/.rhai/all_in_one.d.rhai +++ /dev/null @@ -1,6378 +0,0 @@ -module static; - -op ==(int, int) -> bool; -op !=(int, int) -> bool; -op >(int, int) -> bool; -op >=(int, int) -> bool; -op <(int, int) -> bool; -op <=(int, int) -> bool; -op &(int, int) -> int; -op |(int, int) -> int; -op ^(int, int) -> int; -op ..(int, int) -> Range; -op ..=(int, int) -> RangeInclusive; - -op ==(bool, bool) -> bool; -op !=(bool, bool) -> bool; -op >(bool, bool) -> bool; -op >=(bool, bool) -> bool; -op <(bool, bool) -> bool; -op <=(bool, bool) -> bool; -op &(bool, bool) -> bool; -op |(bool, bool) -> bool; -op ^(bool, bool) -> bool; - -op ==((), ()) -> bool; -op !=((), ()) -> bool; -op >((), ()) -> bool; -op >=((), ()) -> bool; -op <((), ()) -> bool; -op <=((), ()) -> bool; - -op +(int, int) -> int; -op -(int, int) -> int; -op *(int, int) -> int; -op /(int, int) -> int; -op %(int, int) -> int; -op **(int, int) -> int; -op >>(int, int) -> int; -op <<(int, int) -> int; - -op +(float, float) -> float; -op -(float, float) -> float; -op *(float, float) -> float; -op /(float, float) -> float; -op %(float, float) -> float; -op **(float, float) -> float; -op ==(float, float) -> bool; -op !=(float, float) -> bool; -op >(float, float) -> bool; -op >=(float, float) -> bool; -op <(float, float) -> bool; -op <=(float, float) -> bool; - -op +(float, int) -> float; -op -(float, int) -> float; -op *(float, int) -> float; -op /(float, int) -> float; -op %(float, int) -> float; -op **(float, int) -> float; -op ==(float, int) -> bool; -op !=(float, int) -> bool; -op >(float, int) -> bool; -op >=(float, int) -> bool; -op <(float, int) -> bool; -op <=(float, int) -> bool; - -op +(int, float) -> float; -op -(int, float) -> float; -op *(int, float) -> float; -op /(int, float) -> float; -op %(int, float) -> float; -op **(int, float) -> float; -op ==(int, float) -> bool; -op !=(int, float) -> bool; -op >(int, float) -> bool; -op >=(int, float) -> bool; -op <(int, float) -> bool; -op <=(int, float) -> bool; - -op +(Decimal, Decimal) -> Decimal; -op -(Decimal, Decimal) -> Decimal; -op *(Decimal, Decimal) -> Decimal; -op /(Decimal, Decimal) -> Decimal; -op %(Decimal, Decimal) -> Decimal; -op **(Decimal, Decimal) -> Decimal; -op ==(Decimal, Decimal) -> bool; -op !=(Decimal, Decimal) -> bool; -op >(Decimal, Decimal) -> bool; -op >=(Decimal, Decimal) -> bool; -op <(Decimal, Decimal) -> bool; -op <=(Decimal, Decimal) -> bool; - -op +(Decimal, int) -> Decimal; -op -(Decimal, int) -> Decimal; -op *(Decimal, int) -> Decimal; -op /(Decimal, int) -> Decimal; -op %(Decimal, int) -> Decimal; -op **(Decimal, int) -> Decimal; -op ==(Decimal, int) -> bool; -op !=(Decimal, int) -> bool; -op >(Decimal, int) -> bool; -op >=(Decimal, int) -> bool; -op <(Decimal, int) -> bool; -op <=(Decimal, int) -> bool; - -op +(int, Decimal) -> Decimal; -op -(int, Decimal) -> Decimal; -op *(int, Decimal) -> Decimal; -op /(int, Decimal) -> Decimal; -op %(int, Decimal) -> Decimal; -op **(int, Decimal) -> Decimal; -op ==(int, Decimal) -> bool; -op !=(int, Decimal) -> bool; -op >(int, Decimal) -> bool; -op >=(int, Decimal) -> bool; -op <(int, Decimal) -> bool; -op <=(int, Decimal) -> bool; - -op +(String, String) -> String; -op -(String, String) -> String; -op ==(String, String) -> bool; -op !=(String, String) -> bool; -op >(String, String) -> bool; -op >=(String, String) -> bool; -op <(String, String) -> bool; -op <=(String, String) -> bool; - -op +(char, char) -> String; -op ==(char, char) -> bool; -op !=(char, char) -> bool; -op >(char, char) -> bool; -op >=(char, char) -> bool; -op <(char, char) -> bool; -op <=(char, char) -> bool; - -op +(char, String) -> String; -op ==(char, String) -> bool; -op !=(char, String) -> bool; -op >(char, String) -> bool; -op >=(char, String) -> bool; -op <(char, String) -> bool; -op <=(char, String) -> bool; - -op +(String, char) -> String; -op -(String, char) -> String; -op ==(String, char) -> bool; -op !=(String, char) -> bool; -op >(String, char) -> bool; -op >=(String, char) -> bool; -op <(String, char) -> bool; -op <=(String, char) -> bool; - -op +((), String) -> String; -op ==((), String) -> bool; -op !=((), String) -> bool; -op >((), String) -> bool; -op >=((), String) -> bool; -op <((), String) -> bool; -op <=((), String) -> bool; - -op +(String, ()) -> String; -op ==(String, ()) -> bool; -op !=(String, ()) -> bool; -op >(String, ()) -> bool; -op >=(String, ()) -> bool; -op <(String, ()) -> bool; -op <=(String, ()) -> bool; - -op +(Blob, Blob) -> Blob; -op +(Blob, char) -> Blob; -op ==(Blob, Blob) -> bool; -op !=(Blob, Blob) -> bool; - - -op ==(Range, RangeInclusive) -> bool; -op !=(Range, RangeInclusive) -> bool; - -op ==(RangeInclusive, Range) -> bool; -op !=(RangeInclusive, Range) -> bool; - -op ==(Range, Range) -> bool; -op !=(Range, Range) -> bool; - -op ==(RangeInclusive, RangeInclusive) -> bool; -op !=(RangeInclusive, RangeInclusive) -> bool; - -op ==(?, ?) -> bool; -op !=(?, ?) -> bool; -op >(?, ?) -> bool; -op >=(?, ?) -> bool; -op <(?, ?) -> bool; -op <=(?, ?) -> bool; - - -op &=(bool, bool); -op |=(bool, bool); - -op +=(int, int); -op -=(int, int); -op *=(int, int); -op /=(int, int); -op %=(int, int); -op **=(int, int); -op >>=(int, int); -op <<=(int, int); -op &=(int, int); -op |=(int, int); -op ^=(int, int); - -op +=(float, float); -op -=(float, float); -op *=(float, float); -op /=(float, float); -op %=(float, float); -op **=(float, float); - -op +=(float, int); -op -=(float, int); -op *=(float, int); -op /=(float, int); -op %=(float, int); -op **=(float, int); - -op +=(Decimal, Decimal); -op -=(Decimal, Decimal); -op *=(Decimal, Decimal); -op /=(Decimal, Decimal); -op %=(Decimal, Decimal); -op **=(Decimal, Decimal); - -op +=(Decimal, int); -op -=(Decimal, int); -op *=(Decimal, int); -op /=(Decimal, int); -op %=(Decimal, int); -op **=(Decimal, int); - -op +=(String, String); -op -=(String, String); -op +=(String, char); -op -=(String, char); -op +=(char, String); -op +=(char, char); - -op +=(Array, Array); -op +=(Array, ?); - -op +=(Blob, Blob); -op +=(Blob, int); -op +=(Blob, char); -op +=(Blob, String); - -op in(?, Array) -> bool; -op in(String, String) -> bool; -op in(char, String) -> bool; -op in(int, Range) -> bool; -op in(int, RangeInclusive) -> bool; -op in(String, Map) -> bool; -op in(int, Blob) -> bool; - -/// Display any data to the standard output. -/// -/// # Example -/// -/// ```rhai -/// let answer = 42; -/// -/// print(`The Answer is ${answer}`); -/// ``` -fn print(data: ?); - -/// Display any data to the standard output in debug format. -/// -/// # Example -/// -/// ```rhai -/// let answer = 42; -/// -/// debug(answer); -/// ``` -fn debug(data: ?); - -/// Get the type of a value. -/// -/// # Example -/// -/// ```rhai -/// let x = "hello, world!"; -/// -/// print(x.type_of()); // prints "string" -/// ``` -fn type_of(data: ?) -> String; - -/// Create a function pointer to a named function. -/// -/// If the specified name is not a valid function name, an error is raised. -/// -/// # Example -/// -/// ```rhai -/// let f = Fn("foo"); // function pointer to 'foo' -/// -/// f.call(42); // call: foo(42) -/// ``` -fn Fn(fn_name: String) -> FnPtr; - -/// Call a function pointed to by a function pointer, -/// passing following arguments to the function call. -/// -/// If an appropriate function is not found, an error is raised. -/// -/// # Example -/// -/// ```rhai -/// let f = Fn("foo"); // function pointer to 'foo' -/// -/// f.call(1, 2, 3); // call: foo(1, 2, 3) -/// ``` -fn call(fn_ptr: FnPtr, ...args: ?) -> ?; - -/// Call a function pointed to by a function pointer, binding the `this` pointer -/// to the object of the method call, and passing on following arguments to the function call. -/// -/// If an appropriate function is not found, an error is raised. -/// -/// # Example -/// -/// ```rhai -/// fn add(x) { -/// this + x -/// } -/// -/// let f = Fn("add"); // function pointer to 'add' -/// -/// let x = 41; -/// -/// let r = x.call(f, 1); // call: add(1) with 'this' = 'x' -/// -/// print(r); // prints 42 -/// ``` -fn call(obj: ?, fn_ptr: FnPtr, ...args: ?) -> ?; - -/// Curry a number of arguments into a function pointer and return it as a new function pointer. -/// -/// # Example -/// -/// ```rhai -/// fn foo(x, y, z) { -/// x + y + z -/// } -/// -/// let f = Fn("foo"); -/// -/// let g = f.curry(1, 2); // curried arguments: 1, 2 -/// -/// g.call(3); // call: foo(1, 2, 3) -/// ``` -fn curry(fn_ptr: FnPtr, ...args: ?) -> FnPtr; - -/// Return `true` if a script-defined function exists with a specified name and -/// number of parameters. -/// -/// # Example -/// -/// ```rhai -/// fn foo(x) { } -/// -/// print(is_def_fn("foo", 1)); // prints true -/// print(is_def_fn("foo", 2)); // prints false -/// print(is_def_fn("foo", 0)); // prints false -/// print(is_def_fn("bar", 1)); // prints false -/// ``` -fn is_def_fn(fn_name: String, num_params: int) -> bool; - -/// Return `true` if a variable matching a specified name is defined. -/// -/// # Example -/// -/// ```rhai -/// let x = 42; -/// -/// print(is_def_var("x")); // prints true -/// print(is_def_var("foo")); // prints false -/// -/// { -/// let y = 1; -/// print(is_def_var("y")); // prints true -/// } -/// -/// print(is_def_var("y")); // prints false -/// ``` -fn is_def_var(var_name: String) -> bool; - -/// Return `true` if the variable is shared. -/// -/// # Example -/// -/// ```rhai -/// let x = 42; -/// -/// print(is_shared(x)); // prints false -/// -/// let f = || x; // capture 'x', making it shared -/// -/// print(is_shared(x)); // prints true -/// ``` -fn is_shared(variable: ?) -> bool; - -/// Evaluate a text script within the current scope. -/// -/// # Example -/// -/// ```rhai -/// let x = 42; -/// -/// eval("let y = x; x = 123;"); -/// -/// print(x); // prints 123 -/// print(y); // prints 42 -/// ``` -fn eval(script: String) -> ?; - -/// Return `true` if the string contains another string. -/// -/// This function also drives the `in` operator. -/// -/// # Example -/// -/// ```rhai -/// let x = "hello world!"; -/// -/// // The 'in' operator calls 'contains' in the background -/// if "world" in x { -/// print("found!"); -/// } -/// ``` -fn contains(string: String, find: String) -> bool; - -/// Return `true` if the string contains a character. -/// -/// This function also drives the `in` operator. -/// -/// # Example -/// -/// ```rhai -/// let x = "hello world!"; -/// -/// // The 'in' operator calls 'contains' in the background -/// if 'w' in x { -/// print("found!"); -/// } -/// ``` -fn contains(string: String, ch: char) -> bool; - -/// Return `true` if a value falls within the exclusive range. -/// -/// This function also drives the `in` operator. -/// -/// # Example -/// -/// ```rhai -/// let r = 1..100; -/// -/// // The 'in' operator calls 'contains' in the background -/// if 42 in r { -/// print("found!"); -/// } -/// ``` -fn contains(range: Range, value: int) -> bool; - -/// Return `true` if a value falls within the inclusive range. -/// -/// This function also drives the `in` operator. -/// -/// # Example -/// -/// ```rhai -/// let r = 1..=100; -/// -/// // The 'in' operator calls 'contains' in the background -/// if 42 in r { -/// print("found!"); -/// } -/// ``` -fn contains(range: RangeInclusive, value: int) -> bool; - -/// Return `true` if a key exists within the object map. -/// -/// This function also drives the `in` operator. -/// -/// # Example -/// -/// ```rhai -/// let m = #{a:1, b:2, c:3}; -/// -/// // The 'in' operator calls 'contains' in the background -/// if "c" in m { -/// print("found!"); -/// } -/// ``` -fn contains(map: Map, string: String) -> bool; - -/// Return `true` if a value is found within the BLOB. -/// -/// This function also drives the `in` operator. -/// -/// # Example -/// -/// ```rhai -/// let b = blob(); -/// -/// b += 1; b += 2; b += 3; b += 4; b += 5; -/// -/// // The 'in' operator calls 'contains' in the background -/// if 3 in b { -/// print("found!"); -/// } -/// ``` -fn contains(blob: Blob, value: int) -> bool; - -op minus(int, int) -> int; - -op !(bool) -> bool; - -/// Return `true` if two arrays are not-equal (i.e. any element not equal or not in the same order). -/// -/// The operator `==` is used to compare elements and must be defined, -/// otherwise `false` is assumed. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 5]; -/// let y = [1, 2, 3, 4, 5]; -/// let z = [1, 2, 3, 4]; -/// -/// print(x != y); // prints false -/// -/// print(x != z); // prints true -/// ``` -op !=(Array, Array) -> bool; - -/// Return `true` if two object maps are not equal (i.e. at least one property value is not equal). -/// -/// The operator `==` is used to compare property values and must be defined, -/// otherwise `false` is assumed. -/// -/// # Example -/// -/// ```rhai -/// let m1 = #{a:1, b:2, c:3}; -/// let m2 = #{a:1, b:2, c:3}; -/// let m3 = #{a:1, c:3}; -/// -/// print(m1 != m2); // prints false -/// -/// print(m1 != m3); // prints true -/// ``` -op !=(Map, Map) -> bool; - -/// Return `true` if two timestamps are not equal. -op !=(Instant, Instant) -> bool; - -op !=(int, f32) -> bool; - -op !=(int, float) -> bool; - -op !=(f32, int) -> bool; - -op !=(f32, f32) -> bool; - -op !=(float, int) -> bool; - -op !=(i128, i128) -> bool; - -op !=(i16, i16) -> bool; - -op !=(i32, i32) -> bool; - -op !=(i8, i8) -> bool; - -op !=(u128, u128) -> bool; - -op !=(u16, u16) -> bool; - -op !=(u32, u32) -> bool; - -op !=(u64, u64) -> bool; - -op !=(u8, u8) -> bool; - -op %(int, f32) -> f32; - -op %(f32, int) -> f32; - -op %(f32, f32) -> f32; - -op %(i128, i128) -> i128; - -op %(i16, i16) -> i16; - -op %(i32, i32) -> i32; - -op %(i8, i8) -> i8; - -op %(u128, u128) -> u128; - -op %(u16, u16) -> u16; - -op %(u32, u32) -> u32; - -op %(u64, u64) -> u64; - -op %(u8, u8) -> u8; - -op &(i128, i128) -> i128; - -op &(i16, i16) -> i16; - -op &(i32, i32) -> i32; - -op &(i8, i8) -> i8; - -op &(u128, u128) -> u128; - -op &(u16, u16) -> u16; - -op &(u32, u32) -> u32; - -op &(u64, u64) -> u64; - -op &(u8, u8) -> u8; - -op *(int, f32) -> f32; - -op *(f32, int) -> f32; - -op *(f32, f32) -> f32; - -op *(i128, i128) -> i128; - -op *(i16, i16) -> i16; - -op *(i32, i32) -> i32; - -op *(i8, i8) -> i8; - -op *(u128, u128) -> u128; - -op *(u16, u16) -> u16; - -op *(u32, u32) -> u32; - -op *(u64, u64) -> u64; - -op *(u8, u8) -> u8; - -op **(f32, int) -> f32; - -op **(f32, f32) -> f32; - -op **(i128, int) -> i128; - -op **(i16, int) -> i16; - -op **(i32, int) -> i32; - -op **(i8, int) -> i8; - -op **(u128, int) -> u128; - -op **(u16, int) -> u16; - -op **(u32, int) -> u32; - -op **(u64, int) -> u64; - -op **(u8, int) -> u8; - -op +(int) -> int; - -op +(f32) -> f32; - -op +(float) -> float; - -op +(i128) -> i128; - -op +(i16) -> i16; - -op +(i32) -> i32; - -op +(i8) -> i8; - -op +((), String) -> String; - -/// Combine two arrays into a new array and return it. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3]; -/// let y = [true, 'x']; -/// -/// print(x + y); // prints "[1, 2, 3, true, 'x']" -/// -/// print(x); // prints "[1, 2, 3" -/// ``` -op +(Array, Array) -> Array; - -op +(char, String) -> String; - -op +(?, String) -> String; - -/// Make a copy of the object map, add all property values of another object map -/// (existing property values of the same names are replaced), then returning it. -/// -/// # Example -/// -/// ```rhai -/// let m = #{a:1, b:2, c:3}; -/// let n = #{a: 42, d:0}; -/// -/// print(m + n); // prints "#{a:42, b:2, c:3, d:0}" -/// -/// print(m); // prints "#{a:1, b:2, c:3}" -/// ``` -op +(Map, Map) -> Map; - -op +(String, String) -> String; - -op +(String, char) -> String; - -op +(String, ?) -> String; - -op +(String, Blob) -> String; - -op +(String, ()) -> String; - -/// Add the specified number of `seconds` to the timestamp and return it as a new timestamp. -op +(Instant, float) -> Instant; - -/// Add the specified number of `seconds` to the timestamp and return it as a new timestamp. -op +(Instant, int) -> Instant; - -op +(Blob, String) -> String; - -op +(int, f32) -> f32; - -op +(f32, int) -> f32; - -op +(f32, f32) -> f32; - -op +(i128, i128) -> i128; - -op +(i16, i16) -> i16; - -op +(i32, i32) -> i32; - -op +(i8, i8) -> i8; - -op +(u128, u128) -> u128; - -op +(u16, u16) -> u16; - -op +(u32, u32) -> u32; - -op +(u64, u64) -> u64; - -op +(u8, u8) -> u8; - -/// Add all property values of another object map into the object map. -/// Existing property values of the same names are replaced. -/// -/// # Example -/// -/// ```rhai -/// let m = #{a:1, b:2, c:3}; -/// let n = #{a: 42, d:0}; -/// -/// m.mixin(n); -/// -/// print(m); // prints "#{a:42, b:2, c:3, d:0}" -/// ``` -op +=(Map, Map) -> (); - -op +=(String, String) -> (); - -op +=(String, char) -> (); - -op +=(String, ()) -> (); - -op +=(String, ?) -> (); - -op +=(String, Blob) -> (); - -/// Add the specified number of `seconds` to the timestamp. -op +=(Instant, float) -> (); - -/// Add the specified number of `seconds` to the timestamp. -op +=(Instant, int) -> (); - -op -(int) -> int; - -op -(f32) -> f32; - -op -(float) -> float; - -op -(i128) -> i128; - -op -(i16) -> i16; - -op -(i32) -> i32; - -op -(i8) -> i8; - -/// Return the number of seconds between two timestamps. -op -(Instant, Instant) -> RhaiResult; - -/// Subtract the specified number of `seconds` from the timestamp and return it as a new timestamp. -op -(Instant, float) -> Instant; - -/// Subtract the specified number of `seconds` from the timestamp and return it as a new timestamp. -op -(Instant, int) -> Instant; - -op -(int, f32) -> f32; - -op -(f32, int) -> f32; - -op -(f32, f32) -> f32; - -op -(i128, i128) -> i128; - -op -(i16, i16) -> i16; - -op -(i32, i32) -> i32; - -op -(i8, i8) -> i8; - -op -(u128, u128) -> u128; - -op -(u16, u16) -> u16; - -op -(u32, u32) -> u32; - -op -(u64, u64) -> u64; - -op -(u8, u8) -> u8; - -/// Subtract the specified number of `seconds` from the timestamp. -op -=(Instant, float) -> (); - -/// Subtract the specified number of `seconds` from the timestamp. -op -=(Instant, int) -> (); - -op /(int, f32) -> f32; - -op /(f32, int) -> f32; - -op /(f32, f32) -> f32; - -op /(i128, i128) -> i128; - -op /(i16, i16) -> i16; - -op /(i32, i32) -> i32; - -op /(i8, i8) -> i8; - -op /(u128, u128) -> u128; - -op /(u16, u16) -> u16; - -op /(u32, u32) -> u32; - -op /(u64, u64) -> u64; - -op /(u8, u8) -> u8; - -/// Return `true` if the first timestamp is earlier than the second. -op <(Instant, Instant) -> bool; - -op <(int, f32) -> bool; - -op <(int, float) -> bool; - -op <(f32, int) -> bool; - -op <(f32, f32) -> bool; - -op <(float, int) -> bool; - -op <(i128, i128) -> bool; - -op <(i16, i16) -> bool; - -op <(i32, i32) -> bool; - -op <(i8, i8) -> bool; - -op <(u128, u128) -> bool; - -op <(u16, u16) -> bool; - -op <(u32, u32) -> bool; - -op <(u64, u64) -> bool; - -op <(u8, u8) -> bool; - -op <<(i128, int) -> i128; - -op <<(i16, int) -> i16; - -op <<(i32, int) -> i32; - -op <<(i8, int) -> i8; - -op <<(u128, int) -> u128; - -op <<(u16, int) -> u16; - -op <<(u32, int) -> u32; - -op <<(u64, int) -> u64; - -op <<(u8, int) -> u8; - -/// Return `true` if the first timestamp is earlier than or equals to the second. -op <=(Instant, Instant) -> bool; - -op <=(int, f32) -> bool; - -op <=(int, float) -> bool; - -op <=(f32, int) -> bool; - -op <=(f32, f32) -> bool; - -op <=(float, int) -> bool; - -op <=(i128, i128) -> bool; - -op <=(i16, i16) -> bool; - -op <=(i32, i32) -> bool; - -op <=(i8, i8) -> bool; - -op <=(u128, u128) -> bool; - -op <=(u16, u16) -> bool; - -op <=(u32, u32) -> bool; - -op <=(u64, u64) -> bool; - -op <=(u8, u8) -> bool; - -/// Return `true` if two arrays are equal (i.e. all elements are equal and in the same order). -/// -/// The operator `==` is used to compare elements and must be defined, -/// otherwise `false` is assumed. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 5]; -/// let y = [1, 2, 3, 4, 5]; -/// let z = [1, 2, 3, 4]; -/// -/// print(x == y); // prints true -/// -/// print(x == z); // prints false -/// ``` -op ==(Array, Array) -> bool; - -/// Return `true` if two object maps are equal (i.e. all property values are equal). -/// -/// The operator `==` is used to compare property values and must be defined, -/// otherwise `false` is assumed. -/// -/// # Example -/// -/// ```rhai -/// let m1 = #{a:1, b:2, c:3}; -/// let m2 = #{a:1, b:2, c:3}; -/// let m3 = #{a:1, c:3}; -/// -/// print(m1 == m2); // prints true -/// -/// print(m1 == m3); // prints false -/// ``` -op ==(Map, Map) -> bool; - -/// Return `true` if two timestamps are equal. -op ==(Instant, Instant) -> bool; - -op ==(int, f32) -> bool; - -op ==(int, float) -> bool; - -op ==(f32, int) -> bool; - -op ==(f32, f32) -> bool; - -op ==(float, int) -> bool; - -op ==(i128, i128) -> bool; - -op ==(i16, i16) -> bool; - -op ==(i32, i32) -> bool; - -op ==(i8, i8) -> bool; - -op ==(u128, u128) -> bool; - -op ==(u16, u16) -> bool; - -op ==(u32, u32) -> bool; - -op ==(u64, u64) -> bool; - -op ==(u8, u8) -> bool; - -/// Return `true` if the first timestamp is later than the second. -op >(Instant, Instant) -> bool; - -op >(int, f32) -> bool; - -op >(int, float) -> bool; - -op >(f32, int) -> bool; - -op >(f32, f32) -> bool; - -op >(float, int) -> bool; - -op >(i128, i128) -> bool; - -op >(i16, i16) -> bool; - -op >(i32, i32) -> bool; - -op >(i8, i8) -> bool; - -op >(u128, u128) -> bool; - -op >(u16, u16) -> bool; - -op >(u32, u32) -> bool; - -op >(u64, u64) -> bool; - -op >(u8, u8) -> bool; - -/// Return `true` if the first timestamp is later than or equals to the second. -op >=(Instant, Instant) -> bool; - -op >=(int, f32) -> bool; - -op >=(int, float) -> bool; - -op >=(f32, int) -> bool; - -op >=(f32, f32) -> bool; - -op >=(float, int) -> bool; - -op >=(i128, i128) -> bool; - -op >=(i16, i16) -> bool; - -op >=(i32, i32) -> bool; - -op >=(i8, i8) -> bool; - -op >=(u128, u128) -> bool; - -op >=(u16, u16) -> bool; - -op >=(u32, u32) -> bool; - -op >=(u64, u64) -> bool; - -op >=(u8, u8) -> bool; - -op >>(i128, int) -> i128; - -op >>(i16, int) -> i16; - -op >>(i32, int) -> i32; - -op >>(i8, int) -> i8; - -op >>(u128, int) -> u128; - -op >>(u16, int) -> u16; - -op >>(u32, int) -> u32; - -op >>(u64, int) -> u64; - -op >>(u8, int) -> u8; - -/// Return the natural number _e_. -fn E() -> float; - -/// Return the number π. -fn PI() -> float; - -op ^(i128, i128) -> i128; - -op ^(i16, i16) -> i16; - -op ^(i32, i32) -> i32; - -op ^(i8, i8) -> i8; - -op ^(u128, u128) -> u128; - -op ^(u16, u16) -> u16; - -op ^(u32, u32) -> u32; - -op ^(u64, u64) -> u64; - -op ^(u8, u8) -> u8; - -/// Return the absolute value of the number. -fn abs(x: int) -> int; - -/// Return the absolute value of the floating-point number. -fn abs(x: f32) -> f32; - -/// Return the absolute value of the floating-point number. -fn abs(x: float) -> float; - -/// Return the absolute value of the number. -fn abs(x: i128) -> i128; - -/// Return the absolute value of the number. -fn abs(x: i16) -> i16; - -/// Return the absolute value of the number. -fn abs(x: i32) -> i32; - -/// Return the absolute value of the number. -fn abs(x: i8) -> i8; - -/// Return the arc-cosine of the floating-point number, in radians. -fn acos(x: float) -> float; - -/// Return the arc-hyperbolic-cosine of the floating-point number, in radians. -fn acosh(x: float) -> float; - -/// Return `true` if all elements in the array return `true` when applied a function named by `filter`. -/// -/// # Function Parameters -/// -/// A function with the same name as the value of `filter` must exist taking these parameters: -/// -/// * `element`: copy of array element -/// * `index` _(optional)_: current index in the array -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 5]; -/// -/// print(x.all(|v| v > 3)); // prints false -/// -/// print(x.all(|v| v > 1)); // prints true -/// -/// print(x.all(|v, i| i > v)); // prints false -/// ``` -fn all(array: Array, filter: String) -> bool; - -/// Return `true` if all elements in the array return `true` when applied the `filter` function. -/// -/// # Function Parameters -/// -/// * `element`: copy of array element -/// * `index` _(optional)_: current index in the array -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 5]; -/// -/// print(x.all(|v| v > 3)); // prints false -/// -/// print(x.all(|v| v > 1)); // prints true -/// -/// print(x.all(|v, i| i > v)); // prints false -/// ``` -fn all(array: Array, filter: FnPtr) -> bool; - -/// Add all the elements of another array to the end of the array. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3]; -/// let y = [true, 'x']; -/// -/// x.append(y); -/// -/// print(x); // prints "[1, 2, 3, true, 'x']" -/// ``` -fn append(array: Array, new_array: Array) -> (); - -/// Add another BLOB to the end of the BLOB. -/// -/// # Example -/// -/// ```rhai -/// let b1 = blob(5, 0x42); -/// let b2 = blob(3, 0x11); -/// -/// b1.push(b2); -/// -/// print(b1); // prints "[4242424242111111]" -/// ``` -fn append(blob1: Blob, blob2: Blob) -> (); - -/// Add a character (as UTF-8 encoded byte-stream) to the end of the BLOB -/// -/// # Example -/// -/// ```rhai -/// let b = blob(5, 0x42); -/// -/// b.append('!'); -/// -/// print(b); // prints "[424242424221]" -/// ``` -fn append(blob: Blob, character: char) -> (); - -/// Add a string (as UTF-8 encoded byte-stream) to the end of the BLOB -/// -/// # Example -/// -/// ```rhai -/// let b = blob(5, 0x42); -/// -/// b.append("hello"); -/// -/// print(b); // prints "[424242424268656c 6c6f]" -/// ``` -fn append(blob: Blob, string: String) -> (); - -/// Add a new byte `value` to the end of the BLOB. -/// -/// Only the lower 8 bits of the `value` are used; all other bits are ignored. -/// -/// # Example -/// -/// ```rhai -/// let b = blob(); -/// -/// b.push(0x42); -/// -/// print(b); // prints "[42]" -/// ``` -fn append(blob: Blob, value: int) -> (); - -fn append(string: String, item: ?) -> (); - -fn append(string: String, utf8: Blob) -> (); - -/// Convert the BLOB into a string. -/// -/// The byte stream must be valid UTF-8, otherwise an error is raised. -/// -/// # Example -/// -/// ```rhai -/// let b = blob(5, 0x42); -/// -/// let x = b.as_string(); -/// -/// print(x); // prints "FFFFF" -/// ``` -fn as_string(blob: Blob) -> String; - -/// Return the arc-sine of the floating-point number, in radians. -fn asin(x: float) -> float; - -/// Return the arc-hyperbolic-sine of the floating-point number, in radians. -fn asinh(x: float) -> float; - -/// Return the arc-tangent of the floating-point number, in radians. -fn atan(x: float) -> float; - -/// Return the arc-tangent of the floating-point numbers `x` and `y`, in radians. -fn atan(x: float, y: float) -> float; - -/// Return the arc-hyperbolic-tangent of the floating-point number, in radians. -fn atanh(x: float) -> float; - -/// Return an iterator over all the bits in the number. -/// -/// # Example -/// -/// ```rhai -/// let x = 123456; -/// -/// for bit in x.bits() { -/// print(bit); -/// } -/// ``` -fn bits(value: int) -> Iterator; - -/// Return an iterator over the bits in the number starting from the specified `start` position. -/// -/// If `start` < 0, position counts from the MSB (Most Significant Bit)>. -/// -/// # Example -/// -/// ```rhai -/// let x = 123456; -/// -/// for bit in x.bits(10) { -/// print(bit); -/// } -/// ``` -fn bits(value: int, from: int) -> Iterator; - -/// Return an iterator over an exclusive range of bits in the number. -/// -/// # Example -/// -/// ```rhai -/// let x = 123456; -/// -/// for bit in x.bits(10..24) { -/// print(bit); -/// } -/// ``` -fn bits(value: int, range: Range) -> Iterator; - -/// Return an iterator over an inclusive range of bits in the number. -/// -/// # Example -/// -/// ```rhai -/// let x = 123456; -/// -/// for bit in x.bits(10..=23) { -/// print(bit); -/// } -/// ``` -fn bits(value: int, range: RangeInclusive) -> Iterator; - -/// Return an iterator over a portion of bits in the number. -/// -/// * If `start` < 0, position counts from the MSB (Most Significant Bit)>. -/// * If `len` ≤ 0, an empty iterator is returned. -/// * If `start` position + `len` ≥ length of string, all bits of the number after the `start` position are iterated. -/// -/// # Example -/// -/// ```rhai -/// let x = 123456; -/// -/// for bit in x.bits(10, 8) { -/// print(bit); -/// } -/// ``` -fn bits(value: int, from: int, len: int) -> Iterator; - -/// Return a new, empty BLOB. -fn blob() -> Blob; - -/// Return a new BLOB of the specified length, filled with zeros. -/// -/// If `len` ≤ 0, an empty BLOB is returned. -/// -/// # Example -/// -/// ```rhai -/// let b = blob(10); -/// -/// print(b); // prints "[0000000000000000 0000]" -/// ``` -fn blob(len: int) -> Blob; - -/// Return a new BLOB of the specified length, filled with copies of the initial `value`. -/// -/// If `len` ≤ 0, an empty BLOB is returned. -/// -/// Only the lower 8 bits of the initial `value` are used; all other bits are ignored. -/// -/// # Example -/// -/// ```rhai -/// let b = blob(10, 0x42); -/// -/// print(b); // prints "[4242424242424242 4242]" -/// ``` -fn blob(len: int, value: int) -> Blob; - -/// Return the length of the string, in number of bytes used to store it in UTF-8 encoding. -/// -/// # Example -/// -/// ```rhai -/// let text = "朝には紅顔ありて夕べには白骨となる"; -/// -/// print(text.bytes); // prints 51 -/// ``` -fn bytes(string: String) -> int; - -/// Return the smallest whole number larger than or equals to the floating-point number. -fn ceiling(x: float) -> float; - -/// Return an iterator over the characters in the string. -/// -/// # Example -/// -/// ```rhai -/// for ch in "hello, world!".chars() { -/// print(ch); -/// } -/// ``` -fn chars(string: String) -> Iterator; - -/// Return an iterator over the characters in the string starting from the `start` position. -/// -/// * If `start` < 0, position counts from the end of the string (`-1` is the last character). -/// * If `start` < -length of string, position counts from the beginning of the string. -/// * If `start` ≥ length of string, an empty iterator is returned. -/// -/// # Example -/// -/// ```rhai -/// for ch in "hello, world!".chars(2) { -/// print(ch); -/// } -/// ``` -fn chars(string: String, from: int) -> Iterator; - -/// Return an iterator over an exclusive range of characters in the string. -/// -/// # Example -/// -/// ```rhai -/// for ch in "hello, world!".chars(2..5) { -/// print(ch); -/// } -/// ``` -fn chars(string: String, range: Range) -> Iterator; - -/// Return an iterator over an inclusive range of characters in the string. -/// -/// # Example -/// -/// ```rhai -/// for ch in "hello, world!".chars(2..=6) { -/// print(ch); -/// } -/// ``` -fn chars(string: String, range: RangeInclusive) -> Iterator; - -/// Return an iterator over a portion of characters in the string. -/// -/// * If `start` < 0, position counts from the end of the string (`-1` is the last character). -/// * If `start` < -length of string, position counts from the beginning of the string. -/// * If `start` ≥ length of string, an empty iterator is returned. -/// * If `len` ≤ 0, an empty iterator is returned. -/// * If `start` position + `len` ≥ length of string, all characters of the string after the `start` position are iterated. -/// -/// # Example -/// -/// ```rhai -/// for ch in "hello, world!".chars(2, 4) { -/// print(ch); -/// } -/// ``` -fn chars(string: String, start: int, len: int) -> Iterator; - -/// Cut off the head of the array, leaving a tail of the specified length. -/// -/// * If `len` ≤ 0, the array is cleared. -/// * If `len` ≥ length of array, the array is not modified. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 5]; -/// -/// x.chop(3); -/// -/// print(x); // prints "[3, 4, 5]" -/// -/// x.chop(10); -/// -/// print(x); // prints "[3, 4, 5]" -/// ``` -fn chop(array: Array, len: int) -> (); - -/// Cut off the head of the BLOB, leaving a tail of the specified length. -/// -/// * If `len` ≤ 0, the BLOB is cleared. -/// * If `len` ≥ length of BLOB, the BLOB is not modified. -/// -/// # Example -/// -/// ```rhai -/// let b = blob(); -/// -/// b += 1; b += 2; b += 3; b += 4; b += 5; -/// -/// b.chop(3); -/// -/// print(b); // prints "[030405]" -/// -/// b.chop(10); -/// -/// print(b); // prints "[030405]" -/// ``` -fn chop(blob: Blob, len: int) -> (); - -/// Clear the array. -fn clear(array: Array) -> (); - -/// Clear the BLOB. -fn clear(blob: Blob) -> (); - -/// Clear the object map. -fn clear(map: Map) -> (); - -/// Clear the string, making it empty. -fn clear(string: String) -> (); - -/// Return `true` if the array contains an element that equals `value`. -/// -/// The operator `==` is used to compare elements with `value` and must be defined, -/// otherwise `false` is assumed. -/// -/// This function also drives the `in` operator. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 5]; -/// -/// // The 'in' operator calls 'contains' in the background -/// if 4 in x { -/// print("found!"); -/// } -/// ``` -fn contains(array: Array, value: ?) -> bool; - -/// Return `true` if the BLOB contains a specified byte value. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world!"; -/// -/// print(text.contains('h')); // prints true -/// -/// print(text.contains('x')); // prints false -/// ``` -fn contains(blob: Blob, value: int) -> bool; - -/// Returns `true` if the object map contains a specified property. -/// -/// # Example -/// -/// ```rhai -/// let m = #{a: 1, b: 2, c: 3}; -/// -/// print(m.contains("b")); // prints true -/// -/// print(m.contains("x")); // prints false -/// ``` -fn contains(map: Map, property: String) -> bool; - -/// Return `true` if the range contains a specified value. -fn contains(range: ExclusiveRange, value: int) -> bool; - -/// Return `true` if the range contains a specified value. -fn contains(range: InclusiveRange, value: int) -> bool; - -/// Return `true` if the string contains a specified character. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world!"; -/// -/// print(text.contains('h')); // prints true -/// -/// print(text.contains('x')); // prints false -/// ``` -fn contains(string: String, character: char) -> bool; - -/// Return `true` if the string contains a specified string. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world!"; -/// -/// print(text.contains("hello")); // prints true -/// -/// print(text.contains("hey")); // prints false -/// ``` -fn contains(string: String, match_string: String) -> bool; - -/// Return the cosine of the floating-point number in radians. -fn cos(x: float) -> float; - -/// Return the hyperbolic cosine of the floating-point number in radians. -fn cosh(x: float) -> float; - -/// Remove all characters from the string except those within an exclusive `range`. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world!"; -/// -/// text.crop(2..8); -/// -/// print(text); // prints "llo, w" -/// ``` -fn crop(string: String, range: Range) -> (); - -/// Remove all characters from the string except those within an inclusive `range`. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world!"; -/// -/// text.crop(2..=8); -/// -/// print(text); // prints "llo, wo" -/// ``` -fn crop(string: String, range: RangeInclusive) -> (); - -/// Remove all characters from the string except until the `start` position. -/// -/// * If `start` < 0, position counts from the end of the string (`-1` is the last character). -/// * If `start` < -length of string, the string is not modified. -/// * If `start` ≥ length of string, the entire string is cleared. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world!"; -/// -/// text.crop(5); -/// -/// print(text); // prints ", world!" -/// -/// text.crop(-3); -/// -/// print(text); // prints "ld!" -/// ``` -fn crop(string: String, start: int) -> (); - -/// Remove all characters from the string except those within a range. -/// -/// * If `start` < 0, position counts from the end of the string (`-1` is the last character). -/// * If `start` < -length of string, position counts from the beginning of the string. -/// * If `start` ≥ length of string, the entire string is cleared. -/// * If `len` ≤ 0, the entire string is cleared. -/// * If `start` position + `len` ≥ length of string, only the portion of the string after the `start` position is retained. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world!"; -/// -/// text.crop(2, 8); -/// -/// print(text); // prints "llo, wor" -/// -/// text.crop(-5, 3); -/// -/// print(text); // prints ", w" -/// ``` -fn crop(string: String, start: int, len: int) -> (); - -/// Return the empty string. -op debug() -> String; - -/// Convert the array into a string. -op debug(Array) -> String; - -/// Convert the string into debug format. -op debug(char) -> String; - -/// Convert the function pointer into a string in debug format. -op debug(FnPtr) -> String; - -/// Convert the value of the `item` into a string in debug format. -op debug(?) -> String; - -/// Convert the object map into a string. -op debug(Map) -> String; - -/// Convert the value of `number` into a string. -op debug(f32) -> String; - -/// Convert the value of `number` into a string. -op debug(float) -> String; - -/// Convert the string into debug format. -op debug(String) -> String; - -/// Convert the unit into a string in debug format. -op debug(()) -> String; - -/// Convert the boolean value into a string in debug format. -op debug(bool) -> String; - -/// Remove duplicated _consecutive_ elements from the array. -/// -/// The operator `==` is used to compare elements and must be defined, -/// otherwise `false` is assumed. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 2, 2, 3, 4, 3, 3, 2, 1]; -/// -/// x.dedup(); -/// -/// print(x); // prints "[1, 2, 3, 4, 3, 2, 1]" -/// ``` -fn dedup(array: Array) -> (); - -/// Remove duplicated _consecutive_ elements from the array that return `true` when applied a -/// function named by `comparer`. -/// -/// No element is removed if the correct `comparer` function does not exist. -/// -/// # Function Parameters -/// -/// * `element1`: copy of the current array element to compare -/// * `element2`: copy of the next array element to compare -/// -/// ## Return Value -/// -/// `true` if `element1 == element2`, otherwise `false`. -/// -/// # Example -/// -/// ```rhai -/// fn declining(a, b) { a >= b } -/// -/// let x = [1, 2, 2, 2, 3, 1, 2, 3, 4, 3, 3, 2, 1]; -/// -/// x.dedup("declining"); -/// -/// print(x); // prints "[1, 2, 3, 4]" -/// ``` -fn dedup(array: Array, comparer: String) -> (); - -/// Remove duplicated _consecutive_ elements from the array that return `true` when applied the -/// `comparer` function. -/// -/// No element is removed if the correct `comparer` function does not exist. -/// -/// # Function Parameters -/// -/// * `element1`: copy of the current array element to compare -/// * `element2`: copy of the next array element to compare -/// -/// ## Return Value -/// -/// `true` if `element1 == element2`, otherwise `false`. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 2, 2, 3, 1, 2, 3, 4, 3, 3, 2, 1]; -/// -/// x.dedup(|a, b| a >= b); -/// -/// print(x); // prints "[1, 2, 3, 4]" -/// ``` -fn dedup(array: Array, comparer: FnPtr) -> (); - -/// Remove all elements in the array that returns `true` when applied a function named by `filter` -/// and return them as a new array. -/// -/// # Function Parameters -/// -/// A function with the same name as the value of `filter` must exist taking these parameters: -/// -/// * `element`: copy of array element -/// * `index` _(optional)_: current index in the array -/// -/// # Example -/// -/// ```rhai -/// fn small(x) { x < 3 } -/// -/// fn screen(x, i) { x + i > 5 } -/// -/// let x = [1, 2, 3, 4, 5]; -/// -/// let y = x.drain("small"); -/// -/// print(x); // prints "[3, 4, 5]" -/// -/// print(y); // prints "[1, 2]" -/// -/// let z = x.drain("screen"); -/// -/// print(x); // prints "[3, 4]" -/// -/// print(z); // prints "[5]" -/// ``` -fn drain(array: Array, filter: String) -> Array; - -/// Remove all elements in the array that returns `true` when applied the `filter` function and -/// return them as a new array. -/// -/// # Function Parameters -/// -/// * `element`: copy of array element -/// * `index` _(optional)_: current index in the array -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 5]; -/// -/// let y = x.drain(|v| v < 3); -/// -/// print(x); // prints "[3, 4, 5]" -/// -/// print(y); // prints "[1, 2]" -/// -/// let z = x.drain(|v, i| v + i > 5); -/// -/// print(x); // prints "[3, 4]" -/// -/// print(z); // prints "[5]" -/// ``` -fn drain(array: Array, filter: FnPtr) -> Array; - -/// Remove all elements in the array within an exclusive `range` and return them as a new array. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 5]; -/// -/// let y = x.drain(1..3); -/// -/// print(x); // prints "[1, 4, 5]" -/// -/// print(y); // prints "[2, 3]" -/// -/// let z = x.drain(2..3); -/// -/// print(x); // prints "[1, 4]" -/// -/// print(z); // prints "[5]" -/// ``` -fn drain(array: Array, range: Range) -> Array; - -/// Remove all elements in the array within an inclusive `range` and return them as a new array. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 5]; -/// -/// let y = x.drain(1..=2); -/// -/// print(x); // prints "[1, 4, 5]" -/// -/// print(y); // prints "[2, 3]" -/// -/// let z = x.drain(2..=2); -/// -/// print(x); // prints "[1, 4]" -/// -/// print(z); // prints "[5]" -/// ``` -fn drain(array: Array, range: RangeInclusive) -> Array; - -/// Remove all bytes in the BLOB within an exclusive `range` and return them as a new BLOB. -/// -/// # Example -/// -/// ```rhai -/// let b1 = blob(); -/// -/// b1 += 1; b1 += 2; b1 += 3; b1 += 4; b1 += 5; -/// -/// let b2 = b1.drain(1..3); -/// -/// print(b1); // prints "[010405]" -/// -/// print(b2); // prints "[0203]" -/// -/// let b3 = b1.drain(2..3); -/// -/// print(b1); // prints "[0104]" -/// -/// print(b3); // prints "[05]" -/// ``` -fn drain(blob: Blob, range: Range) -> Blob; - -/// Remove all bytes in the BLOB within an inclusive `range` and return them as a new BLOB. -/// -/// # Example -/// -/// ```rhai -/// let b1 = blob(); -/// -/// b1 += 1; b1 += 2; b1 += 3; b1 += 4; b1 += 5; -/// -/// let b2 = b1.drain(1..=2); -/// -/// print(b1); // prints "[010405]" -/// -/// print(b2); // prints "[0203]" -/// -/// let b3 = b1.drain(2..=2); -/// -/// print(b1); // prints "[0104]" -/// -/// print(b3); // prints "[05]" -/// ``` -fn drain(blob: Blob, range: RangeInclusive) -> Blob; - -/// Remove all elements within a portion of the array and return them as a new array. -/// -/// * If `start` < 0, position counts from the end of the array (`-1` is the last element). -/// * If `start` < -length of array, position counts from the beginning of the array. -/// * If `start` ≥ length of array, no element is removed and an empty array is returned. -/// * If `len` ≤ 0, no element is removed and an empty array is returned. -/// * If `start` position + `len` ≥ length of array, entire portion of the array after the `start` position is removed and returned. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 5]; -/// -/// let y = x.drain(1, 2); -/// -/// print(x); // prints "[1, 4, 5]" -/// -/// print(y); // prints "[2, 3]" -/// -/// let z = x.drain(-1, 1); -/// -/// print(x); // prints "[1, 4]" -/// -/// print(z); // prints "[5]" -/// ``` -fn drain(array: Array, start: int, len: int) -> Array; - -/// Remove all bytes within a portion of the BLOB and return them as a new BLOB. -/// -/// * If `start` < 0, position counts from the end of the BLOB (`-1` is the last byte). -/// * If `start` < -length of BLOB, position counts from the beginning of the BLOB. -/// * If `start` ≥ length of BLOB, nothing is removed and an empty BLOB is returned. -/// * If `len` ≤ 0, nothing is removed and an empty BLOB is returned. -/// * If `start` position + `len` ≥ length of BLOB, entire portion of the BLOB after the `start` position is removed and returned. -/// -/// # Example -/// -/// ```rhai -/// let b1 = blob(); -/// -/// b1 += 1; b1 += 2; b1 += 3; b1 += 4; b1 += 5; -/// -/// let b2 = b1.drain(1, 2); -/// -/// print(b1); // prints "[010405]" -/// -/// print(b2); // prints "[0203]" -/// -/// let b3 = b1.drain(-1, 1); -/// -/// print(b3); // prints "[0104]" -/// -/// print(z); // prints "[5]" -/// ``` -fn drain(blob: Blob, start: int, len: int) -> Blob; - -/// Return the number of seconds between the current system time and the timestamp. -/// -/// # Example -/// -/// ```rhai -/// let now = timestamp(); -/// -/// sleep(10.0); // sleep for 10 seconds -/// -/// print(now.elapsed); // prints 10.??? -/// ``` -fn elapsed(timestamp: Instant) -> RhaiResult; - -/// Return the end of the exclusive range. -fn end(range: ExclusiveRange) -> int; - -/// Return the end of the inclusive range. -fn end(range: InclusiveRange) -> int; - -/// Return `true` if the string ends with a specified string. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world!"; -/// -/// print(text.ends_with("world!")); // prints true -/// -/// print(text.ends_with("hello")); // prints false -/// ``` -fn ends_with(string: String, match_string: String) -> bool; - -/// Return the exponential of the floating-point number. -fn exp(x: float) -> float; - -/// Copy an exclusive range of the array and return it as a new array. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 5]; -/// -/// print(x.extract(1..3)); // prints "[2, 3]" -/// -/// print(x); // prints "[1, 2, 3, 4, 5]" -/// ``` -fn extract(array: Array, range: Range) -> Array; - -/// Copy an inclusive range of the array and return it as a new array. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 5]; -/// -/// print(x.extract(1..=3)); // prints "[2, 3, 4]" -/// -/// print(x); // prints "[1, 2, 3, 4, 5]" -/// ``` -fn extract(array: Array, range: RangeInclusive) -> Array; - -/// Copy a portion of the array beginning at the `start` position till the end and return it as -/// a new array. -/// -/// * If `start` < 0, position counts from the end of the array (`-1` is the last element). -/// * If `start` < -length of array, the entire array is copied and returned. -/// * If `start` ≥ length of array, an empty array is returned. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 5]; -/// -/// print(x.extract(2)); // prints "[3, 4, 5]" -/// -/// print(x.extract(-3)); // prints "[3, 4, 5]" -/// -/// print(x); // prints "[1, 2, 3, 4, 5]" -/// ``` -fn extract(array: Array, start: int) -> Array; - -/// Copy an exclusive `range` of the BLOB and return it as a new BLOB. -/// -/// # Example -/// -/// ```rhai -/// let b = blob(); -/// -/// b += 1; b += 2; b += 3; b += 4; b += 5; -/// -/// print(b.extract(1..3)); // prints "[0203]" -/// -/// print(b); // prints "[0102030405]" -/// ``` -fn extract(blob: Blob, range: Range) -> Blob; - -/// Copy an inclusive `range` of the BLOB and return it as a new BLOB. -/// -/// # Example -/// -/// ```rhai -/// let b = blob(); -/// -/// b += 1; b += 2; b += 3; b += 4; b += 5; -/// -/// print(b.extract(1..=3)); // prints "[020304]" -/// -/// print(b); // prints "[0102030405]" -/// ``` -fn extract(blob: Blob, range: RangeInclusive) -> Blob; - -/// Copy a portion of the BLOB beginning at the `start` position till the end and return it as -/// a new BLOB. -/// -/// * If `start` < 0, position counts from the end of the BLOB (`-1` is the last byte). -/// * If `start` < -length of BLOB, the entire BLOB is copied and returned. -/// * If `start` ≥ length of BLOB, an empty BLOB is returned. -/// -/// # Example -/// -/// ```rhai -/// let b = blob(); -/// -/// b += 1; b += 2; b += 3; b += 4; b += 5; -/// -/// print(b.extract(2)); // prints "[030405]" -/// -/// print(b.extract(-3)); // prints "[030405]" -/// -/// print(b); // prints "[0102030405]" -/// ``` -fn extract(blob: Blob, start: int) -> Blob; - -/// Copy a portion of the array and return it as a new array. -/// -/// * If `start` < 0, position counts from the end of the array (`-1` is the last element). -/// * If `start` < -length of array, position counts from the beginning of the array. -/// * If `start` ≥ length of array, an empty array is returned. -/// * If `len` ≤ 0, an empty array is returned. -/// * If `start` position + `len` ≥ length of array, entire portion of the array after the `start` position is copied and returned. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 5]; -/// -/// print(x.extract(1, 3)); // prints "[2, 3, 4]" -/// -/// print(x.extract(-3, 2)); // prints "[3, 4]" -/// -/// print(x); // prints "[1, 2, 3, 4, 5]" -/// ``` -fn extract(array: Array, start: int, len: int) -> Array; - -/// Copy a portion of the BLOB and return it as a new BLOB. -/// -/// * If `start` < 0, position counts from the end of the BLOB (`-1` is the last byte). -/// * If `start` < -length of BLOB, position counts from the beginning of the BLOB. -/// * If `start` ≥ length of BLOB, an empty BLOB is returned. -/// * If `len` ≤ 0, an empty BLOB is returned. -/// * If `start` position + `len` ≥ length of BLOB, entire portion of the BLOB after the `start` position is copied and returned. -/// -/// # Example -/// -/// ```rhai -/// let b = blob(); -/// -/// b += 1; b += 2; b += 3; b += 4; b += 5; -/// -/// print(b.extract(1, 3)); // prints "[020303]" -/// -/// print(b.extract(-3, 2)); // prints "[0304]" -/// -/// print(b); // prints "[0102030405]" -/// ``` -fn extract(blob: Blob, start: int, len: int) -> Blob; - -/// Add all property values of another object map into the object map. -/// Only properties that do not originally exist in the object map are added. -/// -/// # Example -/// -/// ```rhai -/// let m = #{a:1, b:2, c:3}; -/// let n = #{a: 42, d:0}; -/// -/// m.fill_with(n); -/// -/// print(m); // prints "#{a:1, b:2, c:3, d:0}" -/// ``` -fn fill_with(map: Map, map2: Map) -> (); - -/// Iterate through all the elements in the array, applying a `filter` function to each element -/// in turn, and return a copy of all elements (in order) that return `true` as a new array. -/// -/// # Function Parameters -/// -/// * `element`: copy of array element -/// * `index` _(optional)_: current index in the array -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 5]; -/// -/// let y = x.filter(|v| v >= 3); -/// -/// print(y); // prints "[3, 4, 5]" -/// -/// let y = x.filter(|v, i| v * i >= 10); -/// -/// print(y); // prints "[12, 20]" -/// ``` -fn filter(array: Array, filter: FnPtr) -> Array; - -/// Iterate through all the elements in the array, applying a function named by `filter` to each -/// element in turn, and return a copy of all elements (in order) that return `true` as a new array. -/// -/// # Function Parameters -/// -/// A function with the same name as the value of `filter` must exist taking these parameters: -/// -/// * `element`: copy of array element -/// * `index` _(optional)_: current index in the array -/// -/// # Example -/// -/// ```rhai -/// fn screen(x, i) { x * i >= 10 } -/// -/// let x = [1, 2, 3, 4, 5]; -/// -/// let y = x.filter("is_odd"); -/// -/// print(y); // prints "[1, 3, 5]" -/// -/// let y = x.filter("screen"); -/// -/// print(y); // prints "[12, 20]" -/// ``` -fn filter(array: Array, filter_func: String) -> Array; - -/// Return the largest whole number less than or equals to the floating-point number. -fn floor(x: float) -> float; - -/// Return the fractional part of the floating-point number. -fn fraction(x: float) -> float; - -/// Get a copy of the element at the `index` position in the array. -/// -/// * If `index` < 0, position counts from the end of the array (`-1` is the last element). -/// * If `index` < -length of array, `()` is returned. -/// * If `index` ≥ length of array, `()` is returned. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3]; -/// -/// print(x.get(0)); // prints 1 -/// -/// print(x.get(-1)); // prints 3 -/// -/// print(x.get(99)); // prints empty (for '()') -/// ``` -fn get(array: Array, index: int) -> ?; - -/// Get the byte value at the `index` position in the BLOB. -/// -/// * If `index` < 0, position counts from the end of the BLOB (`-1` is the last element). -/// * If `index` < -length of BLOB, zero is returned. -/// * If `index` ≥ length of BLOB, zero is returned. -/// -/// # Example -/// -/// ```rhai -/// let b = blob(); -/// -/// b += 1; b += 2; b += 3; b += 4; b += 5; -/// -/// print(b.get(0)); // prints 1 -/// -/// print(b.get(-1)); // prints 5 -/// -/// print(b.get(99)); // prints 0 -/// ``` -fn get(blob: Blob, index: int) -> int; - -/// Get the value of the `property` in the object map and return a copy. -/// -/// If `property` does not exist in the object map, `()` is returned. -/// -/// # Example -/// -/// ```rhai -/// let m = #{a: 1, b: 2, c: 3}; -/// -/// print(m.get("b")); // prints 2 -/// -/// print(m.get("x")); // prints empty (for '()') -/// ``` -fn get(map: Map, property: String) -> ?; - -/// Get the character at the `index` position in the string. -/// -/// * If `index` < 0, position counts from the end of the string (`-1` is the last character). -/// * If `index` < -length of string, zero is returned. -/// * If `index` ≥ length of string, zero is returned. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world!"; -/// -/// print(text.get(0)); // prints 'h' -/// -/// print(text.get(-1)); // prints '!' -/// -/// print(text.get(99)); // prints empty (for '()')' -/// ``` -fn get(string: String, index: int) -> ?; - -/// Return an iterator over all the bits in the number. -/// -/// # Example -/// -/// ```rhai -/// let x = 123456; -/// -/// for bit in x.bits { -/// print(bit); -/// } -/// ``` -fn get bits(value: int) -> Iterator; - -/// Return the length of the string, in number of bytes used to store it in UTF-8 encoding. -/// -/// # Example -/// -/// ```rhai -/// let text = "朝には紅顔ありて夕べには白骨となる"; -/// -/// print(text.bytes); // prints 51 -/// ``` -fn get bytes(string: String) -> int; - -/// Return the smallest whole number larger than or equals to the floating-point number. -fn get ceiling(x: float) -> float; - -/// Return an iterator over all the characters in the string. -/// -/// # Example -/// -/// ```rhai -/// for ch in "hello, world!".chars { -/// print(ch); -/// } -/// ``` -fn get chars(string: String) -> Iterator; - -/// Return the number of seconds between the current system time and the timestamp. -/// -/// # Example -/// -/// ```rhai -/// let now = timestamp(); -/// -/// sleep(10.0); // sleep for 10 seconds -/// -/// print(now.elapsed); // prints 10.??? -/// ``` -fn get elapsed(timestamp: Instant) -> RhaiResult; - -/// Return the end of the exclusive range. -fn get end(range: ExclusiveRange) -> int; - -/// Return the end of the inclusive range. -fn get end(range: InclusiveRange) -> int; - -/// Return the largest whole number less than or equals to the floating-point number. -fn get floor(x: float) -> float; - -/// Return the fractional part of the floating-point number. -fn get fraction(x: float) -> float; - -/// Return the integral part of the floating-point number. -fn get int(x: float) -> float; - -/// Return `true` if the function is an anonymous function. -/// -/// # Example -/// -/// ```rhai -/// let f = |x| x * 2; -/// -/// print(f.is_anonymous); // prints true -/// ``` -fn get is_anonymous(fn_ptr: FnPtr) -> bool; - -/// Return true if the array is empty. -fn get is_empty(array: Array) -> bool; - -/// Return true if the BLOB is empty. -fn get is_empty(blob: Blob) -> bool; - -/// Return true if the range contains no items. -fn get is_empty(range: ExclusiveRange) -> bool; - -/// Return true if the range contains no items. -fn get is_empty(range: InclusiveRange) -> bool; - -/// Return true if the string is empty. -fn get is_empty(string: String) -> bool; - -/// Return true if the number is even. -fn get is_even(x: int) -> bool; - -/// Return true if the number is even. -fn get is_even(x: i128) -> bool; - -/// Return true if the number is even. -fn get is_even(x: i16) -> bool; - -/// Return true if the number is even. -fn get is_even(x: i32) -> bool; - -/// Return true if the number is even. -fn get is_even(x: i8) -> bool; - -/// Return true if the number is even. -fn get is_even(x: u128) -> bool; - -/// Return true if the number is even. -fn get is_even(x: u16) -> bool; - -/// Return true if the number is even. -fn get is_even(x: u32) -> bool; - -/// Return true if the number is even. -fn get is_even(x: u64) -> bool; - -/// Return true if the number is even. -fn get is_even(x: u8) -> bool; - -/// Return `true` if the range is exclusive. -fn get is_exclusive(range: ExclusiveRange) -> bool; - -/// Return `true` if the range is exclusive. -fn get is_exclusive(range: InclusiveRange) -> bool; - -/// Return `true` if the floating-point number is finite. -fn get is_finite(x: float) -> bool; - -/// Return `true` if the range is inclusive. -fn get is_inclusive(range: ExclusiveRange) -> bool; - -/// Return `true` if the range is inclusive. -fn get is_inclusive(range: InclusiveRange) -> bool; - -/// Return `true` if the floating-point number is infinite. -fn get is_infinite(x: float) -> bool; - -/// Return `true` if the floating-point number is `NaN` (Not A Number). -fn get is_nan(x: float) -> bool; - -/// Return true if the number is odd. -fn get is_odd(x: int) -> bool; - -/// Return true if the number is odd. -fn get is_odd(x: i128) -> bool; - -/// Return true if the number is odd. -fn get is_odd(x: i16) -> bool; - -/// Return true if the number is odd. -fn get is_odd(x: i32) -> bool; - -/// Return true if the number is odd. -fn get is_odd(x: i8) -> bool; - -/// Return true if the number is odd. -fn get is_odd(x: u128) -> bool; - -/// Return true if the number is odd. -fn get is_odd(x: u16) -> bool; - -/// Return true if the number is odd. -fn get is_odd(x: u32) -> bool; - -/// Return true if the number is odd. -fn get is_odd(x: u64) -> bool; - -/// Return true if the number is odd. -fn get is_odd(x: u8) -> bool; - -/// Return true if the number is zero. -fn get is_zero(x: int) -> bool; - -/// Return true if the floating-point number is zero. -fn get is_zero(x: f32) -> bool; - -/// Return true if the floating-point number is zero. -fn get is_zero(x: float) -> bool; - -/// Return true if the number is zero. -fn get is_zero(x: i128) -> bool; - -/// Return true if the number is zero. -fn get is_zero(x: i16) -> bool; - -/// Return true if the number is zero. -fn get is_zero(x: i32) -> bool; - -/// Return true if the number is zero. -fn get is_zero(x: i8) -> bool; - -/// Return true if the number is zero. -fn get is_zero(x: u128) -> bool; - -/// Return true if the number is zero. -fn get is_zero(x: u16) -> bool; - -/// Return true if the number is zero. -fn get is_zero(x: u32) -> bool; - -/// Return true if the number is zero. -fn get is_zero(x: u64) -> bool; - -/// Return true if the number is zero. -fn get is_zero(x: u8) -> bool; - -/// Number of elements in the array. -fn get len(array: Array) -> int; - -/// Return the length of the BLOB. -/// -/// # Example -/// -/// ```rhai -/// let b = blob(10, 0x42); -/// -/// print(b); // prints "[4242424242424242 4242]" -/// -/// print(b.len()); // prints 10 -/// ``` -fn get len(blob: Blob) -> int; - -/// Return the length of the string, in number of characters. -/// -/// # Example -/// -/// ```rhai -/// let text = "朝には紅顔ありて夕べには白骨となる"; -/// -/// print(text.len); // prints 17 -/// ``` -fn get len(string: String) -> int; - -/// Return the name of the function. -/// -/// # Example -/// -/// ```rhai -/// fn double(x) { x * 2 } -/// -/// let f = Fn("double"); -/// -/// print(f.name); // prints "double" -/// ``` -fn get name(fn_ptr: FnPtr) -> String; - -/// Return the nearest whole number closest to the floating-point number. -/// Rounds away from zero. -fn get round(x: float) -> float; - -/// Return the start of the exclusive range. -fn get start(range: ExclusiveRange) -> int; - -/// Return the start of the inclusive range. -fn get start(range: InclusiveRange) -> int; - -/// Return the _tag_ of a `Dynamic` value. -/// -/// # Example -/// -/// ```rhai -/// let x = "hello, world!"; -/// -/// x.tag = 42; -/// -/// print(x.tag); // prints 42 -/// ``` -fn get tag(value: ?) -> int; - -/// Return `true` if the specified `bit` in the number is set. -/// -/// If `bit` < 0, position counts from the MSB (Most Significant Bit). -/// -/// # Example -/// -/// ```rhai -/// let x = 123456; -/// -/// print(x.get_bit(5)); // prints false -/// -/// print(x.get_bit(6)); // prints true -/// -/// print(x.get_bit(-48)); // prints true on 64-bit -/// ``` -fn get_bit(value: int, bit: int) -> bool; - -/// Return an exclusive range of bits in the number as a new number. -/// -/// # Example -/// -/// ```rhai -/// let x = 123456; -/// -/// print(x.get_bits(5..10)); // print 18 -/// ``` -fn get_bits(value: int, range: Range) -> int; - -/// Return an inclusive range of bits in the number as a new number. -/// -/// # Example -/// -/// ```rhai -/// let x = 123456; -/// -/// print(x.get_bits(5..=9)); // print 18 -/// ``` -fn get_bits(value: int, range: RangeInclusive) -> int; - -/// Return a portion of bits in the number as a new number. -/// -/// * If `start` < 0, position counts from the MSB (Most Significant Bit). -/// * If `bits` ≤ 0, zero is returned. -/// * If `start` position + `bits` ≥ total number of bits, the bits after the `start` position are returned. -/// -/// # Example -/// -/// ```rhai -/// let x = 123456; -/// -/// print(x.get_bits(5, 8)); // print 18 -/// ``` -fn get_bits(value: int, start: int, bits: int) -> int; - -fn get_fn_metadata_list() -> Array; - -fn get_fn_metadata_list(name: String) -> Array; - -fn get_fn_metadata_list(name: String, params: int) -> Array; - -/// Return the hypotenuse of a triangle with sides `x` and `y`. -fn hypot(x: float, y: float) -> float; - -/// Iterate through all the elements in the array, applying a function named by `filter` to each -/// element in turn, and return the index of the first element that returns `true`. -/// If no element returns `true`, `-1` is returned. -/// -/// # Function Parameters -/// -/// A function with the same name as the value of `filter` must exist taking these parameters: -/// -/// * `element`: copy of array element -/// * `index` _(optional)_: current index in the array -/// -/// # Example -/// -/// ```rhai -/// fn is_special(x) { x > 3 } -/// -/// fn is_dumb(x) { x > 8 } -/// -/// let x = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 5]; -/// -/// print(x.index_of("is_special")); // prints 3 -/// -/// print(x.index_of("is_dumb")); // prints -1 -/// ``` -fn index_of(array: Array, filter: String) -> int; - -/// Iterate through all the elements in the array, applying a `filter` function to each element -/// in turn, and return the index of the first element that returns `true`. -/// If no element returns `true`, `-1` is returned. -/// -/// # Function Parameters -/// -/// * `element`: copy of array element -/// * `index` _(optional)_: current index in the array -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 5]; -/// -/// print(x.index_of(|v| v > 3)); // prints 3: 4 > 3 -/// -/// print(x.index_of(|v| v > 8)); // prints -1: nothing is > 8 -/// -/// print(x.index_of(|v, i| v * i > 20)); // prints 7: 4 * 7 > 20 -/// ``` -fn index_of(array: Array, filter: FnPtr) -> int; - -/// Find the first element in the array that equals a particular `value` and return its index. -/// If no element equals `value`, `-1` is returned. -/// -/// The operator `==` is used to compare elements with `value` and must be defined, -/// otherwise `false` is assumed. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 5]; -/// -/// print(x.index_of(4)); // prints 3 (first index) -/// -/// print(x.index_of(9)); // prints -1 -/// -/// print(x.index_of("foo")); // prints -1: strings do not equal numbers -/// ``` -fn index_of(array: Array, value: ?) -> int; - -/// Find the specified `character` in the string and return the first index where it is found. -/// If the `character` is not found, `-1` is returned. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world!"; -/// -/// print(text.index_of('l')); // prints 2 (first index) -/// -/// print(text.index_of('x')); // prints -1 -/// ``` -fn index_of(string: String, character: char) -> int; - -/// Find the specified `character` in the string and return the first index where it is found. -/// If the `character` is not found, `-1` is returned. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world! hello, foobar!"; -/// -/// print(text.index_of("ll")); // prints 2 (first index) -/// -/// print(text.index_of("xx:)); // prints -1 -/// ``` -fn index_of(string: String, find_string: String) -> int; - -/// Iterate through all the elements in the array, starting from a particular `start` position, -/// applying a function named by `filter` to each element in turn, and return the index of the -/// first element that returns `true`. If no element returns `true`, `-1` is returned. -/// -/// * If `start` < 0, position counts from the end of the array (`-1` is the last element). -/// * If `start` < -length of array, position counts from the beginning of the array. -/// * If `start` ≥ length of array, `-1` is returned. -/// -/// # Function Parameters -/// -/// A function with the same name as the value of `filter` must exist taking these parameters: -/// -/// * `element`: copy of array element -/// * `index` _(optional)_: current index in the array -/// -/// # Example -/// -/// ```rhai -/// fn plural(x) { x > 1 } -/// -/// fn singular(x) { x < 2 } -/// -/// fn screen(x, i) { x * i > 20 } -/// -/// let x = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 5]; -/// -/// print(x.index_of("plural", 3)); // prints 5: 2 > 1 -/// -/// print(x.index_of("singular", 9)); // prints -1: nothing < 2 past index 9 -/// -/// print(x.index_of("plural", 15)); // prints -1: nothing found past end of array -/// -/// print(x.index_of("plural", -5)); // prints 9: -5 = start from index 8 -/// -/// print(x.index_of("plural", -99)); // prints 1: -99 = start from beginning -/// -/// print(x.index_of("screen", 8)); // prints 10: 3 * 10 > 20 -/// ``` -fn index_of(array: Array, filter: String, start: int) -> int; - -/// Iterate through all the elements in the array, starting from a particular `start` position, -/// applying a `filter` function to each element in turn, and return the index of the first -/// element that returns `true`. If no element returns `true`, `-1` is returned. -/// -/// * If `start` < 0, position counts from the end of the array (`-1` is the last element). -/// * If `start` < -length of array, position counts from the beginning of the array. -/// * If `start` ≥ length of array, `-1` is returned. -/// -/// # Function Parameters -/// -/// * `element`: copy of array element -/// * `index` _(optional)_: current index in the array -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 5]; -/// -/// print(x.index_of(|v| v > 1, 3)); // prints 5: 2 > 1 -/// -/// print(x.index_of(|v| v < 2, 9)); // prints -1: nothing < 2 past index 9 -/// -/// print(x.index_of(|v| v > 1, 15)); // prints -1: nothing found past end of array -/// -/// print(x.index_of(|v| v > 1, -5)); // prints 9: -5 = start from index 8 -/// -/// print(x.index_of(|v| v > 1, -99)); // prints 1: -99 = start from beginning -/// -/// print(x.index_of(|v, i| v * i > 20, 8)); // prints 10: 3 * 10 > 20 -/// ``` -fn index_of(array: Array, filter: FnPtr, start: int) -> int; - -/// Find the first element in the array, starting from a particular `start` position, that -/// equals a particular `value` and return its index. If no element equals `value`, `-1` is returned. -/// -/// * If `start` < 0, position counts from the end of the array (`-1` is the last element). -/// * If `start` < -length of array, position counts from the beginning of the array. -/// * If `start` ≥ length of array, `-1` is returned. -/// -/// The operator `==` is used to compare elements with `value` and must be defined, -/// otherwise `false` is assumed. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 5]; -/// -/// print(x.index_of(4, 2)); // prints 3 -/// -/// print(x.index_of(4, 5)); // prints 7 -/// -/// print(x.index_of(4, 15)); // prints -1: nothing found past end of array -/// -/// print(x.index_of(4, -5)); // prints 11: -5 = start from index 8 -/// -/// print(x.index_of(9, 1)); // prints -1: nothing equals 9 -/// -/// print(x.index_of("foo", 1)); // prints -1: strings do not equal numbers -/// ``` -fn index_of(array: Array, value: ?, start: int) -> int; - -/// Find the specified `character` in the string, starting from the specified `start` position, -/// and return the first index where it is found. -/// If the `character` is not found, `-1` is returned. -/// -/// * If `start` < 0, position counts from the end of the string (`-1` is the last character). -/// * If `start` < -length of string, position counts from the beginning of the string. -/// * If `start` ≥ length of string, `-1` is returned. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world!"; -/// -/// print(text.index_of('l', 5)); // prints 10 (first index after 5) -/// -/// print(text.index_of('o', -7)); // prints 8 -/// -/// print(text.index_of('x', 0)); // prints -1 -/// ``` -fn index_of(string: String, character: char, start: int) -> int; - -/// Find the specified sub-string in the string, starting from the specified `start` position, -/// and return the first index where it is found. -/// If the sub-string is not found, `-1` is returned. -/// -/// * If `start` < 0, position counts from the end of the string (`-1` is the last character). -/// * If `start` < -length of string, position counts from the beginning of the string. -/// * If `start` ≥ length of string, `-1` is returned. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world! hello, foobar!"; -/// -/// print(text.index_of("ll", 5)); // prints 16 (first index after 5) -/// -/// print(text.index_of("ll", -15)); // prints 16 -/// -/// print(text.index_of("xx", 0)); // prints -1 -/// ``` -fn index_of(string: String, find_string: String, start: int) -> int; - -/// Add a new element into the array at a particular `index` position. -/// -/// * If `index` < 0, position counts from the end of the array (`-1` is the last element). -/// * If `index` < -length of array, the element is added to the beginning of the array. -/// * If `index` ≥ length of array, the element is appended to the end of the array. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3]; -/// -/// x.insert(0, "hello"); -/// -/// x.insert(2, true); -/// -/// x.insert(-2, 42); -/// -/// print(x); // prints ["hello", 1, true, 2, 42, 3] -/// ``` -fn insert(array: Array, index: int, item: ?) -> (); - -/// Add a byte `value` to the BLOB at a particular `index` position. -/// -/// * If `index` < 0, position counts from the end of the BLOB (`-1` is the last byte). -/// * If `index` < -length of BLOB, the byte value is added to the beginning of the BLOB. -/// * If `index` ≥ length of BLOB, the byte value is appended to the end of the BLOB. -/// -/// Only the lower 8 bits of the `value` are used; all other bits are ignored. -/// -/// # Example -/// -/// ```rhai -/// let b = blob(5, 0x42); -/// -/// b.insert(2, 0x18); -/// -/// print(b); // prints "[4242184242]" -/// ``` -fn insert(blob: Blob, index: int, value: int) -> (); - -/// Return the integral part of the floating-point number. -fn int(x: float) -> float; - -/// Return `true` if the function is an anonymous function. -/// -/// # Example -/// -/// ```rhai -/// let f = |x| x * 2; -/// -/// print(f.is_anonymous); // prints true -/// ``` -fn is_anonymous(fn_ptr: FnPtr) -> bool; - -/// Return true if the array is empty. -fn is_empty(array: Array) -> bool; - -/// Return true if the BLOB is empty. -fn is_empty(blob: Blob) -> bool; - -/// Return true if the map is empty. -fn is_empty(map: Map) -> bool; - -/// Return true if the range contains no items. -fn is_empty(range: ExclusiveRange) -> bool; - -/// Return true if the range contains no items. -fn is_empty(range: InclusiveRange) -> bool; - -/// Return true if the string is empty. -fn is_empty(string: String) -> bool; - -/// Return true if the number is even. -fn is_even(x: int) -> bool; - -/// Return true if the number is even. -fn is_even(x: i128) -> bool; - -/// Return true if the number is even. -fn is_even(x: i16) -> bool; - -/// Return true if the number is even. -fn is_even(x: i32) -> bool; - -/// Return true if the number is even. -fn is_even(x: i8) -> bool; - -/// Return true if the number is even. -fn is_even(x: u128) -> bool; - -/// Return true if the number is even. -fn is_even(x: u16) -> bool; - -/// Return true if the number is even. -fn is_even(x: u32) -> bool; - -/// Return true if the number is even. -fn is_even(x: u64) -> bool; - -/// Return true if the number is even. -fn is_even(x: u8) -> bool; - -/// Return `true` if the range is exclusive. -fn is_exclusive(range: ExclusiveRange) -> bool; - -/// Return `true` if the range is exclusive. -fn is_exclusive(range: InclusiveRange) -> bool; - -/// Return `true` if the floating-point number is finite. -fn is_finite(x: float) -> bool; - -/// Return `true` if the range is inclusive. -fn is_inclusive(range: ExclusiveRange) -> bool; - -/// Return `true` if the range is inclusive. -fn is_inclusive(range: InclusiveRange) -> bool; - -/// Return `true` if the floating-point number is infinite. -fn is_infinite(x: float) -> bool; - -/// Return `true` if the floating-point number is `NaN` (Not A Number). -fn is_nan(x: float) -> bool; - -/// Return true if the number is odd. -fn is_odd(x: int) -> bool; - -/// Return true if the number is odd. -fn is_odd(x: i128) -> bool; - -/// Return true if the number is odd. -fn is_odd(x: i16) -> bool; - -/// Return true if the number is odd. -fn is_odd(x: i32) -> bool; - -/// Return true if the number is odd. -fn is_odd(x: i8) -> bool; - -/// Return true if the number is odd. -fn is_odd(x: u128) -> bool; - -/// Return true if the number is odd. -fn is_odd(x: u16) -> bool; - -/// Return true if the number is odd. -fn is_odd(x: u32) -> bool; - -/// Return true if the number is odd. -fn is_odd(x: u64) -> bool; - -/// Return true if the number is odd. -fn is_odd(x: u8) -> bool; - -/// Return true if the number is zero. -fn is_zero(x: int) -> bool; - -/// Return true if the floating-point number is zero. -fn is_zero(x: f32) -> bool; - -/// Return true if the floating-point number is zero. -fn is_zero(x: float) -> bool; - -/// Return true if the number is zero. -fn is_zero(x: i128) -> bool; - -/// Return true if the number is zero. -fn is_zero(x: i16) -> bool; - -/// Return true if the number is zero. -fn is_zero(x: i32) -> bool; - -/// Return true if the number is zero. -fn is_zero(x: i8) -> bool; - -/// Return true if the number is zero. -fn is_zero(x: u128) -> bool; - -/// Return true if the number is zero. -fn is_zero(x: u16) -> bool; - -/// Return true if the number is zero. -fn is_zero(x: u32) -> bool; - -/// Return true if the number is zero. -fn is_zero(x: u64) -> bool; - -/// Return true if the number is zero. -fn is_zero(x: u8) -> bool; - -/// Return an array with all the property names in the object map. -/// -/// # Example -/// -/// ```rhai -/// let m = #{a:1, b:2, c:3}; -/// -/// print(m.keys()); // prints ["a", "b", "c"] -/// ``` -fn keys(map: Map) -> Array; - -/// Number of elements in the array. -fn len(array: Array) -> int; - -/// Return the length of the BLOB. -/// -/// # Example -/// -/// ```rhai -/// let b = blob(10, 0x42); -/// -/// print(b); // prints "[4242424242424242 4242]" -/// -/// print(b.len()); // prints 10 -/// ``` -fn len(blob: Blob) -> int; - -/// Return the number of properties in the object map. -fn len(map: Map) -> int; - -/// Return the length of the string, in number of characters. -/// -/// # Example -/// -/// ```rhai -/// let text = "朝には紅顔ありて夕べには白骨となる"; -/// -/// print(text.len); // prints 17 -/// ``` -fn len(string: String) -> int; - -/// Return the natural log of the floating-point number. -fn ln(x: float) -> float; - -/// Return the log of the floating-point number with base 10. -fn log(x: float) -> float; - -/// Return the log of the floating-point number with `base`. -fn log(x: float, base: float) -> float; - -/// Convert the character to lower-case. -/// -/// # Example -/// -/// ```rhai -/// let ch = 'A'; -/// -/// ch.make_lower(); -/// -/// print(ch); // prints 'a' -/// ``` -fn make_lower(character: char) -> (); - -/// Convert the string to all lower-case. -/// -/// # Example -/// -/// ```rhai -/// let text = "HELLO, WORLD!" -/// -/// text.make_lower(); -/// -/// print(text); // prints "hello, world!"; -/// ``` -fn make_lower(string: String) -> (); - -/// Convert the character to upper-case. -/// -/// # Example -/// -/// ```rhai -/// let ch = 'a'; -/// -/// ch.make_upper(); -/// -/// print(ch); // prints 'A' -/// ``` -fn make_upper(character: char) -> (); - -/// Convert the string to all upper-case. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world!" -/// -/// text.make_upper(); -/// -/// print(text); // prints "HELLO, WORLD!"; -/// ``` -fn make_upper(string: String) -> (); - -/// Iterate through all the elements in the array, applying a function named by `mapper` to each -/// element in turn, and return the results as a new array. -/// -/// # Function Parameters -/// -/// A function with the same name as the value of `mapper` must exist taking these parameters: -/// -/// * `element`: copy of array element -/// * `index` _(optional)_: current index in the array -/// -/// # Example -/// -/// ```rhai -/// fn square(x) { x * x } -/// -/// fn multiply(x, i) { x * i } -/// -/// let x = [1, 2, 3, 4, 5]; -/// -/// let y = x.map("square"); -/// -/// print(y); // prints "[1, 4, 9, 16, 25]" -/// -/// let y = x.map("multiply"); -/// -/// print(y); // prints "[0, 2, 6, 12, 20]" -/// ``` -fn map(array: Array, mapper: String) -> Array; - -/// Iterate through all the elements in the array, applying a `mapper` function to each element -/// in turn, and return the results as a new array. -/// -/// # Function Parameters -/// -/// * `element`: copy of array element -/// * `index` _(optional)_: current index in the array -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 5]; -/// -/// let y = x.map(|v| v * v); -/// -/// print(y); // prints "[1, 4, 9, 16, 25]" -/// -/// let y = x.map(|v, i| v * i); -/// -/// print(y); // prints "[0, 2, 6, 12, 20]" -/// ``` -fn map(array: Array, mapper: FnPtr) -> Array; - -/// Add all property values of another object map into the object map. -/// Existing property values of the same names are replaced. -/// -/// # Example -/// -/// ```rhai -/// let m = #{a:1, b:2, c:3}; -/// let n = #{a: 42, d:0}; -/// -/// m.mixin(n); -/// -/// print(m); // prints "#{a:42, b:2, c:3, d:0}" -/// ``` -fn mixin(map: Map, map2: Map) -> (); - -/// Return the name of the function. -/// -/// # Example -/// -/// ```rhai -/// fn double(x) { x * 2 } -/// -/// let f = Fn("double"); -/// -/// print(f.name); // prints "double" -/// ``` -fn name(fn_ptr: FnPtr) -> String; - -/// Pad the array to at least the specified length with copies of a specified element. -/// -/// If `len` ≤ length of array, no padding is done. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3]; -/// -/// x.pad(5, 42); -/// -/// print(x); // prints "[1, 2, 3, 42, 42]" -/// -/// x.pad(3, 123); -/// -/// print(x); // prints "[1, 2, 3, 42, 42]" -/// ``` -fn pad(array: Array, len: int, item: ?) -> (); - -/// Pad the BLOB to at least the specified length with copies of a specified byte `value`. -/// -/// If `len` ≤ length of BLOB, no padding is done. -/// -/// Only the lower 8 bits of the `value` are used; all other bits are ignored. -/// -/// # Example -/// -/// ```rhai -/// let b = blob(3, 0x42); -/// -/// b.pad(5, 0x18) -/// -/// print(b); // prints "[4242421818]" -/// -/// b.pad(3, 0xab) -/// -/// print(b); // prints "[4242421818]" -/// ``` -fn pad(blob: Blob, len: int, value: int) -> (); - -/// Pad the string to at least the specified number of characters with the specified `character`. -/// -/// If `len` ≤ length of string, no padding is done. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello"; -/// -/// text.pad(8, '!'); -/// -/// print(text); // prints "hello!!!" -/// -/// text.pad(5, '*'); -/// -/// print(text); // prints "hello!!!" -/// ``` -fn pad(string: String, len: int, character: char) -> (); - -/// Pad the string to at least the specified number of characters with the specified string. -/// -/// If `len` ≤ length of string, no padding is done. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello"; -/// -/// text.pad(10, "(!)"); -/// -/// print(text); // prints "hello(!)(!)" -/// -/// text.pad(8, '***'); -/// -/// print(text); // prints "hello(!)(!)" -/// ``` -fn pad(string: String, len: int, padding: String) -> (); - -/// Parse the bytes within an exclusive `range` in the BLOB as a `FLOAT` -/// in big-endian byte order. -/// -/// * If number of bytes in `range` < number of bytes for `FLOAT`, zeros are padded. -/// * If number of bytes in `range` > number of bytes for `FLOAT`, extra bytes are ignored. -fn parse_be_float(blob: Blob, range: Range) -> float; - -/// Parse the bytes within an inclusive `range` in the BLOB as a `FLOAT` -/// in big-endian byte order. -/// -/// * If number of bytes in `range` < number of bytes for `FLOAT`, zeros are padded. -/// * If number of bytes in `range` > number of bytes for `FLOAT`, extra bytes are ignored. -fn parse_be_float(blob: Blob, range: RangeInclusive) -> float; - -/// Parse the bytes beginning at the `start` position in the BLOB as a `FLOAT` -/// in big-endian byte order. -/// -/// * If `start` < 0, position counts from the end of the BLOB (`-1` is the last byte). -/// * If `start` < -length of BLOB, position counts from the beginning of the BLOB. -/// * If `start` ≥ length of BLOB, zero is returned. -/// * If `len` ≤ 0, zero is returned. -/// * If `start` position + `len` ≥ length of BLOB, entire portion of the BLOB after the `start` position is parsed. -/// -/// * If number of bytes in range < number of bytes for `FLOAT`, zeros are padded. -/// * If number of bytes in range > number of bytes for `FLOAT`, extra bytes are ignored. -fn parse_be_float(blob: Blob, start: int, len: int) -> float; - -/// Parse the bytes within an exclusive `range` in the BLOB as an `INT` -/// in big-endian byte order. -/// -/// * If number of bytes in `range` < number of bytes for `INT`, zeros are padded. -/// * If number of bytes in `range` > number of bytes for `INT`, extra bytes are ignored. -/// -/// ```rhai -/// let b = blob(); -/// -/// b += 1; b += 2; b += 3; b += 4; b += 5; -/// -/// let x = b.parse_be_int(1..3); // parse two bytes -/// -/// print(x.to_hex()); // prints "02030000...00" -/// ``` -fn parse_be_int(blob: Blob, range: Range) -> int; - -/// Parse the bytes within an inclusive `range` in the BLOB as an `INT` -/// in big-endian byte order. -/// -/// * If number of bytes in `range` < number of bytes for `INT`, zeros are padded. -/// * If number of bytes in `range` > number of bytes for `INT`, extra bytes are ignored. -/// -/// ```rhai -/// let b = blob(); -/// -/// b += 1; b += 2; b += 3; b += 4; b += 5; -/// -/// let x = b.parse_be_int(1..=3); // parse three bytes -/// -/// print(x.to_hex()); // prints "0203040000...00" -/// ``` -fn parse_be_int(blob: Blob, range: RangeInclusive) -> int; - -/// Parse the bytes beginning at the `start` position in the BLOB as an `INT` -/// in big-endian byte order. -/// -/// * If `start` < 0, position counts from the end of the BLOB (`-1` is the last byte). -/// * If `start` < -length of BLOB, position counts from the beginning of the BLOB. -/// * If `start` ≥ length of BLOB, zero is returned. -/// * If `len` ≤ 0, zero is returned. -/// * If `start` position + `len` ≥ length of BLOB, entire portion of the BLOB after the `start` position is parsed. -/// -/// * If number of bytes in range < number of bytes for `INT`, zeros are padded. -/// * If number of bytes in range > number of bytes for `INT`, extra bytes are ignored. -/// -/// ```rhai -/// let b = blob(); -/// -/// b += 1; b += 2; b += 3; b += 4; b += 5; -/// -/// let x = b.parse_be_int(1, 2); -/// -/// print(x.to_hex()); // prints "02030000...00" -/// ``` -fn parse_be_int(blob: Blob, start: int, len: int) -> int; - -/// Parse a string into a floating-point number. -/// -/// # Example -/// -/// ```rhai -/// let x = parse_int("123.456"); -/// -/// print(x); // prints 123.456 -/// ``` -fn parse_float(string: String) -> float; - -/// Parse a string into an integer number. -/// -/// # Example -/// -/// ```rhai -/// let x = parse_int("123"); -/// -/// print(x); // prints 123 -/// ``` -fn parse_int(string: String) -> int; - -/// Parse a string into an integer number of the specified `radix`. -/// -/// `radix` must be between 2 and 36. -/// -/// # Example -/// -/// ```rhai -/// let x = parse_int("123"); -/// -/// print(x); // prints 123 -/// -/// let y = parse_int("123abc", 16); -/// -/// print(y); // prints 1194684 (0x123abc) -/// ``` -fn parse_int(string: String, radix: int) -> int; - -/// Parse a JSON string into a value. -/// -/// # Example -/// -/// ```rhai -/// let m = parse_json(`{"a":1, "b":2, "c":3}`); -/// -/// print(m); // prints #{"a":1, "b":2, "c":3} -/// ``` -fn parse_json(json: String) -> ?; - -/// Parse the bytes within an exclusive `range` in the BLOB as a `FLOAT` -/// in little-endian byte order. -/// -/// * If number of bytes in `range` < number of bytes for `FLOAT`, zeros are padded. -/// * If number of bytes in `range` > number of bytes for `FLOAT`, extra bytes are ignored. -fn parse_le_float(blob: Blob, range: Range) -> float; - -/// Parse the bytes within an inclusive `range` in the BLOB as a `FLOAT` -/// in little-endian byte order. -/// -/// * If number of bytes in `range` < number of bytes for `FLOAT`, zeros are padded. -/// * If number of bytes in `range` > number of bytes for `FLOAT`, extra bytes are ignored. -fn parse_le_float(blob: Blob, range: RangeInclusive) -> float; - -/// Parse the bytes beginning at the `start` position in the BLOB as a `FLOAT` -/// in little-endian byte order. -/// -/// * If `start` < 0, position counts from the end of the BLOB (`-1` is the last byte). -/// * If `start` < -length of BLOB, position counts from the beginning of the BLOB. -/// * If `start` ≥ length of BLOB, zero is returned. -/// * If `len` ≤ 0, zero is returned. -/// * If `start` position + `len` ≥ length of BLOB, entire portion of the BLOB after the `start` position is parsed. -/// -/// * If number of bytes in range < number of bytes for `FLOAT`, zeros are padded. -/// * If number of bytes in range > number of bytes for `FLOAT`, extra bytes are ignored. -fn parse_le_float(blob: Blob, start: int, len: int) -> float; - -/// Parse the bytes within an exclusive `range` in the BLOB as an `INT` -/// in little-endian byte order. -/// -/// * If number of bytes in `range` < number of bytes for `INT`, zeros are padded. -/// * If number of bytes in `range` > number of bytes for `INT`, extra bytes are ignored. -/// -/// ```rhai -/// let b = blob(); -/// -/// b += 1; b += 2; b += 3; b += 4; b += 5; -/// -/// let x = b.parse_le_int(1..3); // parse two bytes -/// -/// print(x.to_hex()); // prints "0302" -/// ``` -fn parse_le_int(blob: Blob, range: Range) -> int; - -/// Parse the bytes within an inclusive `range` in the BLOB as an `INT` -/// in little-endian byte order. -/// -/// * If number of bytes in `range` < number of bytes for `INT`, zeros are padded. -/// * If number of bytes in `range` > number of bytes for `INT`, extra bytes are ignored. -/// -/// ```rhai -/// let b = blob(); -/// -/// b += 1; b += 2; b += 3; b += 4; b += 5; -/// -/// let x = b.parse_le_int(1..=3); // parse three bytes -/// -/// print(x.to_hex()); // prints "040302" -/// ``` -fn parse_le_int(blob: Blob, range: RangeInclusive) -> int; - -/// Parse the bytes beginning at the `start` position in the BLOB as an `INT` -/// in little-endian byte order. -/// -/// * If `start` < 0, position counts from the end of the BLOB (`-1` is the last byte). -/// * If `start` < -length of BLOB, position counts from the beginning of the BLOB. -/// * If `start` ≥ length of BLOB, zero is returned. -/// * If `len` ≤ 0, zero is returned. -/// * If `start` position + `len` ≥ length of BLOB, entire portion of the BLOB after the `start` position is parsed. -/// -/// * If number of bytes in range < number of bytes for `INT`, zeros are padded. -/// * If number of bytes in range > number of bytes for `INT`, extra bytes are ignored. -/// -/// ```rhai -/// let b = blob(); -/// -/// b += 1; b += 2; b += 3; b += 4; b += 5; -/// -/// let x = b.parse_le_int(1, 2); -/// -/// print(x.to_hex()); // prints "0302" -/// ``` -fn parse_le_int(blob: Blob, start: int, len: int) -> int; - -/// Remove the last element from the array and return it. -/// -/// If the array is empty, `()` is returned. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3]; -/// -/// print(x.pop()); // prints 3 -/// -/// print(x); // prints "[1, 2]" -/// ``` -fn pop(array: Array) -> ?; - -/// Remove the last byte from the BLOB and return it. -/// -/// If the BLOB is empty, zero is returned. -/// -/// # Example -/// -/// ```rhai -/// let b = blob(); -/// -/// b += 1; b += 2; b += 3; b += 4; b += 5; -/// -/// print(b.pop()); // prints 5 -/// -/// print(b); // prints "[01020304]" -/// ``` -fn pop(blob: Blob) -> int; - -/// Remove the last character from the string and return it. -/// -/// If the string is empty, `()` is returned. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world!"; -/// -/// print(text.pop()); // prints '!' -/// -/// print(text); // prints "hello, world" -/// ``` -fn pop(string: String) -> ?; - -/// Remove a specified number of characters from the end of the string and return it as a -/// new string. -/// -/// * If `len` ≤ 0, the string is not modified and an empty string is returned. -/// * If `len` ≥ length of string, the string is cleared and the entire string returned. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world!"; -/// -/// print(text.pop(4)); // prints "rld!" -/// -/// print(text); // prints "hello, wo" -/// ``` -fn pop(string: String, len: int) -> String; - -/// Return the empty string. -op print() -> String; - -/// Convert the array into a string. -op print(Array) -> String; - -/// Return the character into a string. -op print(char) -> String; - -/// Convert the value of the `item` into a string. -op print(?) -> String; - -/// Convert the object map into a string. -op print(Map) -> String; - -/// Convert the value of `number` into a string. -op print(f32) -> String; - -/// Convert the value of `number` into a string. -op print(float) -> String; - -/// Return the `string`. -op print(String) -> String; - -/// Return the empty string. -op print(()) -> String; - -/// Return the boolean value into a string. -op print(bool) -> String; - -/// Add a new element, which is not another array, to the end of the array. -/// -/// If `item` is `Array`, then `append` is more specific and will be called instead. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3]; -/// -/// x.push("hello"); -/// -/// print(x); // prints [1, 2, 3, "hello"] -/// ``` -fn push(array: Array, item: ?) -> (); - -/// Add a new byte `value` to the end of the BLOB. -/// -/// Only the lower 8 bits of the `value` are used; all other bits are ignored. -/// -/// # Example -/// -/// ```rhai -/// let b = blob(); -/// -/// b.push(0x42); -/// -/// print(b); // prints "[42]" -/// ``` -fn push(blob: Blob, value: int) -> (); - -/// Return an iterator over the exclusive range of `from..to`. -/// The value `to` is never included. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 -/// for n in range(8, 18) { -/// print(n); -/// } -/// ``` -fn range(from: i128, to: i128) -> Iterator; - -/// Return an iterator over the exclusive range of `from..to`. -/// The value `to` is never included. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 -/// for n in range(8, 18) { -/// print(n); -/// } -/// ``` -fn range(from: i16, to: i16) -> Iterator; - -/// Return an iterator over the exclusive range of `from..to`. -/// The value `to` is never included. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 -/// for n in range(8, 18) { -/// print(n); -/// } -/// ``` -fn range(from: i32, to: i32) -> Iterator; - -/// Return an iterator over the exclusive range of `from..to`. -/// The value `to` is never included. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 -/// for n in range(8, 18) { -/// print(n); -/// } -/// ``` -fn range(from: int, to: int) -> Iterator; - -/// Return an iterator over the exclusive range of `from..to`. -/// The value `to` is never included. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 -/// for n in range(8, 18) { -/// print(n); -/// } -/// ``` -fn range(from: i8, to: i8) -> Iterator; - -/// Return an iterator over the exclusive range of `from..to`. -/// The value `to` is never included. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 -/// for n in range(8, 18) { -/// print(n); -/// } -/// ``` -fn range(from: u128, to: u128) -> Iterator; - -/// Return an iterator over the exclusive range of `from..to`. -/// The value `to` is never included. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 -/// for n in range(8, 18) { -/// print(n); -/// } -/// ``` -fn range(from: u16, to: u16) -> Iterator; - -/// Return an iterator over the exclusive range of `from..to`. -/// The value `to` is never included. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 -/// for n in range(8, 18) { -/// print(n); -/// } -/// ``` -fn range(from: u32, to: u32) -> Iterator; - -/// Return an iterator over the exclusive range of `from..to`. -/// The value `to` is never included. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 -/// for n in range(8, 18) { -/// print(n); -/// } -/// ``` -fn range(from: u64, to: u64) -> Iterator; - -/// Return an iterator over the exclusive range of `from..to`. -/// The value `to` is never included. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 -/// for n in range(8, 18) { -/// print(n); -/// } -/// ``` -fn range(from: u8, to: u8) -> Iterator; - -/// Return an iterator over an exclusive range, each iteration increasing by `step`. -/// -/// If `range` is reversed and `step` < 0, iteration goes backwards. -/// -/// Otherwise, if `range` is empty, an empty iterator is returned. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 in steps of 3 -/// for n in range(8..18, 3) { -/// print(n); -/// } -/// -/// // prints all values down from 18 to 9 in steps of -3 -/// for n in range(18..8, -3) { -/// print(n); -/// } -/// ``` -fn range(range: Range, step: float) -> Iterator; - -/// Return an iterator over an exclusive range, each iteration increasing by `step`. -/// -/// If `range` is reversed and `step` < 0, iteration goes backwards. -/// -/// Otherwise, if `range` is empty, an empty iterator is returned. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 in steps of 3 -/// for n in range(8..18, 3) { -/// print(n); -/// } -/// -/// // prints all values down from 18 to 9 in steps of -3 -/// for n in range(18..8, -3) { -/// print(n); -/// } -/// ``` -fn range(range: Range, step: i128) -> Iterator; - -/// Return an iterator over an exclusive range, each iteration increasing by `step`. -/// -/// If `range` is reversed and `step` < 0, iteration goes backwards. -/// -/// Otherwise, if `range` is empty, an empty iterator is returned. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 in steps of 3 -/// for n in range(8..18, 3) { -/// print(n); -/// } -/// -/// // prints all values down from 18 to 9 in steps of -3 -/// for n in range(18..8, -3) { -/// print(n); -/// } -/// ``` -fn range(range: Range, step: i16) -> Iterator; - -/// Return an iterator over an exclusive range, each iteration increasing by `step`. -/// -/// If `range` is reversed and `step` < 0, iteration goes backwards. -/// -/// Otherwise, if `range` is empty, an empty iterator is returned. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 in steps of 3 -/// for n in range(8..18, 3) { -/// print(n); -/// } -/// -/// // prints all values down from 18 to 9 in steps of -3 -/// for n in range(18..8, -3) { -/// print(n); -/// } -/// ``` -fn range(range: Range, step: i32) -> Iterator; - -/// Return an iterator over an exclusive range, each iteration increasing by `step`. -/// -/// If `range` is reversed and `step` < 0, iteration goes backwards. -/// -/// Otherwise, if `range` is empty, an empty iterator is returned. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 in steps of 3 -/// for n in range(8..18, 3) { -/// print(n); -/// } -/// -/// // prints all values down from 18 to 9 in steps of -3 -/// for n in range(18..8, -3) { -/// print(n); -/// } -/// ``` -fn range(range: Range, step: int) -> Iterator; - -/// Return an iterator over an exclusive range, each iteration increasing by `step`. -/// -/// If `range` is reversed and `step` < 0, iteration goes backwards. -/// -/// Otherwise, if `range` is empty, an empty iterator is returned. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 in steps of 3 -/// for n in range(8..18, 3) { -/// print(n); -/// } -/// -/// // prints all values down from 18 to 9 in steps of -3 -/// for n in range(18..8, -3) { -/// print(n); -/// } -/// ``` -fn range(range: Range, step: i8) -> Iterator; - -/// Return an iterator over an exclusive range, each iteration increasing by `step`. -/// -/// If `range` is reversed and `step` < 0, iteration goes backwards. -/// -/// Otherwise, if `range` is empty, an empty iterator is returned. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 in steps of 3 -/// for n in range(8..18, 3) { -/// print(n); -/// } -/// -/// // prints all values down from 18 to 9 in steps of -3 -/// for n in range(18..8, -3) { -/// print(n); -/// } -/// ``` -fn range(range: Range, step: u128) -> Iterator; - -/// Return an iterator over an exclusive range, each iteration increasing by `step`. -/// -/// If `range` is reversed and `step` < 0, iteration goes backwards. -/// -/// Otherwise, if `range` is empty, an empty iterator is returned. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 in steps of 3 -/// for n in range(8..18, 3) { -/// print(n); -/// } -/// -/// // prints all values down from 18 to 9 in steps of -3 -/// for n in range(18..8, -3) { -/// print(n); -/// } -/// ``` -fn range(range: Range, step: u16) -> Iterator; - -/// Return an iterator over an exclusive range, each iteration increasing by `step`. -/// -/// If `range` is reversed and `step` < 0, iteration goes backwards. -/// -/// Otherwise, if `range` is empty, an empty iterator is returned. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 in steps of 3 -/// for n in range(8..18, 3) { -/// print(n); -/// } -/// -/// // prints all values down from 18 to 9 in steps of -3 -/// for n in range(18..8, -3) { -/// print(n); -/// } -/// ``` -fn range(range: Range, step: u32) -> Iterator; - -/// Return an iterator over an exclusive range, each iteration increasing by `step`. -/// -/// If `range` is reversed and `step` < 0, iteration goes backwards. -/// -/// Otherwise, if `range` is empty, an empty iterator is returned. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 in steps of 3 -/// for n in range(8..18, 3) { -/// print(n); -/// } -/// -/// // prints all values down from 18 to 9 in steps of -3 -/// for n in range(18..8, -3) { -/// print(n); -/// } -/// ``` -fn range(range: Range, step: u64) -> Iterator; - -/// Return an iterator over an exclusive range, each iteration increasing by `step`. -/// -/// If `range` is reversed and `step` < 0, iteration goes backwards. -/// -/// Otherwise, if `range` is empty, an empty iterator is returned. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 in steps of 3 -/// for n in range(8..18, 3) { -/// print(n); -/// } -/// -/// // prints all values down from 18 to 9 in steps of -3 -/// for n in range(18..8, -3) { -/// print(n); -/// } -/// ``` -fn range(range: Range, step: u8) -> Iterator; - -/// Return an iterator over the exclusive range of `from..to`, each iteration increasing by `step`. -/// The value `to` is never included. -/// -/// If `from` > `to` and `step` < 0, iteration goes backwards. -/// -/// If `from` > `to` and `step` > 0 or `from` < `to` and `step` < 0, an empty iterator is returned. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 in steps of 3 -/// for n in range(8, 18, 3) { -/// print(n); -/// } -/// -/// // prints all values down from 18 to 9 in steps of -3 -/// for n in range(18, 8, -3) { -/// print(n); -/// } -/// ``` -fn range(from: float, to: float, step: float) -> Iterator; - -/// Return an iterator over the exclusive range of `from..to`, each iteration increasing by `step`. -/// The value `to` is never included. -/// -/// If `from` > `to` and `step` < 0, iteration goes backwards. -/// -/// If `from` > `to` and `step` > 0 or `from` < `to` and `step` < 0, an empty iterator is returned. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 in steps of 3 -/// for n in range(8, 18, 3) { -/// print(n); -/// } -/// -/// // prints all values down from 18 to 9 in steps of -3 -/// for n in range(18, 8, -3) { -/// print(n); -/// } -/// ``` -fn range(from: i128, to: i128, step: i128) -> Iterator; - -/// Return an iterator over the exclusive range of `from..to`, each iteration increasing by `step`. -/// The value `to` is never included. -/// -/// If `from` > `to` and `step` < 0, iteration goes backwards. -/// -/// If `from` > `to` and `step` > 0 or `from` < `to` and `step` < 0, an empty iterator is returned. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 in steps of 3 -/// for n in range(8, 18, 3) { -/// print(n); -/// } -/// -/// // prints all values down from 18 to 9 in steps of -3 -/// for n in range(18, 8, -3) { -/// print(n); -/// } -/// ``` -fn range(from: i16, to: i16, step: i16) -> Iterator; - -/// Return an iterator over the exclusive range of `from..to`, each iteration increasing by `step`. -/// The value `to` is never included. -/// -/// If `from` > `to` and `step` < 0, iteration goes backwards. -/// -/// If `from` > `to` and `step` > 0 or `from` < `to` and `step` < 0, an empty iterator is returned. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 in steps of 3 -/// for n in range(8, 18, 3) { -/// print(n); -/// } -/// -/// // prints all values down from 18 to 9 in steps of -3 -/// for n in range(18, 8, -3) { -/// print(n); -/// } -/// ``` -fn range(from: i32, to: i32, step: i32) -> Iterator; - -/// Return an iterator over the exclusive range of `from..to`, each iteration increasing by `step`. -/// The value `to` is never included. -/// -/// If `from` > `to` and `step` < 0, iteration goes backwards. -/// -/// If `from` > `to` and `step` > 0 or `from` < `to` and `step` < 0, an empty iterator is returned. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 in steps of 3 -/// for n in range(8, 18, 3) { -/// print(n); -/// } -/// -/// // prints all values down from 18 to 9 in steps of -3 -/// for n in range(18, 8, -3) { -/// print(n); -/// } -/// ``` -fn range(from: int, to: int, step: int) -> Iterator; - -/// Return an iterator over the exclusive range of `from..to`, each iteration increasing by `step`. -/// The value `to` is never included. -/// -/// If `from` > `to` and `step` < 0, iteration goes backwards. -/// -/// If `from` > `to` and `step` > 0 or `from` < `to` and `step` < 0, an empty iterator is returned. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 in steps of 3 -/// for n in range(8, 18, 3) { -/// print(n); -/// } -/// -/// // prints all values down from 18 to 9 in steps of -3 -/// for n in range(18, 8, -3) { -/// print(n); -/// } -/// ``` -fn range(from: i8, to: i8, step: i8) -> Iterator; - -/// Return an iterator over the exclusive range of `from..to`, each iteration increasing by `step`. -/// The value `to` is never included. -/// -/// If `from` > `to` and `step` < 0, iteration goes backwards. -/// -/// If `from` > `to` and `step` > 0 or `from` < `to` and `step` < 0, an empty iterator is returned. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 in steps of 3 -/// for n in range(8, 18, 3) { -/// print(n); -/// } -/// -/// // prints all values down from 18 to 9 in steps of -3 -/// for n in range(18, 8, -3) { -/// print(n); -/// } -/// ``` -fn range(from: u128, to: u128, step: u128) -> Iterator; - -/// Return an iterator over the exclusive range of `from..to`, each iteration increasing by `step`. -/// The value `to` is never included. -/// -/// If `from` > `to` and `step` < 0, iteration goes backwards. -/// -/// If `from` > `to` and `step` > 0 or `from` < `to` and `step` < 0, an empty iterator is returned. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 in steps of 3 -/// for n in range(8, 18, 3) { -/// print(n); -/// } -/// -/// // prints all values down from 18 to 9 in steps of -3 -/// for n in range(18, 8, -3) { -/// print(n); -/// } -/// ``` -fn range(from: u16, to: u16, step: u16) -> Iterator; - -/// Return an iterator over the exclusive range of `from..to`, each iteration increasing by `step`. -/// The value `to` is never included. -/// -/// If `from` > `to` and `step` < 0, iteration goes backwards. -/// -/// If `from` > `to` and `step` > 0 or `from` < `to` and `step` < 0, an empty iterator is returned. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 in steps of 3 -/// for n in range(8, 18, 3) { -/// print(n); -/// } -/// -/// // prints all values down from 18 to 9 in steps of -3 -/// for n in range(18, 8, -3) { -/// print(n); -/// } -/// ``` -fn range(from: u32, to: u32, step: u32) -> Iterator; - -/// Return an iterator over the exclusive range of `from..to`, each iteration increasing by `step`. -/// The value `to` is never included. -/// -/// If `from` > `to` and `step` < 0, iteration goes backwards. -/// -/// If `from` > `to` and `step` > 0 or `from` < `to` and `step` < 0, an empty iterator is returned. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 in steps of 3 -/// for n in range(8, 18, 3) { -/// print(n); -/// } -/// -/// // prints all values down from 18 to 9 in steps of -3 -/// for n in range(18, 8, -3) { -/// print(n); -/// } -/// ``` -fn range(from: u64, to: u64, step: u64) -> Iterator; - -/// Return an iterator over the exclusive range of `from..to`, each iteration increasing by `step`. -/// The value `to` is never included. -/// -/// If `from` > `to` and `step` < 0, iteration goes backwards. -/// -/// If `from` > `to` and `step` > 0 or `from` < `to` and `step` < 0, an empty iterator is returned. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 in steps of 3 -/// for n in range(8, 18, 3) { -/// print(n); -/// } -/// -/// // prints all values down from 18 to 9 in steps of -3 -/// for n in range(18, 8, -3) { -/// print(n); -/// } -/// ``` -fn range(from: u8, to: u8, step: u8) -> Iterator; - -/// Reduce an array by iterating through all elements while applying a function named by `reducer`. -/// -/// # Function Parameters -/// -/// A function with the same name as the value of `reducer` must exist taking these parameters: -/// -/// * `result`: accumulated result, initially `()` -/// * `element`: copy of array element -/// * `index` _(optional)_: current index in the array -/// -/// # Example -/// -/// ```rhai -/// fn process(r, x) { -/// x + (r ?? 0) -/// } -/// fn process_extra(r, x, i) { -/// x + i + (r ?? 0) -/// } -/// -/// let x = [1, 2, 3, 4, 5]; -/// -/// let y = x.reduce("process"); -/// -/// print(y); // prints 15 -/// -/// let y = x.reduce("process_extra"); -/// -/// print(y); // prints 25 -/// ``` -fn reduce(array: Array, reducer: String) -> RhaiResult; - -/// Reduce an array by iterating through all elements while applying the `reducer` function. -/// -/// # Function Parameters -/// -/// * `result`: accumulated result, initially `()` -/// * `element`: copy of array element -/// * `index` _(optional)_: current index in the array -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 5]; -/// -/// let y = x.reduce(|r, v| v + (r ?? 0)); -/// -/// print(y); // prints 15 -/// -/// let y = x.reduce(|r, v, i| v + i + (r ?? 0)); -/// -/// print(y); // prints 25 -/// ``` -fn reduce(array: Array, reducer: FnPtr) -> RhaiResult; - -/// Reduce an array by iterating through all elements while applying a function named by `reducer`. -/// -/// # Function Parameters -/// -/// A function with the same name as the value of `reducer` must exist taking these parameters: -/// -/// * `result`: accumulated result, starting with the value of `initial` -/// * `element`: copy of array element -/// * `index` _(optional)_: current index in the array -/// -/// # Example -/// -/// ```rhai -/// fn process(r, x) { x + r } -/// -/// fn process_extra(r, x, i) { x + i + r } -/// -/// let x = [1, 2, 3, 4, 5]; -/// -/// let y = x.reduce("process", 5); -/// -/// print(y); // prints 20 -/// -/// let y = x.reduce("process_extra", 5); -/// -/// print(y); // prints 30 -/// ``` -fn reduce(array: Array, reducer: String, initial: ?) -> RhaiResult; - -/// Reduce an array by iterating through all elements while applying the `reducer` function. -/// -/// # Function Parameters -/// -/// * `result`: accumulated result, starting with the value of `initial` -/// * `element`: copy of array element -/// * `index` _(optional)_: current index in the array -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 5]; -/// -/// let y = x.reduce(|r, v| v + r, 5); -/// -/// print(y); // prints 20 -/// -/// let y = x.reduce(|r, v, i| v + i + r, 5); -/// -/// print(y); // prints 30 -/// ``` -fn reduce(array: Array, reducer: FnPtr, initial: ?) -> RhaiResult; - -/// Reduce an array by iterating through all elements, in _reverse_ order, -/// while applying a function named by `reducer`. -/// -/// # Function Parameters -/// -/// A function with the same name as the value of `reducer` must exist taking these parameters: -/// -/// * `result`: accumulated result, initially `()` -/// * `element`: copy of array element -/// * `index` _(optional)_: current index in the array -/// -/// # Example -/// -/// ```rhai -/// fn process(r, x) { -/// x + (r ?? 0) -/// } -/// fn process_extra(r, x, i) { -/// x + i + (r ?? 0) -/// } -/// -/// let x = [1, 2, 3, 4, 5]; -/// -/// let y = x.reduce_rev("process"); -/// -/// print(y); // prints 15 -/// -/// let y = x.reduce_rev("process_extra"); -/// -/// print(y); // prints 25 -/// ``` -fn reduce_rev(array: Array, reducer: String) -> RhaiResult; - -/// Reduce an array by iterating through all elements, in _reverse_ order, -/// while applying the `reducer` function. -/// -/// # Function Parameters -/// -/// * `result`: accumulated result, initially `()` -/// * `element`: copy of array element -/// * `index` _(optional)_: current index in the array -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 5]; -/// -/// let y = x.reduce_rev(|r, v| v + (r ?? 0)); -/// -/// print(y); // prints 15 -/// -/// let y = x.reduce_rev(|r, v, i| v + i + (r ?? 0)); -/// -/// print(y); // prints 25 -/// ``` -fn reduce_rev(array: Array, reducer: FnPtr) -> RhaiResult; - -/// Reduce an array by iterating through all elements, in _reverse_ order, -/// while applying a function named by `reducer`. -/// -/// # Function Parameters -/// -/// A function with the same name as the value of `reducer` must exist taking these parameters: -/// -/// * `result`: accumulated result, starting with the value of `initial` -/// * `element`: copy of array element -/// * `index` _(optional)_: current index in the array -/// -/// # Example -/// -/// ```rhai -/// fn process(r, x) { x + r } -/// -/// fn process_extra(r, x, i) { x + i + r } -/// -/// let x = [1, 2, 3, 4, 5]; -/// -/// let y = x.reduce_rev("process", 5); -/// -/// print(y); // prints 20 -/// -/// let y = x.reduce_rev("process_extra", 5); -/// -/// print(y); // prints 30 -/// ``` -fn reduce_rev(array: Array, reducer: String, initial: ?) -> RhaiResult; - -/// Reduce an array by iterating through all elements, in _reverse_ order, -/// while applying the `reducer` function. -/// -/// # Function Parameters -/// -/// * `result`: accumulated result, starting with the value of `initial` -/// * `element`: copy of array element -/// * `index` _(optional)_: current index in the array -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 5]; -/// -/// let y = x.reduce_rev(|r, v| v + r, 5); -/// -/// print(y); // prints 20 -/// -/// let y = x.reduce_rev(|r, v, i| v + i + r, 5); -/// -/// print(y); // prints 30 -/// ``` -fn reduce_rev(array: Array, reducer: FnPtr, initial: ?) -> RhaiResult; - -/// Remove the element at the specified `index` from the array and return it. -/// -/// * If `index` < 0, position counts from the end of the array (`-1` is the last element). -/// * If `index` < -length of array, `()` is returned. -/// * If `index` ≥ length of array, `()` is returned. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3]; -/// -/// print(x.remove(1)); // prints 2 -/// -/// print(x); // prints "[1, 3]" -/// -/// print(x.remove(-2)); // prints 1 -/// -/// print(x); // prints "[3]" -/// ``` -fn remove(array: Array, index: int) -> ?; - -/// Remove the byte at the specified `index` from the BLOB and return it. -/// -/// * If `index` < 0, position counts from the end of the BLOB (`-1` is the last byte). -/// * If `index` < -length of BLOB, zero is returned. -/// * If `index` ≥ length of BLOB, zero is returned. -/// -/// # Example -/// -/// ```rhai -/// let b = blob(); -/// -/// b += 1; b += 2; b += 3; b += 4; b += 5; -/// -/// print(x.remove(1)); // prints 2 -/// -/// print(x); // prints "[01030405]" -/// -/// print(x.remove(-2)); // prints 4 -/// -/// print(x); // prints "[010305]" -/// ``` -fn remove(blob: Blob, index: int) -> int; - -/// Remove any property of the specified `name` from the object map, returning its value. -/// -/// If the property does not exist, `()` is returned. -/// -/// # Example -/// -/// ```rhai -/// let m = #{a:1, b:2, c:3}; -/// -/// let x = m.remove("b"); -/// -/// print(x); // prints 2 -/// -/// print(m); // prints "#{a:1, c:3}" -/// ``` -fn remove(map: Map, property: String) -> ?; - -/// Remove all occurrences of a character from the string. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world! hello, foobar!"; -/// -/// text.remove("o"); -/// -/// print(text); // prints "hell, wrld! hell, fbar!" -/// ``` -fn remove(string: String, character: char) -> (); - -/// Remove all occurrences of a sub-string from the string. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world! hello, foobar!"; -/// -/// text.remove("hello"); -/// -/// print(text); // prints ", world! , foobar!" -/// ``` -fn remove(string: String, sub_string: String) -> (); - -/// Replace all occurrences of the specified character in the string with another character. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world! hello, foobar!"; -/// -/// text.replace("l", '*'); -/// -/// print(text); // prints "he**o, wor*d! he**o, foobar!" -/// ``` -fn replace(string: String, find_character: char, substitute_character: char) -> (); - -/// Replace all occurrences of the specified character in the string with another string. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world! hello, foobar!"; -/// -/// text.replace('l', "(^)"); -/// -/// print(text); // prints "he(^)(^)o, wor(^)d! he(^)(^)o, foobar!" -/// ``` -fn replace(string: String, find_character: char, substitute_string: String) -> (); - -/// Replace all occurrences of the specified sub-string in the string with the specified character. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world! hello, foobar!"; -/// -/// text.replace("hello", '*'); -/// -/// print(text); // prints "*, world! *, foobar!" -/// ``` -fn replace(string: String, find_string: String, substitute_character: char) -> (); - -/// Replace all occurrences of the specified sub-string in the string with another string. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world! hello, foobar!"; -/// -/// text.replace("hello", "hey"); -/// -/// print(text); // prints "hey, world! hey, foobar!" -/// ``` -fn replace(string: String, find_string: String, substitute_string: String) -> (); - -/// Remove all elements in the array that do not return `true` when applied a function named by -/// `filter` and return them as a new array. -/// -/// # Function Parameters -/// -/// A function with the same name as the value of `filter` must exist taking these parameters: -/// -/// * `element`: copy of array element -/// * `index` _(optional)_: current index in the array -/// -/// # Example -/// -/// ```rhai -/// fn large(x) { x >= 3 } -/// -/// fn screen(x, i) { x + i <= 5 } -/// -/// let x = [1, 2, 3, 4, 5]; -/// -/// let y = x.retain("large"); -/// -/// print(x); // prints "[3, 4, 5]" -/// -/// print(y); // prints "[1, 2]" -/// -/// let z = x.retain("screen"); -/// -/// print(x); // prints "[3, 4]" -/// -/// print(z); // prints "[5]" -/// ``` -fn retain(array: Array, filter: String) -> Array; - -/// Remove all elements in the array that do not return `true` when applied the `filter` -/// function and return them as a new array. -/// -/// # Function Parameters -/// -/// * `element`: copy of array element -/// * `index` _(optional)_: current index in the array -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 5]; -/// -/// let y = x.retain(|v| v >= 3); -/// -/// print(x); // prints "[3, 4, 5]" -/// -/// print(y); // prints "[1, 2]" -/// -/// let z = x.retain(|v, i| v + i <= 5); -/// -/// print(x); // prints "[3, 4]" -/// -/// print(z); // prints "[5]" -/// ``` -fn retain(array: Array, filter: FnPtr) -> Array; - -/// Remove all elements in the array not within an exclusive `range` and return them as a new array. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 5]; -/// -/// let y = x.retain(1..4); -/// -/// print(x); // prints "[2, 3, 4]" -/// -/// print(y); // prints "[1, 5]" -/// -/// let z = x.retain(1..3); -/// -/// print(x); // prints "[3, 4]" -/// -/// print(z); // prints "[1]" -/// ``` -fn retain(array: Array, range: Range) -> Array; - -/// Remove all elements in the array not within an inclusive `range` and return them as a new array. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 5]; -/// -/// let y = x.retain(1..=3); -/// -/// print(x); // prints "[2, 3, 4]" -/// -/// print(y); // prints "[1, 5]" -/// -/// let z = x.retain(1..=2); -/// -/// print(x); // prints "[3, 4]" -/// -/// print(z); // prints "[1]" -/// ``` -fn retain(array: Array, range: RangeInclusive) -> Array; - -/// Remove all bytes in the BLOB not within an exclusive `range` and return them as a new BLOB. -/// -/// # Example -/// -/// ```rhai -/// let b1 = blob(); -/// -/// b1 += 1; b1 += 2; b1 += 3; b1 += 4; b1 += 5; -/// -/// let b2 = b1.retain(1..4); -/// -/// print(b1); // prints "[020304]" -/// -/// print(b2); // prints "[0105]" -/// -/// let b3 = b1.retain(1..3); -/// -/// print(b1); // prints "[0304]" -/// -/// print(b2); // prints "[01]" -/// ``` -fn retain(blob: Blob, range: Range) -> Blob; - -/// Remove all bytes in the BLOB not within an inclusive `range` and return them as a new BLOB. -/// -/// # Example -/// -/// ```rhai -/// let b1 = blob(); -/// -/// b1 += 1; b1 += 2; b1 += 3; b1 += 4; b1 += 5; -/// -/// let b2 = b1.retain(1..=3); -/// -/// print(b1); // prints "[020304]" -/// -/// print(b2); // prints "[0105]" -/// -/// let b3 = b1.retain(1..=2); -/// -/// print(b1); // prints "[0304]" -/// -/// print(b2); // prints "[01]" -/// ``` -fn retain(blob: Blob, range: RangeInclusive) -> Blob; - -/// Remove all elements not within a portion of the array and return them as a new array. -/// -/// * If `start` < 0, position counts from the end of the array (`-1` is the last element). -/// * If `start` < -length of array, position counts from the beginning of the array. -/// * If `start` ≥ length of array, all elements are removed returned. -/// * If `len` ≤ 0, all elements are removed and returned. -/// * If `start` position + `len` ≥ length of array, entire portion of the array before the `start` position is removed and returned. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 5]; -/// -/// let y = x.retain(1, 2); -/// -/// print(x); // prints "[2, 3]" -/// -/// print(y); // prints "[1, 4, 5]" -/// -/// let z = x.retain(-1, 1); -/// -/// print(x); // prints "[3]" -/// -/// print(z); // prints "[2]" -/// ``` -fn retain(array: Array, start: int, len: int) -> Array; - -/// Remove all bytes not within a portion of the BLOB and return them as a new BLOB. -/// -/// * If `start` < 0, position counts from the end of the BLOB (`-1` is the last byte). -/// * If `start` < -length of BLOB, position counts from the beginning of the BLOB. -/// * If `start` ≥ length of BLOB, all elements are removed returned. -/// * If `len` ≤ 0, all elements are removed and returned. -/// * If `start` position + `len` ≥ length of BLOB, entire portion of the BLOB before the `start` position is removed and returned. -/// -/// # Example -/// -/// ```rhai -/// let b1 = blob(); -/// -/// b1 += 1; b1 += 2; b1 += 3; b1 += 4; b1 += 5; -/// -/// let b2 = b1.retain(1, 2); -/// -/// print(b1); // prints "[0203]" -/// -/// print(b2); // prints "[010405]" -/// -/// let b3 = b1.retain(-1, 1); -/// -/// print(b1); // prints "[03]" -/// -/// print(b3); // prints "[02]" -/// ``` -fn retain(blob: Blob, start: int, len: int) -> Blob; - -/// Reverse all the elements in the array. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 5]; -/// -/// x.reverse(); -/// -/// print(x); // prints "[5, 4, 3, 2, 1]" -/// ``` -fn reverse(array: Array) -> (); - -/// Reverse the BLOB. -/// -/// # Example -/// -/// ```rhai -/// let b = blob(); -/// -/// b += 1; b += 2; b += 3; b += 4; b += 5; -/// -/// print(b); // prints "[0102030405]" -/// -/// b.reverse(); -/// -/// print(b); // prints "[0504030201]" -/// ``` -fn reverse(blob: Blob) -> (); - -/// Return the nearest whole number closest to the floating-point number. -/// Rounds away from zero. -fn round(x: float) -> float; - -/// Set the element at the `index` position in the array to a new `value`. -/// -/// * If `index` < 0, position counts from the end of the array (`-1` is the last element). -/// * If `index` < -length of array, the array is not modified. -/// * If `index` ≥ length of array, the array is not modified. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3]; -/// -/// x.set(0, 42); -/// -/// print(x); // prints "[42, 2, 3]" -/// -/// x.set(-3, 0); -/// -/// print(x); // prints "[0, 2, 3]" -/// -/// x.set(99, 123); -/// -/// print(x); // prints "[0, 2, 3]" -/// ``` -fn set(array: Array, index: int, value: ?) -> (); - -/// Set the particular `index` position in the BLOB to a new byte `value`. -/// -/// * If `index` < 0, position counts from the end of the BLOB (`-1` is the last byte). -/// * If `index` < -length of BLOB, the BLOB is not modified. -/// * If `index` ≥ length of BLOB, the BLOB is not modified. -/// -/// # Example -/// -/// ```rhai -/// let b = blob(); -/// -/// b += 1; b += 2; b += 3; b += 4; b += 5; -/// -/// b.set(0, 0x42); -/// -/// print(b); // prints "[4202030405]" -/// -/// b.set(-3, 0); -/// -/// print(b); // prints "[4202000405]" -/// -/// b.set(99, 123); -/// -/// print(b); // prints "[4202000405]" -/// ``` -fn set(blob: Blob, index: int, value: int) -> (); - -/// Set the value of the `property` in the object map to a new `value`. -/// -/// If `property` does not exist in the object map, it is added. -/// -/// # Example -/// -/// ```rhai -/// let m = #{a: 1, b: 2, c: 3}; -/// -/// m.set("b", 42)' -/// -/// print(m); // prints "#{a: 1, b: 42, c: 3}" -/// -/// x.set("x", 0); -/// -/// print(m); // prints "#{a: 1, b: 42, c: 3, x: 0}" -/// ``` -fn set(map: Map, property: String, value: ?) -> (); - -/// Set the `index` position in the string to a new `character`. -/// -/// * If `index` < 0, position counts from the end of the string (`-1` is the last character). -/// * If `index` < -length of string, the string is not modified. -/// * If `index` ≥ length of string, the string is not modified. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world!"; -/// -/// text.set(3, 'x'); -/// -/// print(text); // prints "helxo, world!" -/// -/// text.set(-3, 'x'); -/// -/// print(text); // prints "hello, worxd!" -/// -/// text.set(99, 'x'); -/// -/// print(text); // prints "hello, worxd!" -/// ``` -fn set(string: String, index: int, character: char) -> (); - -/// Set the _tag_ of a `Dynamic` value. -/// -/// # Example -/// -/// ```rhai -/// let x = "hello, world!"; -/// -/// x.tag = 42; -/// -/// print(x.tag); // prints 42 -/// ``` -fn set tag(value: ?, tag: int) -> (); - -/// Set the specified `bit` in the number if the new value is `true`. -/// Clear the `bit` if the new value is `false`. -/// -/// If `bit` < 0, position counts from the MSB (Most Significant Bit). -/// -/// # Example -/// -/// ```rhai -/// let x = 123456; -/// -/// x.set_bit(5, true); -/// -/// print(x); // prints 123488 -/// -/// x.set_bit(6, false); -/// -/// print(x); // prints 123424 -/// -/// x.set_bit(-48, false); -/// -/// print(x); // prints 57888 on 64-bit -/// ``` -fn set_bit(value: int, bit: int, new_value: bool) -> (); - -/// Replace an exclusive range of bits in the number with a new value. -/// -/// # Example -/// -/// ```rhai -/// let x = 123456; -/// -/// x.set_bits(5..10, 42); -/// -/// print(x); // print 123200 -/// ``` -fn set_bits(value: int, range: Range, new_value: int) -> (); - -/// Replace an inclusive range of bits in the number with a new value. -/// -/// # Example -/// -/// ```rhai -/// let x = 123456; -/// -/// x.set_bits(5..=9, 42); -/// -/// print(x); // print 123200 -/// ``` -fn set_bits(value: int, range: RangeInclusive, new_value: int) -> (); - -/// Replace a portion of bits in the number with a new value. -/// -/// * If `start` < 0, position counts from the MSB (Most Significant Bit). -/// * If `bits` ≤ 0, the number is not modified. -/// * If `start` position + `bits` ≥ total number of bits, the bits after the `start` position are replaced. -/// -/// # Example -/// -/// ```rhai -/// let x = 123456; -/// -/// x.set_bits(5, 8, 42); -/// -/// print(x); // prints 124224 -/// -/// x.set_bits(-16, 10, 42); -/// -/// print(x); // prints 11821949021971776 on 64-bit -/// ``` -fn set_bits(value: int, bit: int, bits: int, new_value: int) -> (); - -/// Set the _tag_ of a `Dynamic` value. -/// -/// # Example -/// -/// ```rhai -/// let x = "hello, world!"; -/// -/// x.tag = 42; -/// -/// print(x.tag); // prints 42 -/// ``` -fn set_tag(value: ?, tag: int) -> (); - -/// Remove the first element from the array and return it. -/// -/// If the array is empty, `()` is returned. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3]; -/// -/// print(x.shift()); // prints 1 -/// -/// print(x); // prints "[2, 3]" -/// ``` -fn shift(array: Array) -> ?; - -/// Remove the first byte from the BLOB and return it. -/// -/// If the BLOB is empty, zero is returned. -/// -/// # Example -/// -/// ```rhai -/// let b = blob(); -/// -/// b += 1; b += 2; b += 3; b += 4; b += 5; -/// -/// print(b.shift()); // prints 1 -/// -/// print(b); // prints "[02030405]" -/// ``` -fn shift(blob: Blob) -> int; - -/// Return the sign (as an integer) of the number according to the following: -/// -/// * `0` if the number is zero -/// * `1` if the number is positive -/// * `-1` if the number is negative -fn sign(x: int) -> int; - -/// Return the sign (as an integer) of the floating-point number according to the following: -/// -/// * `0` if the number is zero -/// * `1` if the number is positive -/// * `-1` if the number is negative -fn sign(x: f32) -> int; - -/// Return the sign (as an integer) of the floating-point number according to the following: -/// -/// * `0` if the number is zero -/// * `1` if the number is positive -/// * `-1` if the number is negative -fn sign(x: float) -> int; - -/// Return the sign (as an integer) of the number according to the following: -/// -/// * `0` if the number is zero -/// * `1` if the number is positive -/// * `-1` if the number is negative -fn sign(x: i128) -> int; - -/// Return the sign (as an integer) of the number according to the following: -/// -/// * `0` if the number is zero -/// * `1` if the number is positive -/// * `-1` if the number is negative -fn sign(x: i16) -> int; - -/// Return the sign (as an integer) of the number according to the following: -/// -/// * `0` if the number is zero -/// * `1` if the number is positive -/// * `-1` if the number is negative -fn sign(x: i32) -> int; - -/// Return the sign (as an integer) of the number according to the following: -/// -/// * `0` if the number is zero -/// * `1` if the number is positive -/// * `-1` if the number is negative -fn sign(x: i8) -> int; - -/// Return the sine of the floating-point number in radians. -fn sin(x: float) -> float; - -/// Return the hyperbolic sine of the floating-point number in radians. -fn sinh(x: float) -> float; - -/// Block the current thread for a particular number of `seconds`. -fn sleep(seconds: int) -> (); - -/// Block the current thread for a particular number of `seconds`. -fn sleep(seconds: float) -> (); - -/// Return `true` if any element in the array that returns `true` when applied a function named -/// by `filter`. -/// -/// # Function Parameters -/// -/// A function with the same name as the value of `filter` must exist taking these parameters: -/// -/// * `element`: copy of array element -/// * `index` _(optional)_: current index in the array -/// -/// # Example -/// -/// ```rhai -/// fn large(x) { x > 3 } -/// -/// fn huge(x) { x > 10 } -/// -/// fn screen(x, i) { i > x } -/// -/// let x = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 5]; -/// -/// print(x.some("large")); // prints true -/// -/// print(x.some("huge")); // prints false -/// -/// print(x.some("screen")); // prints true -/// ``` -fn some(array: Array, filter: String) -> bool; - -/// Return `true` if any element in the array that returns `true` when applied the `filter` function. -/// -/// # Function Parameters -/// -/// * `element`: copy of array element -/// * `index` _(optional)_: current index in the array -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 5]; -/// -/// print(x.some(|v| v > 3)); // prints true -/// -/// print(x.some(|v| v > 10)); // prints false -/// -/// print(x.some(|v, i| i > v)); // prints true -/// ``` -fn some(array: Array, filter: FnPtr) -> bool; - -/// Sort the array. -/// -/// All elements in the array must be of the same data type. -/// -/// # Supported Data Types -/// -/// * integer numbers -/// * floating-point numbers -/// * decimal numbers -/// * characters -/// * strings -/// * booleans -/// * `()` -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 3, 5, 7, 9, 2, 4, 6, 8, 10]; -/// -/// x.sort(); -/// -/// print(x); // prints "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]" -/// ``` -fn sort(array: Array) -> (); - -/// Sort the array based on applying a function named by `comparer`. -/// -/// # Function Parameters -/// -/// A function with the same name as the value of `comparer` must exist taking these parameters: -/// -/// * `element1`: copy of the current array element to compare -/// * `element2`: copy of the next array element to compare -/// -/// ## Return Value -/// -/// * Any integer > 0 if `element1 > element2` -/// * Zero if `element1 == element2` -/// * Any integer < 0 if `element1 < element2` -/// -/// # Example -/// -/// ```rhai -/// fn reverse(a, b) { -/// if a > b { -/// -1 -/// } else if a < b { -/// 1 -/// } else { -/// 0 -/// } -/// } -/// let x = [1, 3, 5, 7, 9, 2, 4, 6, 8, 10]; -/// -/// x.sort("reverse"); -/// -/// print(x); // prints "[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]" -/// ``` -fn sort(array: Array, comparer: String) -> (); - -/// Sort the array based on applying the `comparer` function. -/// -/// # Function Parameters -/// -/// * `element1`: copy of the current array element to compare -/// * `element2`: copy of the next array element to compare -/// -/// ## Return Value -/// -/// * Any integer > 0 if `element1 > element2` -/// * Zero if `element1 == element2` -/// * Any integer < 0 if `element1 < element2` -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 3, 5, 7, 9, 2, 4, 6, 8, 10]; -/// -/// // Do comparisons in reverse -/// x.sort(|a, b| if a > b { -1 } else if a < b { 1 } else { 0 }); -/// -/// print(x); // prints "[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]" -/// ``` -fn sort(array: Array, comparer: FnPtr) -> (); - -/// Replace an exclusive range of the array with another array. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 5]; -/// let y = [7, 8, 9, 10]; -/// -/// x.splice(1..3, y); -/// -/// print(x); // prints "[1, 7, 8, 9, 10, 4, 5]" -/// ``` -fn splice(array: Array, range: Range, replace: Array) -> (); - -/// Replace an inclusive range of the array with another array. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 5]; -/// let y = [7, 8, 9, 10]; -/// -/// x.splice(1..=3, y); -/// -/// print(x); // prints "[1, 7, 8, 9, 10, 5]" -/// ``` -fn splice(array: Array, range: RangeInclusive, replace: Array) -> (); - -/// Replace an exclusive `range` of the BLOB with another BLOB. -/// -/// # Example -/// -/// ```rhai -/// let b1 = blob(10, 0x42); -/// let b2 = blob(5, 0x18); -/// -/// b1.splice(1..4, b2); -/// -/// print(b1); // prints "[4218181818184242 42424242]" -/// ``` -fn splice(blob: Blob, range: Range, replace: Blob) -> (); - -/// Replace an inclusive `range` of the BLOB with another BLOB. -/// -/// # Example -/// -/// ```rhai -/// let b1 = blob(10, 0x42); -/// let b2 = blob(5, 0x18); -/// -/// b1.splice(1..=4, b2); -/// -/// print(b1); // prints "[4218181818184242 424242]" -/// ``` -fn splice(blob: Blob, range: RangeInclusive, replace: Blob) -> (); - -/// Replace a portion of the array with another array. -/// -/// * If `start` < 0, position counts from the end of the array (`-1` is the last element). -/// * If `start` < -length of array, position counts from the beginning of the array. -/// * If `start` ≥ length of array, the other array is appended to the end of the array. -/// * If `len` ≤ 0, the other array is inserted into the array at the `start` position without replacing any element. -/// * If `start` position + `len` ≥ length of array, entire portion of the array after the `start` position is replaced. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 5]; -/// let y = [7, 8, 9, 10]; -/// -/// x.splice(1, 2, y); -/// -/// print(x); // prints "[1, 7, 8, 9, 10, 4, 5]" -/// -/// x.splice(-5, 4, y); -/// -/// print(x); // prints "[1, 7, 7, 8, 9, 10, 5]" -/// ``` -fn splice(array: Array, start: int, len: int, replace: Array) -> (); - -/// Replace a portion of the BLOB with another BLOB. -/// -/// * If `start` < 0, position counts from the end of the BLOB (`-1` is the last byte). -/// * If `start` < -length of BLOB, position counts from the beginning of the BLOB. -/// * If `start` ≥ length of BLOB, the other BLOB is appended to the end of the BLOB. -/// * If `len` ≤ 0, the other BLOB is inserted into the BLOB at the `start` position without replacing anything. -/// * If `start` position + `len` ≥ length of BLOB, entire portion of the BLOB after the `start` position is replaced. -/// -/// # Example -/// -/// ```rhai -/// let b1 = blob(10, 0x42); -/// let b2 = blob(5, 0x18); -/// -/// b1.splice(1, 3, b2); -/// -/// print(b1); // prints "[4218181818184242 42424242]" -/// -/// b1.splice(-5, 4, b2); -/// -/// print(b1); // prints "[4218181818184218 1818181842]" -/// ``` -fn splice(blob: Blob, start: int, len: int, replace: Blob) -> (); - -/// Split the string into segments based on whitespaces, returning an array of the segments. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world! hello, foo!"; -/// -/// print(text.split()); // prints ["hello,", "world!", "hello,", "foo!"] -/// ``` -fn split(string: String) -> Array; - -/// Cut off the array at `index` and return it as a new array. -/// -/// * If `index` < 0, position counts from the end of the array (`-1` is the last element). -/// * If `index` is zero, the entire array is cut and returned. -/// * If `index` < -length of array, the entire array is cut and returned. -/// * If `index` ≥ length of array, nothing is cut from the array and an empty array is returned. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 5]; -/// -/// let y = x.split(2); -/// -/// print(y); // prints "[3, 4, 5]" -/// -/// print(x); // prints "[1, 2]" -/// ``` -fn split(array: Array, index: int) -> Array; - -/// Cut off the BLOB at `index` and return it as a new BLOB. -/// -/// * If `index` < 0, position counts from the end of the BLOB (`-1` is the last byte). -/// * If `index` is zero, the entire BLOB is cut and returned. -/// * If `index` < -length of BLOB, the entire BLOB is cut and returned. -/// * If `index` ≥ length of BLOB, nothing is cut from the BLOB and an empty BLOB is returned. -/// -/// # Example -/// -/// ```rhai -/// let b1 = blob(); -/// -/// b1 += 1; b1 += 2; b1 += 3; b1 += 4; b1 += 5; -/// -/// let b2 = b1.split(2); -/// -/// print(b2); // prints "[030405]" -/// -/// print(b1); // prints "[0102]" -/// ``` -fn split(blob: Blob, index: int) -> Blob; - -/// Split the string into two at the specified `index` position and return it both strings -/// as an array. -/// -/// The character at the `index` position (if any) is returned in the _second_ string. -/// -/// * If `index` < 0, position counts from the end of the string (`-1` is the last character). -/// * If `index` < -length of string, it is equivalent to cutting at position 0. -/// * If `index` ≥ length of string, it is equivalent to cutting at the end of the string. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world!"; -/// -/// print(text.split(6)); // prints ["hello,", " world!"] -/// -/// print(text.split(13)); // prints ["hello, world!", ""] -/// -/// print(text.split(-6)); // prints ["hello, ", "world!"] -/// -/// print(text.split(-99)); // prints ["", "hello, world!"] -/// ``` -fn split(string: String, index: int) -> Array; - -/// Split the string into segments based on a `delimiter` string, returning an array of the segments. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world! hello, foo!"; -/// -/// print(text.split("ll")); // prints ["he", "o, world! he", "o, foo!"] -/// ``` -fn split(string: String, delimiter: String) -> Array; - -/// Split the string into segments based on a `delimiter` character, returning an array of the segments. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world! hello, foo!"; -/// -/// print(text.split('l')); // prints ["he", "", "o, wor", "d! he", "", "o, foo!"] -/// ``` -fn split(string: String, delimiter: char) -> Array; - -/// Split the string into at most the specified number of `segments` based on a `delimiter` string, -/// returning an array of the segments. -/// -/// If `segments` < 1, only one segment is returned. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world! hello, foo!"; -/// -/// print(text.split("ll", 2)); // prints ["he", "o, world! hello, foo!"] -/// ``` -fn split(string: String, delimiter: String, segments: int) -> Array; - -/// Split the string into at most the specified number of `segments` based on a `delimiter` character, -/// returning an array of the segments. -/// -/// If `segments` < 1, only one segment is returned. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world! hello, foo!"; -/// -/// print(text.split('l', 3)); // prints ["he", "", "o, world! hello, foo!"] -/// ``` -fn split(string: String, delimiter: char, segments: int) -> Array; - -/// Split the string into segments based on a `delimiter` string, returning an array of the -/// segments in _reverse_ order. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world! hello, foo!"; -/// -/// print(text.split_rev("ll")); // prints ["o, foo!", "o, world! he", "he"] -/// ``` -fn split_rev(string: String, delimiter: String) -> Array; - -/// Split the string into segments based on a `delimiter` character, returning an array of -/// the segments in _reverse_ order. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world! hello, foo!"; -/// -/// print(text.split_rev('l')); // prints ["o, foo!", "", "d! he", "o, wor", "", "he"] -/// ``` -fn split_rev(string: String, delimiter: char) -> Array; - -/// Split the string into at most a specified number of `segments` based on a `delimiter` string, -/// returning an array of the segments in _reverse_ order. -/// -/// If `segments` < 1, only one segment is returned. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world! hello, foo!"; -/// -/// print(text.split_rev("ll", 2)); // prints ["o, foo!", "hello, world! he"] -/// ``` -fn split_rev(string: String, delimiter: String, segments: int) -> Array; - -/// Split the string into at most the specified number of `segments` based on a `delimiter` character, -/// returning an array of the segments. -/// -/// If `segments` < 1, only one segment is returned. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world! hello, foo!"; -/// -/// print(text.split('l', 3)); // prints ["o, foo!", "", "hello, world! he" -/// ``` -fn split_rev(string: String, delimiter: char, segments: int) -> Array; - -/// Return the square root of the floating-point number. -fn sqrt(x: float) -> float; - -/// Return the start of the exclusive range. -fn start(range: ExclusiveRange) -> int; - -/// Return the start of the inclusive range. -fn start(range: InclusiveRange) -> int; - -/// Return `true` if the string starts with a specified string. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world!"; -/// -/// print(text.starts_with("hello")); // prints true -/// -/// print(text.starts_with("world")); // prints false -/// ``` -fn starts_with(string: String, match_string: String) -> bool; - -/// Copy an exclusive range of characters from the string and return it as a new string. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world!"; -/// -/// print(text.sub_string(3..7)); // prints "lo, " -/// ``` -fn sub_string(string: String, range: Range) -> String; - -/// Copy an inclusive range of characters from the string and return it as a new string. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world!"; -/// -/// print(text.sub_string(3..=7)); // prints "lo, w" -/// ``` -fn sub_string(string: String, range: RangeInclusive) -> String; - -/// Copy a portion of the string beginning at the `start` position till the end and return it as -/// a new string. -/// -/// * If `start` < 0, position counts from the end of the string (`-1` is the last character). -/// * If `start` < -length of string, the entire string is copied and returned. -/// * If `start` ≥ length of string, an empty string is returned. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world!"; -/// -/// print(text.sub_string(5)); // prints ", world!" -/// -/// print(text.sub_string(-5)); // prints "orld!" -/// ``` -fn sub_string(string: String, start: int) -> String; - -/// Copy a portion of the string and return it as a new string. -/// -/// * If `start` < 0, position counts from the end of the string (`-1` is the last character). -/// * If `start` < -length of string, position counts from the beginning of the string. -/// * If `start` ≥ length of string, an empty string is returned. -/// * If `len` ≤ 0, an empty string is returned. -/// * If `start` position + `len` ≥ length of string, entire portion of the string after the `start` position is copied and returned. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world!"; -/// -/// print(text.sub_string(3, 4)); // prints "lo, " -/// -/// print(text.sub_string(-8, 3)); // prints ", w" -/// ``` -fn sub_string(string: String, start: int, len: int) -> String; - -/// Return the _tag_ of a `Dynamic` value. -/// -/// # Example -/// -/// ```rhai -/// let x = "hello, world!"; -/// -/// x.tag = 42; -/// -/// print(x.tag); // prints 42 -/// ``` -fn tag(value: ?) -> int; - -/// Return the tangent of the floating-point number in radians. -fn tan(x: float) -> float; - -/// Return the hyperbolic tangent of the floating-point number in radians. -fn tanh(x: float) -> float; - -/// Create a timestamp containing the current system time. -/// -/// # Example -/// -/// ```rhai -/// let now = timestamp(); -/// -/// sleep(10.0); // sleep for 10 seconds -/// -/// print(now.elapsed); // prints 10.??? -/// ``` -fn timestamp() -> Instant; - -/// Convert the BLOB into an array of integers. -/// -/// # Example -/// -/// ```rhai -/// let b = blob(5, 0x42); -/// -/// let x = b.to_array(); -/// -/// print(x); // prints "[66, 66, 66, 66, 66]" -/// ``` -fn to_array(blob: Blob) -> Array; - -/// Convert the `value` into a string in binary format. -fn to_binary(value: i128) -> String; - -/// Convert the `value` into a string in binary format. -fn to_binary(value: i16) -> String; - -/// Convert the `value` into a string in binary format. -fn to_binary(value: i32) -> String; - -/// Convert the `value` into a string in binary format. -fn to_binary(value: int) -> String; - -/// Convert the `value` into a string in binary format. -fn to_binary(value: i8) -> String; - -/// Convert the `value` into a string in binary format. -fn to_binary(value: u128) -> String; - -/// Convert the `value` into a string in binary format. -fn to_binary(value: u16) -> String; - -/// Convert the `value` into a string in binary format. -fn to_binary(value: u32) -> String; - -/// Convert the `value` into a string in binary format. -fn to_binary(value: u64) -> String; - -/// Convert the `value` into a string in binary format. -fn to_binary(value: u8) -> String; - -/// Convert the string into an UTF-8 encoded byte-stream as a BLOB. -/// -/// # Example -/// -/// ```rhai -/// let text = "朝には紅顔ありて夕べには白骨となる"; -/// -/// let bytes = text.to_blob(); -/// -/// print(bytes.len()); // prints 51 -/// ``` -fn to_blob(string: String) -> Blob; - -/// Return an array containing all the characters of the string. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello"; -/// -/// print(text.to_chars()); // prints "['h', 'e', 'l', 'l', 'o']" -/// ``` -fn to_chars(string: String) -> Array; - -/// Convert the array into a string. -fn to_debug(array: Array) -> String; - -/// Convert the string into debug format. -fn to_debug(character: char) -> String; - -/// Convert the function pointer into a string in debug format. -fn to_debug(f: FnPtr) -> String; - -/// Convert the value of the `item` into a string in debug format. -fn to_debug(item: ?) -> String; - -/// Convert the object map into a string. -fn to_debug(map: Map) -> String; - -/// Convert the value of `number` into a string. -fn to_debug(number: f32) -> String; - -/// Convert the value of `number` into a string. -fn to_debug(number: float) -> String; - -/// Convert the string into debug format. -fn to_debug(string: String) -> String; - -/// Convert the unit into a string in debug format. -fn to_debug(unit: ()) -> String; - -/// Convert the boolean value into a string in debug format. -fn to_debug(value: bool) -> String; - -/// Convert radians to degrees. -fn to_degrees(x: float) -> float; - -/// Convert the 32-bit floating-point number to 64-bit. -fn to_float(x: f32) -> float; - -fn to_float(x: i128) -> float; - -fn to_float(x: i16) -> float; - -fn to_float(x: i32) -> float; - -fn to_float(x: int) -> float; - -fn to_float(x: i8) -> float; - -fn to_float(x: u128) -> float; - -fn to_float(x: u16) -> float; - -fn to_float(x: u32) -> float; - -fn to_float(x: u8) -> float; - -/// Convert the `value` into a string in hex format. -fn to_hex(value: i128) -> String; - -/// Convert the `value` into a string in hex format. -fn to_hex(value: i16) -> String; - -/// Convert the `value` into a string in hex format. -fn to_hex(value: i32) -> String; - -/// Convert the `value` into a string in hex format. -fn to_hex(value: int) -> String; - -/// Convert the `value` into a string in hex format. -fn to_hex(value: i8) -> String; - -/// Convert the `value` into a string in hex format. -fn to_hex(value: u128) -> String; - -/// Convert the `value` into a string in hex format. -fn to_hex(value: u16) -> String; - -/// Convert the `value` into a string in hex format. -fn to_hex(value: u32) -> String; - -/// Convert the `value` into a string in hex format. -fn to_hex(value: u64) -> String; - -/// Convert the `value` into a string in hex format. -fn to_hex(value: u8) -> String; - -fn to_int(x: char) -> int; - -/// Convert the floating-point number into an integer. -fn to_int(x: f32) -> int; - -/// Convert the floating-point number into an integer. -fn to_int(x: float) -> int; - -fn to_int(x: i128) -> int; - -fn to_int(x: i16) -> int; - -fn to_int(x: i32) -> int; - -fn to_int(x: int) -> int; - -fn to_int(x: i8) -> int; - -fn to_int(x: u128) -> int; - -fn to_int(x: u16) -> int; - -fn to_int(x: u32) -> int; - -fn to_int(x: u64) -> int; - -fn to_int(x: u8) -> int; - -/// Return the JSON representation of the object map. -/// -/// # Data types -/// -/// Only the following data types should be kept inside the object map: -/// `INT`, `FLOAT`, `ImmutableString`, `char`, `bool`, `()`, `Array`, `Map`. -/// -/// # Errors -/// -/// Data types not supported by JSON serialize into formats that may -/// invalidate the result. -/// -/// # Example -/// -/// ```rhai -/// let m = #{a:1, b:2, c:3}; -/// -/// print(m.to_json()); // prints {"a":1, "b":2, "c":3} -/// ``` -fn to_json(map: Map) -> String; - -/// Convert the character to lower-case and return it as a new character. -/// -/// # Example -/// -/// ```rhai -/// let ch = 'A'; -/// -/// print(ch.to_lower()); // prints 'a' -/// -/// print(ch); // prints 'A' -/// ``` -fn to_lower(character: char) -> char; - -/// Convert the string to all lower-case and return it as a new string. -/// -/// # Example -/// -/// ```rhai -/// let text = "HELLO, WORLD!" -/// -/// print(text.to_lower()); // prints "hello, world!" -/// -/// print(text); // prints "HELLO, WORLD!" -/// ``` -fn to_lower(string: String) -> String; - -/// Convert the `value` into a string in octal format. -fn to_octal(value: i128) -> String; - -/// Convert the `value` into a string in octal format. -fn to_octal(value: i16) -> String; - -/// Convert the `value` into a string in octal format. -fn to_octal(value: i32) -> String; - -/// Convert the `value` into a string in octal format. -fn to_octal(value: int) -> String; - -/// Convert the `value` into a string in octal format. -fn to_octal(value: i8) -> String; - -/// Convert the `value` into a string in octal format. -fn to_octal(value: u128) -> String; - -/// Convert the `value` into a string in octal format. -fn to_octal(value: u16) -> String; - -/// Convert the `value` into a string in octal format. -fn to_octal(value: u32) -> String; - -/// Convert the `value` into a string in octal format. -fn to_octal(value: u64) -> String; - -/// Convert the `value` into a string in octal format. -fn to_octal(value: u8) -> String; - -/// Convert degrees to radians. -fn to_radians(x: float) -> float; - -/// Convert the array into a string. -fn to_string(array: Array) -> String; - -/// Return the character into a string. -fn to_string(character: char) -> String; - -/// Convert the value of the `item` into a string. -fn to_string(item: ?) -> String; - -/// Convert the object map into a string. -fn to_string(map: Map) -> String; - -/// Convert the value of `number` into a string. -fn to_string(number: f32) -> String; - -/// Convert the value of `number` into a string. -fn to_string(number: float) -> String; - -/// Return the `string`. -fn to_string(string: String) -> String; - -/// Return the empty string. -fn to_string(unit: ()) -> String; - -/// Return the boolean value into a string. -fn to_string(value: bool) -> String; - -/// Convert the character to upper-case and return it as a new character. -/// -/// # Example -/// -/// ```rhai -/// let ch = 'a'; -/// -/// print(ch.to_upper()); // prints 'A' -/// -/// print(ch); // prints 'a' -/// ``` -fn to_upper(character: char) -> char; - -/// Convert the string to all upper-case and return it as a new string. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world!" -/// -/// print(text.to_upper()); // prints "HELLO, WORLD!" -/// -/// print(text); // prints "hello, world!" -/// ``` -fn to_upper(string: String) -> String; - -/// Remove whitespace characters from both ends of the string. -/// -/// # Example -/// -/// ```rhai -/// let text = " hello "; -/// -/// text.trim(); -/// -/// print(text); // prints "hello" -/// ``` -fn trim(string: String) -> (); - -/// Cut off the array at the specified length. -/// -/// * If `len` ≤ 0, the array is cleared. -/// * If `len` ≥ length of array, the array is not truncated. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 5]; -/// -/// x.truncate(3); -/// -/// print(x); // prints "[1, 2, 3]" -/// -/// x.truncate(10); -/// -/// print(x); // prints "[1, 2, 3]" -/// ``` -fn truncate(array: Array, len: int) -> (); - -/// Cut off the BLOB at the specified length. -/// -/// * If `len` ≤ 0, the BLOB is cleared. -/// * If `len` ≥ length of BLOB, the BLOB is not truncated. -/// -/// # Example -/// -/// ```rhai -/// let b = blob(); -/// -/// b += 1; b += 2; b += 3; b += 4; b += 5; -/// -/// b.truncate(3); -/// -/// print(b); // prints "[010203]" -/// -/// b.truncate(10); -/// -/// print(b); // prints "[010203]" -/// ``` -fn truncate(blob: Blob, len: int) -> (); - -/// Cut off the string at the specified number of characters. -/// -/// * If `len` ≤ 0, the string is cleared. -/// * If `len` ≥ length of string, the string is not truncated. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world! hello, foobar!"; -/// -/// text.truncate(13); -/// -/// print(text); // prints "hello, world!" -/// -/// x.truncate(10); -/// -/// print(text); // prints "hello, world!" -/// ``` -fn truncate(string: String, len: int) -> (); - -/// Return an array with all the property values in the object map. -/// -/// # Example -/// -/// ```rhai -/// let m = #{a:1, b:2, c:3}; -/// -/// print(m.values()); // prints "[1, 2, 3]"" -/// ``` -fn values(map: Map) -> Array; - -/// Write an ASCII string to the bytes within an exclusive `range` in the BLOB. -/// -/// Each ASCII character encodes to one single byte in the BLOB. -/// Non-ASCII characters are ignored. -/// -/// * If number of bytes in `range` < length of `string`, extra bytes in `string` are not written. -/// * If number of bytes in `range` > length of `string`, extra bytes in `range` are not modified. -/// -/// ```rhai -/// let b = blob(8); -/// -/// b.write_ascii(1..5, "hello, world!"); -/// -/// print(b); // prints "[0068656c6c000000]" -/// ``` -fn write_ascii(blob: Blob, range: Range, string: String) -> (); - -/// Write an ASCII string to the bytes within an inclusive `range` in the BLOB. -/// -/// Each ASCII character encodes to one single byte in the BLOB. -/// Non-ASCII characters are ignored. -/// -/// * If number of bytes in `range` < length of `string`, extra bytes in `string` are not written. -/// * If number of bytes in `range` > length of `string`, extra bytes in `range` are not modified. -/// -/// ```rhai -/// let b = blob(8); -/// -/// b.write_ascii(1..=5, "hello, world!"); -/// -/// print(b); // prints "[0068656c6c6f0000]" -/// ``` -fn write_ascii(blob: Blob, range: RangeInclusive, string: String) -> (); - -/// Write an ASCII string to the bytes within an exclusive `range` in the BLOB. -/// -/// * If `start` < 0, position counts from the end of the BLOB (`-1` is the last byte). -/// * If `start` < -length of BLOB, position counts from the beginning of the BLOB. -/// * If `start` ≥ length of BLOB, the BLOB is not modified. -/// * If `len` ≤ 0, the BLOB is not modified. -/// * If `start` position + `len` ≥ length of BLOB, only the portion of the BLOB after the `start` position is modified. -/// -/// * If number of bytes in `range` < length of `string`, extra bytes in `string` are not written. -/// * If number of bytes in `range` > length of `string`, extra bytes in `range` are not modified. -/// -/// ```rhai -/// let b = blob(8); -/// -/// b.write_ascii(1, 5, "hello, world!"); -/// -/// print(b); // prints "[0068656c6c6f0000]" -/// ``` -fn write_ascii(blob: Blob, start: int, len: int, string: String) -> (); - -/// Write a `FLOAT` value to the bytes within an exclusive `range` in the BLOB -/// in big-endian byte order. -/// -/// * If number of bytes in `range` < number of bytes for `FLOAT`, extra bytes in `FLOAT` are not written. -/// * If number of bytes in `range` > number of bytes for `FLOAT`, extra bytes in `range` are not modified. -fn write_be(blob: Blob, range: Range, value: float) -> (); - -/// Write an `INT` value to the bytes within an exclusive `range` in the BLOB -/// in big-endian byte order. -/// -/// * If number of bytes in `range` < number of bytes for `INT`, extra bytes in `INT` are not written. -/// * If number of bytes in `range` > number of bytes for `INT`, extra bytes in `range` are not modified. -/// -/// ```rhai -/// let b = blob(8, 0x42); -/// -/// b.write_be_int(1..3, 0x99); -/// -/// print(b); // prints "[4200004242424242]" -/// ``` -fn write_be(blob: Blob, range: Range, value: int) -> (); - -/// Write a `FLOAT` value to the bytes within an inclusive `range` in the BLOB -/// in big-endian byte order. -/// -/// * If number of bytes in `range` < number of bytes for `FLOAT`, extra bytes in `FLOAT` are not written. -/// * If number of bytes in `range` > number of bytes for `FLOAT`, extra bytes in `range` are not modified. -fn write_be(blob: Blob, range: RangeInclusive, value: float) -> (); - -/// Write an `INT` value to the bytes within an inclusive `range` in the BLOB -/// in big-endian byte order. -/// -/// * If number of bytes in `range` < number of bytes for `INT`, extra bytes in `INT` are not written. -/// * If number of bytes in `range` > number of bytes for `INT`, extra bytes in `range` are not modified. -/// -/// ```rhai -/// let b = blob(8, 0x42); -/// -/// b.write_be_int(1..=3, 0x99); -/// -/// print(b); // prints "[4200000042424242]" -/// ``` -fn write_be(blob: Blob, range: RangeInclusive, value: int) -> (); - -/// Write a `FLOAT` value to the bytes beginning at the `start` position in the BLOB -/// in big-endian byte order. -/// -/// * If `start` < 0, position counts from the end of the BLOB (`-1` is the last byte). -/// * If `start` < -length of BLOB, position counts from the beginning of the BLOB. -/// * If `start` ≥ length of BLOB, zero is returned. -/// * If `len` ≤ 0, zero is returned. -/// * If `start` position + `len` ≥ length of BLOB, entire portion of the BLOB after the `start` position is parsed. -/// -/// * If number of bytes in `range` < number of bytes for `FLOAT`, extra bytes in `FLOAT` are not written. -/// * If number of bytes in `range` > number of bytes for `FLOAT`, extra bytes in `range` are not modified. -fn write_be(blob: Blob, start: int, len: int, value: float) -> (); - -/// Write an `INT` value to the bytes beginning at the `start` position in the BLOB -/// in big-endian byte order. -/// -/// * If `start` < 0, position counts from the end of the BLOB (`-1` is the last byte). -/// * If `start` < -length of BLOB, position counts from the beginning of the BLOB. -/// * If `start` ≥ length of BLOB, zero is returned. -/// * If `len` ≤ 0, zero is returned. -/// * If `start` position + `len` ≥ length of BLOB, entire portion of the BLOB after the `start` position is parsed. -/// -/// * If number of bytes in `range` < number of bytes for `INT`, extra bytes in `INT` are not written. -/// * If number of bytes in `range` > number of bytes for `INT`, extra bytes in `range` are not modified. -/// -/// ```rhai -/// let b = blob(8, 0x42); -/// -/// b.write_be_int(1, 3, 0x99); -/// -/// print(b); // prints "[4200000042424242]" -/// ``` -fn write_be(blob: Blob, start: int, len: int, value: int) -> (); - -/// Write a `FLOAT` value to the bytes within an exclusive `range` in the BLOB -/// in little-endian byte order. -/// -/// * If number of bytes in `range` < number of bytes for `FLOAT`, extra bytes in `FLOAT` are not written. -/// * If number of bytes in `range` > number of bytes for `FLOAT`, extra bytes in `range` are not modified. -fn write_le(blob: Blob, range: Range, value: float) -> (); - -/// Write an `INT` value to the bytes within an exclusive `range` in the BLOB -/// in little-endian byte order. -/// -/// * If number of bytes in `range` < number of bytes for `INT`, extra bytes in `INT` are not written. -/// * If number of bytes in `range` > number of bytes for `INT`, extra bytes in `range` are not modified. -/// -/// ```rhai -/// let b = blob(8); -/// -/// b.write_le_int(1..3, 0x12345678); -/// -/// print(b); // prints "[0078560000000000]" -/// ``` -fn write_le(blob: Blob, range: Range, value: int) -> (); - -/// Write a `FLOAT` value to the bytes within an inclusive `range` in the BLOB -/// in little-endian byte order. -/// -/// * If number of bytes in `range` < number of bytes for `FLOAT`, extra bytes in `FLOAT` are not written. -/// * If number of bytes in `range` > number of bytes for `FLOAT`, extra bytes in `range` are not modified. -fn write_le(blob: Blob, range: RangeInclusive, value: float) -> (); - -/// Write an `INT` value to the bytes within an inclusive `range` in the BLOB -/// in little-endian byte order. -/// -/// * If number of bytes in `range` < number of bytes for `INT`, extra bytes in `INT` are not written. -/// * If number of bytes in `range` > number of bytes for `INT`, extra bytes in `range` are not modified. -/// -/// ```rhai -/// let b = blob(8); -/// -/// b.write_le_int(1..=3, 0x12345678); -/// -/// print(b); // prints "[0078563400000000]" -/// ``` -fn write_le(blob: Blob, range: RangeInclusive, value: int) -> (); - -/// Write a `FLOAT` value to the bytes beginning at the `start` position in the BLOB -/// in little-endian byte order. -/// -/// * If `start` < 0, position counts from the end of the BLOB (`-1` is the last byte). -/// * If `start` < -length of BLOB, position counts from the beginning of the BLOB. -/// * If `start` ≥ length of BLOB, zero is returned. -/// * If `len` ≤ 0, zero is returned. -/// * If `start` position + `len` ≥ length of BLOB, entire portion of the BLOB after the `start` position is parsed. -/// -/// * If number of bytes in `range` < number of bytes for `FLOAT`, extra bytes in `FLOAT` are not written. -/// * If number of bytes in `range` > number of bytes for `FLOAT`, extra bytes in `range` are not modified. -fn write_le(blob: Blob, start: int, len: int, value: float) -> (); - -/// Write an `INT` value to the bytes beginning at the `start` position in the BLOB -/// in little-endian byte order. -/// -/// * If `start` < 0, position counts from the end of the BLOB (`-1` is the last byte). -/// * If `start` < -length of BLOB, position counts from the beginning of the BLOB. -/// * If `start` ≥ length of BLOB, zero is returned. -/// * If `len` ≤ 0, zero is returned. -/// * If `start` position + `len` ≥ length of BLOB, entire portion of the BLOB after the `start` position is parsed. -/// -/// * If number of bytes in `range` < number of bytes for `INT`, extra bytes in `INT` are not written. -/// * If number of bytes in `range` > number of bytes for `INT`, extra bytes in `range` are not modified. -/// -/// ```rhai -/// let b = blob(8); -/// -/// b.write_le_int(1, 3, 0x12345678); -/// -/// print(b); // prints "[0078563400000000]" -/// ``` -fn write_le(blob: Blob, start: int, len: int, value: int) -> (); - -/// Write a string to the bytes within an exclusive `range` in the BLOB in UTF-8 encoding. -/// -/// * If number of bytes in `range` < length of `string`, extra bytes in `string` are not written. -/// * If number of bytes in `range` > length of `string`, extra bytes in `range` are not modified. -/// -/// ```rhai -/// let b = blob(8); -/// -/// b.write_utf8(1..5, "朝には紅顔ありて夕べには白骨となる"); -/// -/// print(b); // prints "[00e69c9de3000000]" -/// ``` -fn write_utf8(blob: Blob, range: Range, string: String) -> (); - -/// Write a string to the bytes within an inclusive `range` in the BLOB in UTF-8 encoding. -/// -/// * If number of bytes in `range` < length of `string`, extra bytes in `string` are not written. -/// * If number of bytes in `range` > length of `string`, extra bytes in `range` are not modified. -/// -/// ```rhai -/// let b = blob(8); -/// -/// b.write_utf8(1..=5, "朝には紅顔ありて夕べには白骨となる"); -/// -/// print(b); // prints "[00e69c9de3810000]" -/// ``` -fn write_utf8(blob: Blob, range: RangeInclusive, string: String) -> (); - -/// Write a string to the bytes within an inclusive `range` in the BLOB in UTF-8 encoding. -/// -/// * If `start` < 0, position counts from the end of the BLOB (`-1` is the last byte). -/// * If `start` < -length of BLOB, position counts from the beginning of the BLOB. -/// * If `start` ≥ length of BLOB, the BLOB is not modified. -/// * If `len` ≤ 0, the BLOB is not modified. -/// * If `start` position + `len` ≥ length of BLOB, only the portion of the BLOB after the `start` position is modified. -/// -/// * If number of bytes in `range` < length of `string`, extra bytes in `string` are not written. -/// * If number of bytes in `range` > length of `string`, extra bytes in `range` are not modified. -/// -/// ```rhai -/// let b = blob(8); -/// -/// b.write_utf8(1, 5, "朝には紅顔ありて夕べには白骨となる"); -/// -/// print(b); // prints "[00e69c9de3810000]" -/// ``` -fn write_utf8(blob: Blob, start: int, len: int, string: String) -> (); - -op |(i128, i128) -> i128; - -op |(i16, i16) -> i16; - -op |(i32, i32) -> i32; - -op |(i8, i8) -> i8; - -op |(u128, u128) -> u128; - -op |(u16, u16) -> u16; - -op |(u32, u32) -> u32; - -op |(u64, u64) -> u64; - -op |(u8, u8) -> u8; - -module general_kenobi { -const CONSTANT: int; - -/// Returns a string where "hello there" is repeated `n` times. -fn hello_there(n: int) -> String; -} - -let hello_there: string; - -const HELLO: string; diff --git a/examples/definitions/.rhai/all_in_one_without_standard.d.rhai b/examples/definitions/.rhai/all_in_one_without_standard.d.rhai deleted file mode 100644 index 729b64fca..000000000 --- a/examples/definitions/.rhai/all_in_one_without_standard.d.rhai +++ /dev/null @@ -1,14 +0,0 @@ -module static; - -op minus(int, int) -> int; - -module general_kenobi { -const CONSTANT: int; - -/// Returns a string where "hello there" is repeated `n` times. -fn hello_there(n: int) -> String; -} - -let hello_there: string; - -const HELLO: string; diff --git a/examples/definitions/.rhai/definitions/__builtin-operators__.d.rhai b/examples/definitions/.rhai/definitions/__builtin-operators__.d.rhai deleted file mode 100644 index 012a95a44..000000000 --- a/examples/definitions/.rhai/definitions/__builtin-operators__.d.rhai +++ /dev/null @@ -1,259 +0,0 @@ -module static; - -op ==(int, int) -> bool; -op !=(int, int) -> bool; -op >(int, int) -> bool; -op >=(int, int) -> bool; -op <(int, int) -> bool; -op <=(int, int) -> bool; -op &(int, int) -> int; -op |(int, int) -> int; -op ^(int, int) -> int; -op ..(int, int) -> Range; -op ..=(int, int) -> RangeInclusive; - -op ==(bool, bool) -> bool; -op !=(bool, bool) -> bool; -op >(bool, bool) -> bool; -op >=(bool, bool) -> bool; -op <(bool, bool) -> bool; -op <=(bool, bool) -> bool; -op &(bool, bool) -> bool; -op |(bool, bool) -> bool; -op ^(bool, bool) -> bool; - -op ==((), ()) -> bool; -op !=((), ()) -> bool; -op >((), ()) -> bool; -op >=((), ()) -> bool; -op <((), ()) -> bool; -op <=((), ()) -> bool; - -op +(int, int) -> int; -op -(int, int) -> int; -op *(int, int) -> int; -op /(int, int) -> int; -op %(int, int) -> int; -op **(int, int) -> int; -op >>(int, int) -> int; -op <<(int, int) -> int; - -op +(float, float) -> float; -op -(float, float) -> float; -op *(float, float) -> float; -op /(float, float) -> float; -op %(float, float) -> float; -op **(float, float) -> float; -op ==(float, float) -> bool; -op !=(float, float) -> bool; -op >(float, float) -> bool; -op >=(float, float) -> bool; -op <(float, float) -> bool; -op <=(float, float) -> bool; - -op +(float, int) -> float; -op -(float, int) -> float; -op *(float, int) -> float; -op /(float, int) -> float; -op %(float, int) -> float; -op **(float, int) -> float; -op ==(float, int) -> bool; -op !=(float, int) -> bool; -op >(float, int) -> bool; -op >=(float, int) -> bool; -op <(float, int) -> bool; -op <=(float, int) -> bool; - -op +(int, float) -> float; -op -(int, float) -> float; -op *(int, float) -> float; -op /(int, float) -> float; -op %(int, float) -> float; -op **(int, float) -> float; -op ==(int, float) -> bool; -op !=(int, float) -> bool; -op >(int, float) -> bool; -op >=(int, float) -> bool; -op <(int, float) -> bool; -op <=(int, float) -> bool; - -op +(Decimal, Decimal) -> Decimal; -op -(Decimal, Decimal) -> Decimal; -op *(Decimal, Decimal) -> Decimal; -op /(Decimal, Decimal) -> Decimal; -op %(Decimal, Decimal) -> Decimal; -op **(Decimal, Decimal) -> Decimal; -op ==(Decimal, Decimal) -> bool; -op !=(Decimal, Decimal) -> bool; -op >(Decimal, Decimal) -> bool; -op >=(Decimal, Decimal) -> bool; -op <(Decimal, Decimal) -> bool; -op <=(Decimal, Decimal) -> bool; - -op +(Decimal, int) -> Decimal; -op -(Decimal, int) -> Decimal; -op *(Decimal, int) -> Decimal; -op /(Decimal, int) -> Decimal; -op %(Decimal, int) -> Decimal; -op **(Decimal, int) -> Decimal; -op ==(Decimal, int) -> bool; -op !=(Decimal, int) -> bool; -op >(Decimal, int) -> bool; -op >=(Decimal, int) -> bool; -op <(Decimal, int) -> bool; -op <=(Decimal, int) -> bool; - -op +(int, Decimal) -> Decimal; -op -(int, Decimal) -> Decimal; -op *(int, Decimal) -> Decimal; -op /(int, Decimal) -> Decimal; -op %(int, Decimal) -> Decimal; -op **(int, Decimal) -> Decimal; -op ==(int, Decimal) -> bool; -op !=(int, Decimal) -> bool; -op >(int, Decimal) -> bool; -op >=(int, Decimal) -> bool; -op <(int, Decimal) -> bool; -op <=(int, Decimal) -> bool; - -op +(String, String) -> String; -op -(String, String) -> String; -op ==(String, String) -> bool; -op !=(String, String) -> bool; -op >(String, String) -> bool; -op >=(String, String) -> bool; -op <(String, String) -> bool; -op <=(String, String) -> bool; - -op +(char, char) -> String; -op ==(char, char) -> bool; -op !=(char, char) -> bool; -op >(char, char) -> bool; -op >=(char, char) -> bool; -op <(char, char) -> bool; -op <=(char, char) -> bool; - -op +(char, String) -> String; -op ==(char, String) -> bool; -op !=(char, String) -> bool; -op >(char, String) -> bool; -op >=(char, String) -> bool; -op <(char, String) -> bool; -op <=(char, String) -> bool; - -op +(String, char) -> String; -op -(String, char) -> String; -op ==(String, char) -> bool; -op !=(String, char) -> bool; -op >(String, char) -> bool; -op >=(String, char) -> bool; -op <(String, char) -> bool; -op <=(String, char) -> bool; - -op +((), String) -> String; -op ==((), String) -> bool; -op !=((), String) -> bool; -op >((), String) -> bool; -op >=((), String) -> bool; -op <((), String) -> bool; -op <=((), String) -> bool; - -op +(String, ()) -> String; -op ==(String, ()) -> bool; -op !=(String, ()) -> bool; -op >(String, ()) -> bool; -op >=(String, ()) -> bool; -op <(String, ()) -> bool; -op <=(String, ()) -> bool; - -op +(Blob, Blob) -> Blob; -op +(Blob, char) -> Blob; -op ==(Blob, Blob) -> bool; -op !=(Blob, Blob) -> bool; - - -op ==(Range, RangeInclusive) -> bool; -op !=(Range, RangeInclusive) -> bool; - -op ==(RangeInclusive, Range) -> bool; -op !=(RangeInclusive, Range) -> bool; - -op ==(Range, Range) -> bool; -op !=(Range, Range) -> bool; - -op ==(RangeInclusive, RangeInclusive) -> bool; -op !=(RangeInclusive, RangeInclusive) -> bool; - -op ==(?, ?) -> bool; -op !=(?, ?) -> bool; -op >(?, ?) -> bool; -op >=(?, ?) -> bool; -op <(?, ?) -> bool; -op <=(?, ?) -> bool; - - -op &=(bool, bool); -op |=(bool, bool); - -op +=(int, int); -op -=(int, int); -op *=(int, int); -op /=(int, int); -op %=(int, int); -op **=(int, int); -op >>=(int, int); -op <<=(int, int); -op &=(int, int); -op |=(int, int); -op ^=(int, int); - -op +=(float, float); -op -=(float, float); -op *=(float, float); -op /=(float, float); -op %=(float, float); -op **=(float, float); - -op +=(float, int); -op -=(float, int); -op *=(float, int); -op /=(float, int); -op %=(float, int); -op **=(float, int); - -op +=(Decimal, Decimal); -op -=(Decimal, Decimal); -op *=(Decimal, Decimal); -op /=(Decimal, Decimal); -op %=(Decimal, Decimal); -op **=(Decimal, Decimal); - -op +=(Decimal, int); -op -=(Decimal, int); -op *=(Decimal, int); -op /=(Decimal, int); -op %=(Decimal, int); -op **=(Decimal, int); - -op +=(String, String); -op -=(String, String); -op +=(String, char); -op -=(String, char); -op +=(char, String); -op +=(char, char); - -op +=(Array, Array); -op +=(Array, ?); - -op +=(Blob, Blob); -op +=(Blob, int); -op +=(Blob, char); -op +=(Blob, String); - -op in(?, Array) -> bool; -op in(String, String) -> bool; -op in(char, String) -> bool; -op in(int, Range) -> bool; -op in(int, RangeInclusive) -> bool; -op in(String, Map) -> bool; -op in(int, Blob) -> bool; diff --git a/examples/definitions/.rhai/definitions/__builtin__.d.rhai b/examples/definitions/.rhai/definitions/__builtin__.d.rhai deleted file mode 100644 index 881c15821..000000000 --- a/examples/definitions/.rhai/definitions/__builtin__.d.rhai +++ /dev/null @@ -1,261 +0,0 @@ -module static; - -/// Display any data to the standard output. -/// -/// # Example -/// -/// ```rhai -/// let answer = 42; -/// -/// print(`The Answer is ${answer}`); -/// ``` -fn print(data: ?); - -/// Display any data to the standard output in debug format. -/// -/// # Example -/// -/// ```rhai -/// let answer = 42; -/// -/// debug(answer); -/// ``` -fn debug(data: ?); - -/// Get the type of a value. -/// -/// # Example -/// -/// ```rhai -/// let x = "hello, world!"; -/// -/// print(x.type_of()); // prints "string" -/// ``` -fn type_of(data: ?) -> String; - -/// Create a function pointer to a named function. -/// -/// If the specified name is not a valid function name, an error is raised. -/// -/// # Example -/// -/// ```rhai -/// let f = Fn("foo"); // function pointer to 'foo' -/// -/// f.call(42); // call: foo(42) -/// ``` -fn Fn(fn_name: String) -> FnPtr; - -/// Call a function pointed to by a function pointer, -/// passing following arguments to the function call. -/// -/// If an appropriate function is not found, an error is raised. -/// -/// # Example -/// -/// ```rhai -/// let f = Fn("foo"); // function pointer to 'foo' -/// -/// f.call(1, 2, 3); // call: foo(1, 2, 3) -/// ``` -fn call(fn_ptr: FnPtr, ...args: ?) -> ?; - -/// Call a function pointed to by a function pointer, binding the `this` pointer -/// to the object of the method call, and passing on following arguments to the function call. -/// -/// If an appropriate function is not found, an error is raised. -/// -/// # Example -/// -/// ```rhai -/// fn add(x) { -/// this + x -/// } -/// -/// let f = Fn("add"); // function pointer to 'add' -/// -/// let x = 41; -/// -/// let r = x.call(f, 1); // call: add(1) with 'this' = 'x' -/// -/// print(r); // prints 42 -/// ``` -fn call(obj: ?, fn_ptr: FnPtr, ...args: ?) -> ?; - -/// Curry a number of arguments into a function pointer and return it as a new function pointer. -/// -/// # Example -/// -/// ```rhai -/// fn foo(x, y, z) { -/// x + y + z -/// } -/// -/// let f = Fn("foo"); -/// -/// let g = f.curry(1, 2); // curried arguments: 1, 2 -/// -/// g.call(3); // call: foo(1, 2, 3) -/// ``` -fn curry(fn_ptr: FnPtr, ...args: ?) -> FnPtr; - -/// Return `true` if a script-defined function exists with a specified name and -/// number of parameters. -/// -/// # Example -/// -/// ```rhai -/// fn foo(x) { } -/// -/// print(is_def_fn("foo", 1)); // prints true -/// print(is_def_fn("foo", 2)); // prints false -/// print(is_def_fn("foo", 0)); // prints false -/// print(is_def_fn("bar", 1)); // prints false -/// ``` -fn is_def_fn(fn_name: String, num_params: int) -> bool; - -/// Return `true` if a variable matching a specified name is defined. -/// -/// # Example -/// -/// ```rhai -/// let x = 42; -/// -/// print(is_def_var("x")); // prints true -/// print(is_def_var("foo")); // prints false -/// -/// { -/// let y = 1; -/// print(is_def_var("y")); // prints true -/// } -/// -/// print(is_def_var("y")); // prints false -/// ``` -fn is_def_var(var_name: String) -> bool; - -/// Return `true` if the variable is shared. -/// -/// # Example -/// -/// ```rhai -/// let x = 42; -/// -/// print(is_shared(x)); // prints false -/// -/// let f = || x; // capture 'x', making it shared -/// -/// print(is_shared(x)); // prints true -/// ``` -fn is_shared(variable: ?) -> bool; - -/// Evaluate a text script within the current scope. -/// -/// # Example -/// -/// ```rhai -/// let x = 42; -/// -/// eval("let y = x; x = 123;"); -/// -/// print(x); // prints 123 -/// print(y); // prints 42 -/// ``` -fn eval(script: String) -> ?; - -/// Return `true` if the string contains another string. -/// -/// This function also drives the `in` operator. -/// -/// # Example -/// -/// ```rhai -/// let x = "hello world!"; -/// -/// // The 'in' operator calls 'contains' in the background -/// if "world" in x { -/// print("found!"); -/// } -/// ``` -fn contains(string: String, find: String) -> bool; - -/// Return `true` if the string contains a character. -/// -/// This function also drives the `in` operator. -/// -/// # Example -/// -/// ```rhai -/// let x = "hello world!"; -/// -/// // The 'in' operator calls 'contains' in the background -/// if 'w' in x { -/// print("found!"); -/// } -/// ``` -fn contains(string: String, ch: char) -> bool; - -/// Return `true` if a value falls within the exclusive range. -/// -/// This function also drives the `in` operator. -/// -/// # Example -/// -/// ```rhai -/// let r = 1..100; -/// -/// // The 'in' operator calls 'contains' in the background -/// if 42 in r { -/// print("found!"); -/// } -/// ``` -fn contains(range: Range, value: int) -> bool; - -/// Return `true` if a value falls within the inclusive range. -/// -/// This function also drives the `in` operator. -/// -/// # Example -/// -/// ```rhai -/// let r = 1..=100; -/// -/// // The 'in' operator calls 'contains' in the background -/// if 42 in r { -/// print("found!"); -/// } -/// ``` -fn contains(range: RangeInclusive, value: int) -> bool; - -/// Return `true` if a key exists within the object map. -/// -/// This function also drives the `in` operator. -/// -/// # Example -/// -/// ```rhai -/// let m = #{a:1, b:2, c:3}; -/// -/// // The 'in' operator calls 'contains' in the background -/// if "c" in m { -/// print("found!"); -/// } -/// ``` -fn contains(map: Map, string: String) -> bool; - -/// Return `true` if a value is found within the BLOB. -/// -/// This function also drives the `in` operator. -/// -/// # Example -/// -/// ```rhai -/// let b = blob(); -/// -/// b += 1; b += 2; b += 3; b += 4; b += 5; -/// -/// // The 'in' operator calls 'contains' in the background -/// if 3 in b { -/// print("found!"); -/// } -/// ``` -fn contains(blob: Blob, value: int) -> bool; diff --git a/examples/definitions/.rhai/definitions/__scope__.d.rhai b/examples/definitions/.rhai/definitions/__scope__.d.rhai deleted file mode 100644 index 96d874f3a..000000000 --- a/examples/definitions/.rhai/definitions/__scope__.d.rhai +++ /dev/null @@ -1,5 +0,0 @@ -module static; - -let hello_there: string; - -const HELLO: string; \ No newline at end of file diff --git a/examples/definitions/.rhai/definitions/__static__.d.rhai b/examples/definitions/.rhai/definitions/__static__.d.rhai deleted file mode 100644 index 9a1e2f7af..000000000 --- a/examples/definitions/.rhai/definitions/__static__.d.rhai +++ /dev/null @@ -1,5849 +0,0 @@ -module static; - -op minus(int, int) -> int; - -op !(bool) -> bool; - -/// Return `true` if two arrays are not-equal (i.e. any element not equal or not in the same order). -/// -/// The operator `==` is used to compare elements and must be defined, -/// otherwise `false` is assumed. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 5]; -/// let y = [1, 2, 3, 4, 5]; -/// let z = [1, 2, 3, 4]; -/// -/// print(x != y); // prints false -/// -/// print(x != z); // prints true -/// ``` -op !=(Array, Array) -> bool; - -/// Return `true` if two object maps are not equal (i.e. at least one property value is not equal). -/// -/// The operator `==` is used to compare property values and must be defined, -/// otherwise `false` is assumed. -/// -/// # Example -/// -/// ```rhai -/// let m1 = #{a:1, b:2, c:3}; -/// let m2 = #{a:1, b:2, c:3}; -/// let m3 = #{a:1, c:3}; -/// -/// print(m1 != m2); // prints false -/// -/// print(m1 != m3); // prints true -/// ``` -op !=(Map, Map) -> bool; - -/// Return `true` if two timestamps are not equal. -op !=(Instant, Instant) -> bool; - -op !=(int, f32) -> bool; - -op !=(int, float) -> bool; - -op !=(f32, int) -> bool; - -op !=(f32, f32) -> bool; - -op !=(float, int) -> bool; - -op !=(i128, i128) -> bool; - -op !=(i16, i16) -> bool; - -op !=(i32, i32) -> bool; - -op !=(i8, i8) -> bool; - -op !=(u128, u128) -> bool; - -op !=(u16, u16) -> bool; - -op !=(u32, u32) -> bool; - -op !=(u64, u64) -> bool; - -op !=(u8, u8) -> bool; - -op %(int, f32) -> f32; - -op %(f32, int) -> f32; - -op %(f32, f32) -> f32; - -op %(i128, i128) -> i128; - -op %(i16, i16) -> i16; - -op %(i32, i32) -> i32; - -op %(i8, i8) -> i8; - -op %(u128, u128) -> u128; - -op %(u16, u16) -> u16; - -op %(u32, u32) -> u32; - -op %(u64, u64) -> u64; - -op %(u8, u8) -> u8; - -op &(i128, i128) -> i128; - -op &(i16, i16) -> i16; - -op &(i32, i32) -> i32; - -op &(i8, i8) -> i8; - -op &(u128, u128) -> u128; - -op &(u16, u16) -> u16; - -op &(u32, u32) -> u32; - -op &(u64, u64) -> u64; - -op &(u8, u8) -> u8; - -op *(int, f32) -> f32; - -op *(f32, int) -> f32; - -op *(f32, f32) -> f32; - -op *(i128, i128) -> i128; - -op *(i16, i16) -> i16; - -op *(i32, i32) -> i32; - -op *(i8, i8) -> i8; - -op *(u128, u128) -> u128; - -op *(u16, u16) -> u16; - -op *(u32, u32) -> u32; - -op *(u64, u64) -> u64; - -op *(u8, u8) -> u8; - -op **(f32, int) -> f32; - -op **(f32, f32) -> f32; - -op **(i128, int) -> i128; - -op **(i16, int) -> i16; - -op **(i32, int) -> i32; - -op **(i8, int) -> i8; - -op **(u128, int) -> u128; - -op **(u16, int) -> u16; - -op **(u32, int) -> u32; - -op **(u64, int) -> u64; - -op **(u8, int) -> u8; - -op +(int) -> int; - -op +(f32) -> f32; - -op +(float) -> float; - -op +(i128) -> i128; - -op +(i16) -> i16; - -op +(i32) -> i32; - -op +(i8) -> i8; - -op +((), String) -> String; - -/// Combine two arrays into a new array and return it. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3]; -/// let y = [true, 'x']; -/// -/// print(x + y); // prints "[1, 2, 3, true, 'x']" -/// -/// print(x); // prints "[1, 2, 3" -/// ``` -op +(Array, Array) -> Array; - -op +(char, String) -> String; - -op +(?, String) -> String; - -/// Make a copy of the object map, add all property values of another object map -/// (existing property values of the same names are replaced), then returning it. -/// -/// # Example -/// -/// ```rhai -/// let m = #{a:1, b:2, c:3}; -/// let n = #{a: 42, d:0}; -/// -/// print(m + n); // prints "#{a:42, b:2, c:3, d:0}" -/// -/// print(m); // prints "#{a:1, b:2, c:3}" -/// ``` -op +(Map, Map) -> Map; - -op +(String, String) -> String; - -op +(String, char) -> String; - -op +(String, ?) -> String; - -op +(String, Blob) -> String; - -op +(String, ()) -> String; - -/// Add the specified number of `seconds` to the timestamp and return it as a new timestamp. -op +(Instant, float) -> Instant; - -/// Add the specified number of `seconds` to the timestamp and return it as a new timestamp. -op +(Instant, int) -> Instant; - -op +(Blob, String) -> String; - -op +(int, f32) -> f32; - -op +(f32, int) -> f32; - -op +(f32, f32) -> f32; - -op +(i128, i128) -> i128; - -op +(i16, i16) -> i16; - -op +(i32, i32) -> i32; - -op +(i8, i8) -> i8; - -op +(u128, u128) -> u128; - -op +(u16, u16) -> u16; - -op +(u32, u32) -> u32; - -op +(u64, u64) -> u64; - -op +(u8, u8) -> u8; - -/// Add all property values of another object map into the object map. -/// Existing property values of the same names are replaced. -/// -/// # Example -/// -/// ```rhai -/// let m = #{a:1, b:2, c:3}; -/// let n = #{a: 42, d:0}; -/// -/// m.mixin(n); -/// -/// print(m); // prints "#{a:42, b:2, c:3, d:0}" -/// ``` -op +=(Map, Map) -> (); - -op +=(String, String) -> (); - -op +=(String, char) -> (); - -op +=(String, ()) -> (); - -op +=(String, ?) -> (); - -op +=(String, Blob) -> (); - -/// Add the specified number of `seconds` to the timestamp. -op +=(Instant, float) -> (); - -/// Add the specified number of `seconds` to the timestamp. -op +=(Instant, int) -> (); - -op -(int) -> int; - -op -(f32) -> f32; - -op -(float) -> float; - -op -(i128) -> i128; - -op -(i16) -> i16; - -op -(i32) -> i32; - -op -(i8) -> i8; - -/// Return the number of seconds between two timestamps. -op -(Instant, Instant) -> RhaiResult; - -/// Subtract the specified number of `seconds` from the timestamp and return it as a new timestamp. -op -(Instant, float) -> Instant; - -/// Subtract the specified number of `seconds` from the timestamp and return it as a new timestamp. -op -(Instant, int) -> Instant; - -op -(int, f32) -> f32; - -op -(f32, int) -> f32; - -op -(f32, f32) -> f32; - -op -(i128, i128) -> i128; - -op -(i16, i16) -> i16; - -op -(i32, i32) -> i32; - -op -(i8, i8) -> i8; - -op -(u128, u128) -> u128; - -op -(u16, u16) -> u16; - -op -(u32, u32) -> u32; - -op -(u64, u64) -> u64; - -op -(u8, u8) -> u8; - -/// Subtract the specified number of `seconds` from the timestamp. -op -=(Instant, float) -> (); - -/// Subtract the specified number of `seconds` from the timestamp. -op -=(Instant, int) -> (); - -op /(int, f32) -> f32; - -op /(f32, int) -> f32; - -op /(f32, f32) -> f32; - -op /(i128, i128) -> i128; - -op /(i16, i16) -> i16; - -op /(i32, i32) -> i32; - -op /(i8, i8) -> i8; - -op /(u128, u128) -> u128; - -op /(u16, u16) -> u16; - -op /(u32, u32) -> u32; - -op /(u64, u64) -> u64; - -op /(u8, u8) -> u8; - -/// Return `true` if the first timestamp is earlier than the second. -op <(Instant, Instant) -> bool; - -op <(int, f32) -> bool; - -op <(int, float) -> bool; - -op <(f32, int) -> bool; - -op <(f32, f32) -> bool; - -op <(float, int) -> bool; - -op <(i128, i128) -> bool; - -op <(i16, i16) -> bool; - -op <(i32, i32) -> bool; - -op <(i8, i8) -> bool; - -op <(u128, u128) -> bool; - -op <(u16, u16) -> bool; - -op <(u32, u32) -> bool; - -op <(u64, u64) -> bool; - -op <(u8, u8) -> bool; - -op <<(i128, int) -> i128; - -op <<(i16, int) -> i16; - -op <<(i32, int) -> i32; - -op <<(i8, int) -> i8; - -op <<(u128, int) -> u128; - -op <<(u16, int) -> u16; - -op <<(u32, int) -> u32; - -op <<(u64, int) -> u64; - -op <<(u8, int) -> u8; - -/// Return `true` if the first timestamp is earlier than or equals to the second. -op <=(Instant, Instant) -> bool; - -op <=(int, f32) -> bool; - -op <=(int, float) -> bool; - -op <=(f32, int) -> bool; - -op <=(f32, f32) -> bool; - -op <=(float, int) -> bool; - -op <=(i128, i128) -> bool; - -op <=(i16, i16) -> bool; - -op <=(i32, i32) -> bool; - -op <=(i8, i8) -> bool; - -op <=(u128, u128) -> bool; - -op <=(u16, u16) -> bool; - -op <=(u32, u32) -> bool; - -op <=(u64, u64) -> bool; - -op <=(u8, u8) -> bool; - -/// Return `true` if two arrays are equal (i.e. all elements are equal and in the same order). -/// -/// The operator `==` is used to compare elements and must be defined, -/// otherwise `false` is assumed. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 5]; -/// let y = [1, 2, 3, 4, 5]; -/// let z = [1, 2, 3, 4]; -/// -/// print(x == y); // prints true -/// -/// print(x == z); // prints false -/// ``` -op ==(Array, Array) -> bool; - -/// Return `true` if two object maps are equal (i.e. all property values are equal). -/// -/// The operator `==` is used to compare property values and must be defined, -/// otherwise `false` is assumed. -/// -/// # Example -/// -/// ```rhai -/// let m1 = #{a:1, b:2, c:3}; -/// let m2 = #{a:1, b:2, c:3}; -/// let m3 = #{a:1, c:3}; -/// -/// print(m1 == m2); // prints true -/// -/// print(m1 == m3); // prints false -/// ``` -op ==(Map, Map) -> bool; - -/// Return `true` if two timestamps are equal. -op ==(Instant, Instant) -> bool; - -op ==(int, f32) -> bool; - -op ==(int, float) -> bool; - -op ==(f32, int) -> bool; - -op ==(f32, f32) -> bool; - -op ==(float, int) -> bool; - -op ==(i128, i128) -> bool; - -op ==(i16, i16) -> bool; - -op ==(i32, i32) -> bool; - -op ==(i8, i8) -> bool; - -op ==(u128, u128) -> bool; - -op ==(u16, u16) -> bool; - -op ==(u32, u32) -> bool; - -op ==(u64, u64) -> bool; - -op ==(u8, u8) -> bool; - -/// Return `true` if the first timestamp is later than the second. -op >(Instant, Instant) -> bool; - -op >(int, f32) -> bool; - -op >(int, float) -> bool; - -op >(f32, int) -> bool; - -op >(f32, f32) -> bool; - -op >(float, int) -> bool; - -op >(i128, i128) -> bool; - -op >(i16, i16) -> bool; - -op >(i32, i32) -> bool; - -op >(i8, i8) -> bool; - -op >(u128, u128) -> bool; - -op >(u16, u16) -> bool; - -op >(u32, u32) -> bool; - -op >(u64, u64) -> bool; - -op >(u8, u8) -> bool; - -/// Return `true` if the first timestamp is later than or equals to the second. -op >=(Instant, Instant) -> bool; - -op >=(int, f32) -> bool; - -op >=(int, float) -> bool; - -op >=(f32, int) -> bool; - -op >=(f32, f32) -> bool; - -op >=(float, int) -> bool; - -op >=(i128, i128) -> bool; - -op >=(i16, i16) -> bool; - -op >=(i32, i32) -> bool; - -op >=(i8, i8) -> bool; - -op >=(u128, u128) -> bool; - -op >=(u16, u16) -> bool; - -op >=(u32, u32) -> bool; - -op >=(u64, u64) -> bool; - -op >=(u8, u8) -> bool; - -op >>(i128, int) -> i128; - -op >>(i16, int) -> i16; - -op >>(i32, int) -> i32; - -op >>(i8, int) -> i8; - -op >>(u128, int) -> u128; - -op >>(u16, int) -> u16; - -op >>(u32, int) -> u32; - -op >>(u64, int) -> u64; - -op >>(u8, int) -> u8; - -/// Return the natural number _e_. -fn E() -> float; - -/// Return the number π. -fn PI() -> float; - -op ^(i128, i128) -> i128; - -op ^(i16, i16) -> i16; - -op ^(i32, i32) -> i32; - -op ^(i8, i8) -> i8; - -op ^(u128, u128) -> u128; - -op ^(u16, u16) -> u16; - -op ^(u32, u32) -> u32; - -op ^(u64, u64) -> u64; - -op ^(u8, u8) -> u8; - -/// Return the absolute value of the number. -fn abs(x: int) -> int; - -/// Return the absolute value of the floating-point number. -fn abs(x: f32) -> f32; - -/// Return the absolute value of the floating-point number. -fn abs(x: float) -> float; - -/// Return the absolute value of the number. -fn abs(x: i128) -> i128; - -/// Return the absolute value of the number. -fn abs(x: i16) -> i16; - -/// Return the absolute value of the number. -fn abs(x: i32) -> i32; - -/// Return the absolute value of the number. -fn abs(x: i8) -> i8; - -/// Return the arc-cosine of the floating-point number, in radians. -fn acos(x: float) -> float; - -/// Return the arc-hyperbolic-cosine of the floating-point number, in radians. -fn acosh(x: float) -> float; - -/// Return `true` if all elements in the array return `true` when applied a function named by `filter`. -/// -/// # Function Parameters -/// -/// A function with the same name as the value of `filter` must exist taking these parameters: -/// -/// * `element`: copy of array element -/// * `index` _(optional)_: current index in the array -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 5]; -/// -/// print(x.all(|v| v > 3)); // prints false -/// -/// print(x.all(|v| v > 1)); // prints true -/// -/// print(x.all(|v, i| i > v)); // prints false -/// ``` -fn all(array: Array, filter: String) -> bool; - -/// Return `true` if all elements in the array return `true` when applied the `filter` function. -/// -/// # Function Parameters -/// -/// * `element`: copy of array element -/// * `index` _(optional)_: current index in the array -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 5]; -/// -/// print(x.all(|v| v > 3)); // prints false -/// -/// print(x.all(|v| v > 1)); // prints true -/// -/// print(x.all(|v, i| i > v)); // prints false -/// ``` -fn all(array: Array, filter: FnPtr) -> bool; - -/// Add all the elements of another array to the end of the array. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3]; -/// let y = [true, 'x']; -/// -/// x.append(y); -/// -/// print(x); // prints "[1, 2, 3, true, 'x']" -/// ``` -fn append(array: Array, new_array: Array) -> (); - -/// Add another BLOB to the end of the BLOB. -/// -/// # Example -/// -/// ```rhai -/// let b1 = blob(5, 0x42); -/// let b2 = blob(3, 0x11); -/// -/// b1.push(b2); -/// -/// print(b1); // prints "[4242424242111111]" -/// ``` -fn append(blob1: Blob, blob2: Blob) -> (); - -/// Add a character (as UTF-8 encoded byte-stream) to the end of the BLOB -/// -/// # Example -/// -/// ```rhai -/// let b = blob(5, 0x42); -/// -/// b.append('!'); -/// -/// print(b); // prints "[424242424221]" -/// ``` -fn append(blob: Blob, character: char) -> (); - -/// Add a string (as UTF-8 encoded byte-stream) to the end of the BLOB -/// -/// # Example -/// -/// ```rhai -/// let b = blob(5, 0x42); -/// -/// b.append("hello"); -/// -/// print(b); // prints "[424242424268656c 6c6f]" -/// ``` -fn append(blob: Blob, string: String) -> (); - -/// Add a new byte `value` to the end of the BLOB. -/// -/// Only the lower 8 bits of the `value` are used; all other bits are ignored. -/// -/// # Example -/// -/// ```rhai -/// let b = blob(); -/// -/// b.push(0x42); -/// -/// print(b); // prints "[42]" -/// ``` -fn append(blob: Blob, value: int) -> (); - -fn append(string: String, item: ?) -> (); - -fn append(string: String, utf8: Blob) -> (); - -/// Convert the BLOB into a string. -/// -/// The byte stream must be valid UTF-8, otherwise an error is raised. -/// -/// # Example -/// -/// ```rhai -/// let b = blob(5, 0x42); -/// -/// let x = b.as_string(); -/// -/// print(x); // prints "FFFFF" -/// ``` -fn as_string(blob: Blob) -> String; - -/// Return the arc-sine of the floating-point number, in radians. -fn asin(x: float) -> float; - -/// Return the arc-hyperbolic-sine of the floating-point number, in radians. -fn asinh(x: float) -> float; - -/// Return the arc-tangent of the floating-point number, in radians. -fn atan(x: float) -> float; - -/// Return the arc-tangent of the floating-point numbers `x` and `y`, in radians. -fn atan(x: float, y: float) -> float; - -/// Return the arc-hyperbolic-tangent of the floating-point number, in radians. -fn atanh(x: float) -> float; - -/// Return an iterator over all the bits in the number. -/// -/// # Example -/// -/// ```rhai -/// let x = 123456; -/// -/// for bit in x.bits() { -/// print(bit); -/// } -/// ``` -fn bits(value: int) -> Iterator; - -/// Return an iterator over the bits in the number starting from the specified `start` position. -/// -/// If `start` < 0, position counts from the MSB (Most Significant Bit)>. -/// -/// # Example -/// -/// ```rhai -/// let x = 123456; -/// -/// for bit in x.bits(10) { -/// print(bit); -/// } -/// ``` -fn bits(value: int, from: int) -> Iterator; - -/// Return an iterator over an exclusive range of bits in the number. -/// -/// # Example -/// -/// ```rhai -/// let x = 123456; -/// -/// for bit in x.bits(10..24) { -/// print(bit); -/// } -/// ``` -fn bits(value: int, range: Range) -> Iterator; - -/// Return an iterator over an inclusive range of bits in the number. -/// -/// # Example -/// -/// ```rhai -/// let x = 123456; -/// -/// for bit in x.bits(10..=23) { -/// print(bit); -/// } -/// ``` -fn bits(value: int, range: RangeInclusive) -> Iterator; - -/// Return an iterator over a portion of bits in the number. -/// -/// * If `start` < 0, position counts from the MSB (Most Significant Bit)>. -/// * If `len` ≤ 0, an empty iterator is returned. -/// * If `start` position + `len` ≥ length of string, all bits of the number after the `start` position are iterated. -/// -/// # Example -/// -/// ```rhai -/// let x = 123456; -/// -/// for bit in x.bits(10, 8) { -/// print(bit); -/// } -/// ``` -fn bits(value: int, from: int, len: int) -> Iterator; - -/// Return a new, empty BLOB. -fn blob() -> Blob; - -/// Return a new BLOB of the specified length, filled with zeros. -/// -/// If `len` ≤ 0, an empty BLOB is returned. -/// -/// # Example -/// -/// ```rhai -/// let b = blob(10); -/// -/// print(b); // prints "[0000000000000000 0000]" -/// ``` -fn blob(len: int) -> Blob; - -/// Return a new BLOB of the specified length, filled with copies of the initial `value`. -/// -/// If `len` ≤ 0, an empty BLOB is returned. -/// -/// Only the lower 8 bits of the initial `value` are used; all other bits are ignored. -/// -/// # Example -/// -/// ```rhai -/// let b = blob(10, 0x42); -/// -/// print(b); // prints "[4242424242424242 4242]" -/// ``` -fn blob(len: int, value: int) -> Blob; - -/// Return the length of the string, in number of bytes used to store it in UTF-8 encoding. -/// -/// # Example -/// -/// ```rhai -/// let text = "朝には紅顔ありて夕べには白骨となる"; -/// -/// print(text.bytes); // prints 51 -/// ``` -fn bytes(string: String) -> int; - -/// Return the smallest whole number larger than or equals to the floating-point number. -fn ceiling(x: float) -> float; - -/// Return an iterator over the characters in the string. -/// -/// # Example -/// -/// ```rhai -/// for ch in "hello, world!".chars() { -/// print(ch); -/// } -/// ``` -fn chars(string: String) -> Iterator; - -/// Return an iterator over the characters in the string starting from the `start` position. -/// -/// * If `start` < 0, position counts from the end of the string (`-1` is the last character). -/// * If `start` < -length of string, position counts from the beginning of the string. -/// * If `start` ≥ length of string, an empty iterator is returned. -/// -/// # Example -/// -/// ```rhai -/// for ch in "hello, world!".chars(2) { -/// print(ch); -/// } -/// ``` -fn chars(string: String, from: int) -> Iterator; - -/// Return an iterator over an exclusive range of characters in the string. -/// -/// # Example -/// -/// ```rhai -/// for ch in "hello, world!".chars(2..5) { -/// print(ch); -/// } -/// ``` -fn chars(string: String, range: Range) -> Iterator; - -/// Return an iterator over an inclusive range of characters in the string. -/// -/// # Example -/// -/// ```rhai -/// for ch in "hello, world!".chars(2..=6) { -/// print(ch); -/// } -/// ``` -fn chars(string: String, range: RangeInclusive) -> Iterator; - -/// Return an iterator over a portion of characters in the string. -/// -/// * If `start` < 0, position counts from the end of the string (`-1` is the last character). -/// * If `start` < -length of string, position counts from the beginning of the string. -/// * If `start` ≥ length of string, an empty iterator is returned. -/// * If `len` ≤ 0, an empty iterator is returned. -/// * If `start` position + `len` ≥ length of string, all characters of the string after the `start` position are iterated. -/// -/// # Example -/// -/// ```rhai -/// for ch in "hello, world!".chars(2, 4) { -/// print(ch); -/// } -/// ``` -fn chars(string: String, start: int, len: int) -> Iterator; - -/// Cut off the head of the array, leaving a tail of the specified length. -/// -/// * If `len` ≤ 0, the array is cleared. -/// * If `len` ≥ length of array, the array is not modified. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 5]; -/// -/// x.chop(3); -/// -/// print(x); // prints "[3, 4, 5]" -/// -/// x.chop(10); -/// -/// print(x); // prints "[3, 4, 5]" -/// ``` -fn chop(array: Array, len: int) -> (); - -/// Cut off the head of the BLOB, leaving a tail of the specified length. -/// -/// * If `len` ≤ 0, the BLOB is cleared. -/// * If `len` ≥ length of BLOB, the BLOB is not modified. -/// -/// # Example -/// -/// ```rhai -/// let b = blob(); -/// -/// b += 1; b += 2; b += 3; b += 4; b += 5; -/// -/// b.chop(3); -/// -/// print(b); // prints "[030405]" -/// -/// b.chop(10); -/// -/// print(b); // prints "[030405]" -/// ``` -fn chop(blob: Blob, len: int) -> (); - -/// Clear the array. -fn clear(array: Array) -> (); - -/// Clear the BLOB. -fn clear(blob: Blob) -> (); - -/// Clear the object map. -fn clear(map: Map) -> (); - -/// Clear the string, making it empty. -fn clear(string: String) -> (); - -/// Return `true` if the array contains an element that equals `value`. -/// -/// The operator `==` is used to compare elements with `value` and must be defined, -/// otherwise `false` is assumed. -/// -/// This function also drives the `in` operator. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 5]; -/// -/// // The 'in' operator calls 'contains' in the background -/// if 4 in x { -/// print("found!"); -/// } -/// ``` -fn contains(array: Array, value: ?) -> bool; - -/// Return `true` if the BLOB contains a specified byte value. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world!"; -/// -/// print(text.contains('h')); // prints true -/// -/// print(text.contains('x')); // prints false -/// ``` -fn contains(blob: Blob, value: int) -> bool; - -/// Returns `true` if the object map contains a specified property. -/// -/// # Example -/// -/// ```rhai -/// let m = #{a: 1, b: 2, c: 3}; -/// -/// print(m.contains("b")); // prints true -/// -/// print(m.contains("x")); // prints false -/// ``` -fn contains(map: Map, property: String) -> bool; - -/// Return `true` if the range contains a specified value. -fn contains(range: ExclusiveRange, value: int) -> bool; - -/// Return `true` if the range contains a specified value. -fn contains(range: InclusiveRange, value: int) -> bool; - -/// Return `true` if the string contains a specified character. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world!"; -/// -/// print(text.contains('h')); // prints true -/// -/// print(text.contains('x')); // prints false -/// ``` -fn contains(string: String, character: char) -> bool; - -/// Return `true` if the string contains a specified string. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world!"; -/// -/// print(text.contains("hello")); // prints true -/// -/// print(text.contains("hey")); // prints false -/// ``` -fn contains(string: String, match_string: String) -> bool; - -/// Return the cosine of the floating-point number in radians. -fn cos(x: float) -> float; - -/// Return the hyperbolic cosine of the floating-point number in radians. -fn cosh(x: float) -> float; - -/// Remove all characters from the string except those within an exclusive `range`. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world!"; -/// -/// text.crop(2..8); -/// -/// print(text); // prints "llo, w" -/// ``` -fn crop(string: String, range: Range) -> (); - -/// Remove all characters from the string except those within an inclusive `range`. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world!"; -/// -/// text.crop(2..=8); -/// -/// print(text); // prints "llo, wo" -/// ``` -fn crop(string: String, range: RangeInclusive) -> (); - -/// Remove all characters from the string except until the `start` position. -/// -/// * If `start` < 0, position counts from the end of the string (`-1` is the last character). -/// * If `start` < -length of string, the string is not modified. -/// * If `start` ≥ length of string, the entire string is cleared. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world!"; -/// -/// text.crop(5); -/// -/// print(text); // prints ", world!" -/// -/// text.crop(-3); -/// -/// print(text); // prints "ld!" -/// ``` -fn crop(string: String, start: int) -> (); - -/// Remove all characters from the string except those within a range. -/// -/// * If `start` < 0, position counts from the end of the string (`-1` is the last character). -/// * If `start` < -length of string, position counts from the beginning of the string. -/// * If `start` ≥ length of string, the entire string is cleared. -/// * If `len` ≤ 0, the entire string is cleared. -/// * If `start` position + `len` ≥ length of string, only the portion of the string after the `start` position is retained. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world!"; -/// -/// text.crop(2, 8); -/// -/// print(text); // prints "llo, wor" -/// -/// text.crop(-5, 3); -/// -/// print(text); // prints ", w" -/// ``` -fn crop(string: String, start: int, len: int) -> (); - -/// Return the empty string. -op debug() -> String; - -/// Convert the array into a string. -op debug(Array) -> String; - -/// Convert the string into debug format. -op debug(char) -> String; - -/// Convert the function pointer into a string in debug format. -op debug(FnPtr) -> String; - -/// Convert the value of the `item` into a string in debug format. -op debug(?) -> String; - -/// Convert the object map into a string. -op debug(Map) -> String; - -/// Convert the value of `number` into a string. -op debug(f32) -> String; - -/// Convert the value of `number` into a string. -op debug(float) -> String; - -/// Convert the string into debug format. -op debug(String) -> String; - -/// Convert the unit into a string in debug format. -op debug(()) -> String; - -/// Convert the boolean value into a string in debug format. -op debug(bool) -> String; - -/// Remove duplicated _consecutive_ elements from the array. -/// -/// The operator `==` is used to compare elements and must be defined, -/// otherwise `false` is assumed. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 2, 2, 3, 4, 3, 3, 2, 1]; -/// -/// x.dedup(); -/// -/// print(x); // prints "[1, 2, 3, 4, 3, 2, 1]" -/// ``` -fn dedup(array: Array) -> (); - -/// Remove duplicated _consecutive_ elements from the array that return `true` when applied a -/// function named by `comparer`. -/// -/// No element is removed if the correct `comparer` function does not exist. -/// -/// # Function Parameters -/// -/// * `element1`: copy of the current array element to compare -/// * `element2`: copy of the next array element to compare -/// -/// ## Return Value -/// -/// `true` if `element1 == element2`, otherwise `false`. -/// -/// # Example -/// -/// ```rhai -/// fn declining(a, b) { a >= b } -/// -/// let x = [1, 2, 2, 2, 3, 1, 2, 3, 4, 3, 3, 2, 1]; -/// -/// x.dedup("declining"); -/// -/// print(x); // prints "[1, 2, 3, 4]" -/// ``` -fn dedup(array: Array, comparer: String) -> (); - -/// Remove duplicated _consecutive_ elements from the array that return `true` when applied the -/// `comparer` function. -/// -/// No element is removed if the correct `comparer` function does not exist. -/// -/// # Function Parameters -/// -/// * `element1`: copy of the current array element to compare -/// * `element2`: copy of the next array element to compare -/// -/// ## Return Value -/// -/// `true` if `element1 == element2`, otherwise `false`. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 2, 2, 3, 1, 2, 3, 4, 3, 3, 2, 1]; -/// -/// x.dedup(|a, b| a >= b); -/// -/// print(x); // prints "[1, 2, 3, 4]" -/// ``` -fn dedup(array: Array, comparer: FnPtr) -> (); - -/// Remove all elements in the array that returns `true` when applied a function named by `filter` -/// and return them as a new array. -/// -/// # Function Parameters -/// -/// A function with the same name as the value of `filter` must exist taking these parameters: -/// -/// * `element`: copy of array element -/// * `index` _(optional)_: current index in the array -/// -/// # Example -/// -/// ```rhai -/// fn small(x) { x < 3 } -/// -/// fn screen(x, i) { x + i > 5 } -/// -/// let x = [1, 2, 3, 4, 5]; -/// -/// let y = x.drain("small"); -/// -/// print(x); // prints "[3, 4, 5]" -/// -/// print(y); // prints "[1, 2]" -/// -/// let z = x.drain("screen"); -/// -/// print(x); // prints "[3, 4]" -/// -/// print(z); // prints "[5]" -/// ``` -fn drain(array: Array, filter: String) -> Array; - -/// Remove all elements in the array that returns `true` when applied the `filter` function and -/// return them as a new array. -/// -/// # Function Parameters -/// -/// * `element`: copy of array element -/// * `index` _(optional)_: current index in the array -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 5]; -/// -/// let y = x.drain(|v| v < 3); -/// -/// print(x); // prints "[3, 4, 5]" -/// -/// print(y); // prints "[1, 2]" -/// -/// let z = x.drain(|v, i| v + i > 5); -/// -/// print(x); // prints "[3, 4]" -/// -/// print(z); // prints "[5]" -/// ``` -fn drain(array: Array, filter: FnPtr) -> Array; - -/// Remove all elements in the array within an exclusive `range` and return them as a new array. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 5]; -/// -/// let y = x.drain(1..3); -/// -/// print(x); // prints "[1, 4, 5]" -/// -/// print(y); // prints "[2, 3]" -/// -/// let z = x.drain(2..3); -/// -/// print(x); // prints "[1, 4]" -/// -/// print(z); // prints "[5]" -/// ``` -fn drain(array: Array, range: Range) -> Array; - -/// Remove all elements in the array within an inclusive `range` and return them as a new array. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 5]; -/// -/// let y = x.drain(1..=2); -/// -/// print(x); // prints "[1, 4, 5]" -/// -/// print(y); // prints "[2, 3]" -/// -/// let z = x.drain(2..=2); -/// -/// print(x); // prints "[1, 4]" -/// -/// print(z); // prints "[5]" -/// ``` -fn drain(array: Array, range: RangeInclusive) -> Array; - -/// Remove all bytes in the BLOB within an exclusive `range` and return them as a new BLOB. -/// -/// # Example -/// -/// ```rhai -/// let b1 = blob(); -/// -/// b1 += 1; b1 += 2; b1 += 3; b1 += 4; b1 += 5; -/// -/// let b2 = b1.drain(1..3); -/// -/// print(b1); // prints "[010405]" -/// -/// print(b2); // prints "[0203]" -/// -/// let b3 = b1.drain(2..3); -/// -/// print(b1); // prints "[0104]" -/// -/// print(b3); // prints "[05]" -/// ``` -fn drain(blob: Blob, range: Range) -> Blob; - -/// Remove all bytes in the BLOB within an inclusive `range` and return them as a new BLOB. -/// -/// # Example -/// -/// ```rhai -/// let b1 = blob(); -/// -/// b1 += 1; b1 += 2; b1 += 3; b1 += 4; b1 += 5; -/// -/// let b2 = b1.drain(1..=2); -/// -/// print(b1); // prints "[010405]" -/// -/// print(b2); // prints "[0203]" -/// -/// let b3 = b1.drain(2..=2); -/// -/// print(b1); // prints "[0104]" -/// -/// print(b3); // prints "[05]" -/// ``` -fn drain(blob: Blob, range: RangeInclusive) -> Blob; - -/// Remove all elements within a portion of the array and return them as a new array. -/// -/// * If `start` < 0, position counts from the end of the array (`-1` is the last element). -/// * If `start` < -length of array, position counts from the beginning of the array. -/// * If `start` ≥ length of array, no element is removed and an empty array is returned. -/// * If `len` ≤ 0, no element is removed and an empty array is returned. -/// * If `start` position + `len` ≥ length of array, entire portion of the array after the `start` position is removed and returned. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 5]; -/// -/// let y = x.drain(1, 2); -/// -/// print(x); // prints "[1, 4, 5]" -/// -/// print(y); // prints "[2, 3]" -/// -/// let z = x.drain(-1, 1); -/// -/// print(x); // prints "[1, 4]" -/// -/// print(z); // prints "[5]" -/// ``` -fn drain(array: Array, start: int, len: int) -> Array; - -/// Remove all bytes within a portion of the BLOB and return them as a new BLOB. -/// -/// * If `start` < 0, position counts from the end of the BLOB (`-1` is the last byte). -/// * If `start` < -length of BLOB, position counts from the beginning of the BLOB. -/// * If `start` ≥ length of BLOB, nothing is removed and an empty BLOB is returned. -/// * If `len` ≤ 0, nothing is removed and an empty BLOB is returned. -/// * If `start` position + `len` ≥ length of BLOB, entire portion of the BLOB after the `start` position is removed and returned. -/// -/// # Example -/// -/// ```rhai -/// let b1 = blob(); -/// -/// b1 += 1; b1 += 2; b1 += 3; b1 += 4; b1 += 5; -/// -/// let b2 = b1.drain(1, 2); -/// -/// print(b1); // prints "[010405]" -/// -/// print(b2); // prints "[0203]" -/// -/// let b3 = b1.drain(-1, 1); -/// -/// print(b3); // prints "[0104]" -/// -/// print(z); // prints "[5]" -/// ``` -fn drain(blob: Blob, start: int, len: int) -> Blob; - -/// Return the number of seconds between the current system time and the timestamp. -/// -/// # Example -/// -/// ```rhai -/// let now = timestamp(); -/// -/// sleep(10.0); // sleep for 10 seconds -/// -/// print(now.elapsed); // prints 10.??? -/// ``` -fn elapsed(timestamp: Instant) -> RhaiResult; - -/// Return the end of the exclusive range. -fn end(range: ExclusiveRange) -> int; - -/// Return the end of the inclusive range. -fn end(range: InclusiveRange) -> int; - -/// Return `true` if the string ends with a specified string. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world!"; -/// -/// print(text.ends_with("world!")); // prints true -/// -/// print(text.ends_with("hello")); // prints false -/// ``` -fn ends_with(string: String, match_string: String) -> bool; - -/// Return the exponential of the floating-point number. -fn exp(x: float) -> float; - -/// Copy an exclusive range of the array and return it as a new array. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 5]; -/// -/// print(x.extract(1..3)); // prints "[2, 3]" -/// -/// print(x); // prints "[1, 2, 3, 4, 5]" -/// ``` -fn extract(array: Array, range: Range) -> Array; - -/// Copy an inclusive range of the array and return it as a new array. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 5]; -/// -/// print(x.extract(1..=3)); // prints "[2, 3, 4]" -/// -/// print(x); // prints "[1, 2, 3, 4, 5]" -/// ``` -fn extract(array: Array, range: RangeInclusive) -> Array; - -/// Copy a portion of the array beginning at the `start` position till the end and return it as -/// a new array. -/// -/// * If `start` < 0, position counts from the end of the array (`-1` is the last element). -/// * If `start` < -length of array, the entire array is copied and returned. -/// * If `start` ≥ length of array, an empty array is returned. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 5]; -/// -/// print(x.extract(2)); // prints "[3, 4, 5]" -/// -/// print(x.extract(-3)); // prints "[3, 4, 5]" -/// -/// print(x); // prints "[1, 2, 3, 4, 5]" -/// ``` -fn extract(array: Array, start: int) -> Array; - -/// Copy an exclusive `range` of the BLOB and return it as a new BLOB. -/// -/// # Example -/// -/// ```rhai -/// let b = blob(); -/// -/// b += 1; b += 2; b += 3; b += 4; b += 5; -/// -/// print(b.extract(1..3)); // prints "[0203]" -/// -/// print(b); // prints "[0102030405]" -/// ``` -fn extract(blob: Blob, range: Range) -> Blob; - -/// Copy an inclusive `range` of the BLOB and return it as a new BLOB. -/// -/// # Example -/// -/// ```rhai -/// let b = blob(); -/// -/// b += 1; b += 2; b += 3; b += 4; b += 5; -/// -/// print(b.extract(1..=3)); // prints "[020304]" -/// -/// print(b); // prints "[0102030405]" -/// ``` -fn extract(blob: Blob, range: RangeInclusive) -> Blob; - -/// Copy a portion of the BLOB beginning at the `start` position till the end and return it as -/// a new BLOB. -/// -/// * If `start` < 0, position counts from the end of the BLOB (`-1` is the last byte). -/// * If `start` < -length of BLOB, the entire BLOB is copied and returned. -/// * If `start` ≥ length of BLOB, an empty BLOB is returned. -/// -/// # Example -/// -/// ```rhai -/// let b = blob(); -/// -/// b += 1; b += 2; b += 3; b += 4; b += 5; -/// -/// print(b.extract(2)); // prints "[030405]" -/// -/// print(b.extract(-3)); // prints "[030405]" -/// -/// print(b); // prints "[0102030405]" -/// ``` -fn extract(blob: Blob, start: int) -> Blob; - -/// Copy a portion of the array and return it as a new array. -/// -/// * If `start` < 0, position counts from the end of the array (`-1` is the last element). -/// * If `start` < -length of array, position counts from the beginning of the array. -/// * If `start` ≥ length of array, an empty array is returned. -/// * If `len` ≤ 0, an empty array is returned. -/// * If `start` position + `len` ≥ length of array, entire portion of the array after the `start` position is copied and returned. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 5]; -/// -/// print(x.extract(1, 3)); // prints "[2, 3, 4]" -/// -/// print(x.extract(-3, 2)); // prints "[3, 4]" -/// -/// print(x); // prints "[1, 2, 3, 4, 5]" -/// ``` -fn extract(array: Array, start: int, len: int) -> Array; - -/// Copy a portion of the BLOB and return it as a new BLOB. -/// -/// * If `start` < 0, position counts from the end of the BLOB (`-1` is the last byte). -/// * If `start` < -length of BLOB, position counts from the beginning of the BLOB. -/// * If `start` ≥ length of BLOB, an empty BLOB is returned. -/// * If `len` ≤ 0, an empty BLOB is returned. -/// * If `start` position + `len` ≥ length of BLOB, entire portion of the BLOB after the `start` position is copied and returned. -/// -/// # Example -/// -/// ```rhai -/// let b = blob(); -/// -/// b += 1; b += 2; b += 3; b += 4; b += 5; -/// -/// print(b.extract(1, 3)); // prints "[020303]" -/// -/// print(b.extract(-3, 2)); // prints "[0304]" -/// -/// print(b); // prints "[0102030405]" -/// ``` -fn extract(blob: Blob, start: int, len: int) -> Blob; - -/// Add all property values of another object map into the object map. -/// Only properties that do not originally exist in the object map are added. -/// -/// # Example -/// -/// ```rhai -/// let m = #{a:1, b:2, c:3}; -/// let n = #{a: 42, d:0}; -/// -/// m.fill_with(n); -/// -/// print(m); // prints "#{a:1, b:2, c:3, d:0}" -/// ``` -fn fill_with(map: Map, map2: Map) -> (); - -/// Iterate through all the elements in the array, applying a `filter` function to each element -/// in turn, and return a copy of all elements (in order) that return `true` as a new array. -/// -/// # Function Parameters -/// -/// * `element`: copy of array element -/// * `index` _(optional)_: current index in the array -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 5]; -/// -/// let y = x.filter(|v| v >= 3); -/// -/// print(y); // prints "[3, 4, 5]" -/// -/// let y = x.filter(|v, i| v * i >= 10); -/// -/// print(y); // prints "[12, 20]" -/// ``` -fn filter(array: Array, filter: FnPtr) -> Array; - -/// Iterate through all the elements in the array, applying a function named by `filter` to each -/// element in turn, and return a copy of all elements (in order) that return `true` as a new array. -/// -/// # Function Parameters -/// -/// A function with the same name as the value of `filter` must exist taking these parameters: -/// -/// * `element`: copy of array element -/// * `index` _(optional)_: current index in the array -/// -/// # Example -/// -/// ```rhai -/// fn screen(x, i) { x * i >= 10 } -/// -/// let x = [1, 2, 3, 4, 5]; -/// -/// let y = x.filter("is_odd"); -/// -/// print(y); // prints "[1, 3, 5]" -/// -/// let y = x.filter("screen"); -/// -/// print(y); // prints "[12, 20]" -/// ``` -fn filter(array: Array, filter_func: String) -> Array; - -/// Return the largest whole number less than or equals to the floating-point number. -fn floor(x: float) -> float; - -/// Return the fractional part of the floating-point number. -fn fraction(x: float) -> float; - -/// Get a copy of the element at the `index` position in the array. -/// -/// * If `index` < 0, position counts from the end of the array (`-1` is the last element). -/// * If `index` < -length of array, `()` is returned. -/// * If `index` ≥ length of array, `()` is returned. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3]; -/// -/// print(x.get(0)); // prints 1 -/// -/// print(x.get(-1)); // prints 3 -/// -/// print(x.get(99)); // prints empty (for '()') -/// ``` -fn get(array: Array, index: int) -> ?; - -/// Get the byte value at the `index` position in the BLOB. -/// -/// * If `index` < 0, position counts from the end of the BLOB (`-1` is the last element). -/// * If `index` < -length of BLOB, zero is returned. -/// * If `index` ≥ length of BLOB, zero is returned. -/// -/// # Example -/// -/// ```rhai -/// let b = blob(); -/// -/// b += 1; b += 2; b += 3; b += 4; b += 5; -/// -/// print(b.get(0)); // prints 1 -/// -/// print(b.get(-1)); // prints 5 -/// -/// print(b.get(99)); // prints 0 -/// ``` -fn get(blob: Blob, index: int) -> int; - -/// Get the value of the `property` in the object map and return a copy. -/// -/// If `property` does not exist in the object map, `()` is returned. -/// -/// # Example -/// -/// ```rhai -/// let m = #{a: 1, b: 2, c: 3}; -/// -/// print(m.get("b")); // prints 2 -/// -/// print(m.get("x")); // prints empty (for '()') -/// ``` -fn get(map: Map, property: String) -> ?; - -/// Get the character at the `index` position in the string. -/// -/// * If `index` < 0, position counts from the end of the string (`-1` is the last character). -/// * If `index` < -length of string, zero is returned. -/// * If `index` ≥ length of string, zero is returned. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world!"; -/// -/// print(text.get(0)); // prints 'h' -/// -/// print(text.get(-1)); // prints '!' -/// -/// print(text.get(99)); // prints empty (for '()')' -/// ``` -fn get(string: String, index: int) -> ?; - -/// Return an iterator over all the bits in the number. -/// -/// # Example -/// -/// ```rhai -/// let x = 123456; -/// -/// for bit in x.bits { -/// print(bit); -/// } -/// ``` -fn get bits(value: int) -> Iterator; - -/// Return the length of the string, in number of bytes used to store it in UTF-8 encoding. -/// -/// # Example -/// -/// ```rhai -/// let text = "朝には紅顔ありて夕べには白骨となる"; -/// -/// print(text.bytes); // prints 51 -/// ``` -fn get bytes(string: String) -> int; - -/// Return the smallest whole number larger than or equals to the floating-point number. -fn get ceiling(x: float) -> float; - -/// Return an iterator over all the characters in the string. -/// -/// # Example -/// -/// ```rhai -/// for ch in "hello, world!".chars { -/// print(ch); -/// } -/// ``` -fn get chars(string: String) -> Iterator; - -/// Return the number of seconds between the current system time and the timestamp. -/// -/// # Example -/// -/// ```rhai -/// let now = timestamp(); -/// -/// sleep(10.0); // sleep for 10 seconds -/// -/// print(now.elapsed); // prints 10.??? -/// ``` -fn get elapsed(timestamp: Instant) -> RhaiResult; - -/// Return the end of the exclusive range. -fn get end(range: ExclusiveRange) -> int; - -/// Return the end of the inclusive range. -fn get end(range: InclusiveRange) -> int; - -/// Return the largest whole number less than or equals to the floating-point number. -fn get floor(x: float) -> float; - -/// Return the fractional part of the floating-point number. -fn get fraction(x: float) -> float; - -/// Return the integral part of the floating-point number. -fn get int(x: float) -> float; - -/// Return `true` if the function is an anonymous function. -/// -/// # Example -/// -/// ```rhai -/// let f = |x| x * 2; -/// -/// print(f.is_anonymous); // prints true -/// ``` -fn get is_anonymous(fn_ptr: FnPtr) -> bool; - -/// Return true if the array is empty. -fn get is_empty(array: Array) -> bool; - -/// Return true if the BLOB is empty. -fn get is_empty(blob: Blob) -> bool; - -/// Return true if the range contains no items. -fn get is_empty(range: ExclusiveRange) -> bool; - -/// Return true if the range contains no items. -fn get is_empty(range: InclusiveRange) -> bool; - -/// Return true if the string is empty. -fn get is_empty(string: String) -> bool; - -/// Return true if the number is even. -fn get is_even(x: int) -> bool; - -/// Return true if the number is even. -fn get is_even(x: i128) -> bool; - -/// Return true if the number is even. -fn get is_even(x: i16) -> bool; - -/// Return true if the number is even. -fn get is_even(x: i32) -> bool; - -/// Return true if the number is even. -fn get is_even(x: i8) -> bool; - -/// Return true if the number is even. -fn get is_even(x: u128) -> bool; - -/// Return true if the number is even. -fn get is_even(x: u16) -> bool; - -/// Return true if the number is even. -fn get is_even(x: u32) -> bool; - -/// Return true if the number is even. -fn get is_even(x: u64) -> bool; - -/// Return true if the number is even. -fn get is_even(x: u8) -> bool; - -/// Return `true` if the range is exclusive. -fn get is_exclusive(range: ExclusiveRange) -> bool; - -/// Return `true` if the range is exclusive. -fn get is_exclusive(range: InclusiveRange) -> bool; - -/// Return `true` if the floating-point number is finite. -fn get is_finite(x: float) -> bool; - -/// Return `true` if the range is inclusive. -fn get is_inclusive(range: ExclusiveRange) -> bool; - -/// Return `true` if the range is inclusive. -fn get is_inclusive(range: InclusiveRange) -> bool; - -/// Return `true` if the floating-point number is infinite. -fn get is_infinite(x: float) -> bool; - -/// Return `true` if the floating-point number is `NaN` (Not A Number). -fn get is_nan(x: float) -> bool; - -/// Return true if the number is odd. -fn get is_odd(x: int) -> bool; - -/// Return true if the number is odd. -fn get is_odd(x: i128) -> bool; - -/// Return true if the number is odd. -fn get is_odd(x: i16) -> bool; - -/// Return true if the number is odd. -fn get is_odd(x: i32) -> bool; - -/// Return true if the number is odd. -fn get is_odd(x: i8) -> bool; - -/// Return true if the number is odd. -fn get is_odd(x: u128) -> bool; - -/// Return true if the number is odd. -fn get is_odd(x: u16) -> bool; - -/// Return true if the number is odd. -fn get is_odd(x: u32) -> bool; - -/// Return true if the number is odd. -fn get is_odd(x: u64) -> bool; - -/// Return true if the number is odd. -fn get is_odd(x: u8) -> bool; - -/// Return true if the number is zero. -fn get is_zero(x: int) -> bool; - -/// Return true if the floating-point number is zero. -fn get is_zero(x: f32) -> bool; - -/// Return true if the floating-point number is zero. -fn get is_zero(x: float) -> bool; - -/// Return true if the number is zero. -fn get is_zero(x: i128) -> bool; - -/// Return true if the number is zero. -fn get is_zero(x: i16) -> bool; - -/// Return true if the number is zero. -fn get is_zero(x: i32) -> bool; - -/// Return true if the number is zero. -fn get is_zero(x: i8) -> bool; - -/// Return true if the number is zero. -fn get is_zero(x: u128) -> bool; - -/// Return true if the number is zero. -fn get is_zero(x: u16) -> bool; - -/// Return true if the number is zero. -fn get is_zero(x: u32) -> bool; - -/// Return true if the number is zero. -fn get is_zero(x: u64) -> bool; - -/// Return true if the number is zero. -fn get is_zero(x: u8) -> bool; - -/// Number of elements in the array. -fn get len(array: Array) -> int; - -/// Return the length of the BLOB. -/// -/// # Example -/// -/// ```rhai -/// let b = blob(10, 0x42); -/// -/// print(b); // prints "[4242424242424242 4242]" -/// -/// print(b.len()); // prints 10 -/// ``` -fn get len(blob: Blob) -> int; - -/// Return the length of the string, in number of characters. -/// -/// # Example -/// -/// ```rhai -/// let text = "朝には紅顔ありて夕べには白骨となる"; -/// -/// print(text.len); // prints 17 -/// ``` -fn get len(string: String) -> int; - -/// Return the name of the function. -/// -/// # Example -/// -/// ```rhai -/// fn double(x) { x * 2 } -/// -/// let f = Fn("double"); -/// -/// print(f.name); // prints "double" -/// ``` -fn get name(fn_ptr: FnPtr) -> String; - -/// Return the nearest whole number closest to the floating-point number. -/// Rounds away from zero. -fn get round(x: float) -> float; - -/// Return the start of the exclusive range. -fn get start(range: ExclusiveRange) -> int; - -/// Return the start of the inclusive range. -fn get start(range: InclusiveRange) -> int; - -/// Return the _tag_ of a `Dynamic` value. -/// -/// # Example -/// -/// ```rhai -/// let x = "hello, world!"; -/// -/// x.tag = 42; -/// -/// print(x.tag); // prints 42 -/// ``` -fn get tag(value: ?) -> int; - -/// Return `true` if the specified `bit` in the number is set. -/// -/// If `bit` < 0, position counts from the MSB (Most Significant Bit). -/// -/// # Example -/// -/// ```rhai -/// let x = 123456; -/// -/// print(x.get_bit(5)); // prints false -/// -/// print(x.get_bit(6)); // prints true -/// -/// print(x.get_bit(-48)); // prints true on 64-bit -/// ``` -fn get_bit(value: int, bit: int) -> bool; - -/// Return an exclusive range of bits in the number as a new number. -/// -/// # Example -/// -/// ```rhai -/// let x = 123456; -/// -/// print(x.get_bits(5..10)); // print 18 -/// ``` -fn get_bits(value: int, range: Range) -> int; - -/// Return an inclusive range of bits in the number as a new number. -/// -/// # Example -/// -/// ```rhai -/// let x = 123456; -/// -/// print(x.get_bits(5..=9)); // print 18 -/// ``` -fn get_bits(value: int, range: RangeInclusive) -> int; - -/// Return a portion of bits in the number as a new number. -/// -/// * If `start` < 0, position counts from the MSB (Most Significant Bit). -/// * If `bits` ≤ 0, zero is returned. -/// * If `start` position + `bits` ≥ total number of bits, the bits after the `start` position are returned. -/// -/// # Example -/// -/// ```rhai -/// let x = 123456; -/// -/// print(x.get_bits(5, 8)); // print 18 -/// ``` -fn get_bits(value: int, start: int, bits: int) -> int; - -fn get_fn_metadata_list() -> Array; - -fn get_fn_metadata_list(name: String) -> Array; - -fn get_fn_metadata_list(name: String, params: int) -> Array; - -/// Return the hypotenuse of a triangle with sides `x` and `y`. -fn hypot(x: float, y: float) -> float; - -/// Iterate through all the elements in the array, applying a function named by `filter` to each -/// element in turn, and return the index of the first element that returns `true`. -/// If no element returns `true`, `-1` is returned. -/// -/// # Function Parameters -/// -/// A function with the same name as the value of `filter` must exist taking these parameters: -/// -/// * `element`: copy of array element -/// * `index` _(optional)_: current index in the array -/// -/// # Example -/// -/// ```rhai -/// fn is_special(x) { x > 3 } -/// -/// fn is_dumb(x) { x > 8 } -/// -/// let x = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 5]; -/// -/// print(x.index_of("is_special")); // prints 3 -/// -/// print(x.index_of("is_dumb")); // prints -1 -/// ``` -fn index_of(array: Array, filter: String) -> int; - -/// Iterate through all the elements in the array, applying a `filter` function to each element -/// in turn, and return the index of the first element that returns `true`. -/// If no element returns `true`, `-1` is returned. -/// -/// # Function Parameters -/// -/// * `element`: copy of array element -/// * `index` _(optional)_: current index in the array -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 5]; -/// -/// print(x.index_of(|v| v > 3)); // prints 3: 4 > 3 -/// -/// print(x.index_of(|v| v > 8)); // prints -1: nothing is > 8 -/// -/// print(x.index_of(|v, i| v * i > 20)); // prints 7: 4 * 7 > 20 -/// ``` -fn index_of(array: Array, filter: FnPtr) -> int; - -/// Find the first element in the array that equals a particular `value` and return its index. -/// If no element equals `value`, `-1` is returned. -/// -/// The operator `==` is used to compare elements with `value` and must be defined, -/// otherwise `false` is assumed. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 5]; -/// -/// print(x.index_of(4)); // prints 3 (first index) -/// -/// print(x.index_of(9)); // prints -1 -/// -/// print(x.index_of("foo")); // prints -1: strings do not equal numbers -/// ``` -fn index_of(array: Array, value: ?) -> int; - -/// Find the specified `character` in the string and return the first index where it is found. -/// If the `character` is not found, `-1` is returned. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world!"; -/// -/// print(text.index_of('l')); // prints 2 (first index) -/// -/// print(text.index_of('x')); // prints -1 -/// ``` -fn index_of(string: String, character: char) -> int; - -/// Find the specified `character` in the string and return the first index where it is found. -/// If the `character` is not found, `-1` is returned. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world! hello, foobar!"; -/// -/// print(text.index_of("ll")); // prints 2 (first index) -/// -/// print(text.index_of("xx:)); // prints -1 -/// ``` -fn index_of(string: String, find_string: String) -> int; - -/// Iterate through all the elements in the array, starting from a particular `start` position, -/// applying a function named by `filter` to each element in turn, and return the index of the -/// first element that returns `true`. If no element returns `true`, `-1` is returned. -/// -/// * If `start` < 0, position counts from the end of the array (`-1` is the last element). -/// * If `start` < -length of array, position counts from the beginning of the array. -/// * If `start` ≥ length of array, `-1` is returned. -/// -/// # Function Parameters -/// -/// A function with the same name as the value of `filter` must exist taking these parameters: -/// -/// * `element`: copy of array element -/// * `index` _(optional)_: current index in the array -/// -/// # Example -/// -/// ```rhai -/// fn plural(x) { x > 1 } -/// -/// fn singular(x) { x < 2 } -/// -/// fn screen(x, i) { x * i > 20 } -/// -/// let x = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 5]; -/// -/// print(x.index_of("plural", 3)); // prints 5: 2 > 1 -/// -/// print(x.index_of("singular", 9)); // prints -1: nothing < 2 past index 9 -/// -/// print(x.index_of("plural", 15)); // prints -1: nothing found past end of array -/// -/// print(x.index_of("plural", -5)); // prints 9: -5 = start from index 8 -/// -/// print(x.index_of("plural", -99)); // prints 1: -99 = start from beginning -/// -/// print(x.index_of("screen", 8)); // prints 10: 3 * 10 > 20 -/// ``` -fn index_of(array: Array, filter: String, start: int) -> int; - -/// Iterate through all the elements in the array, starting from a particular `start` position, -/// applying a `filter` function to each element in turn, and return the index of the first -/// element that returns `true`. If no element returns `true`, `-1` is returned. -/// -/// * If `start` < 0, position counts from the end of the array (`-1` is the last element). -/// * If `start` < -length of array, position counts from the beginning of the array. -/// * If `start` ≥ length of array, `-1` is returned. -/// -/// # Function Parameters -/// -/// * `element`: copy of array element -/// * `index` _(optional)_: current index in the array -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 5]; -/// -/// print(x.index_of(|v| v > 1, 3)); // prints 5: 2 > 1 -/// -/// print(x.index_of(|v| v < 2, 9)); // prints -1: nothing < 2 past index 9 -/// -/// print(x.index_of(|v| v > 1, 15)); // prints -1: nothing found past end of array -/// -/// print(x.index_of(|v| v > 1, -5)); // prints 9: -5 = start from index 8 -/// -/// print(x.index_of(|v| v > 1, -99)); // prints 1: -99 = start from beginning -/// -/// print(x.index_of(|v, i| v * i > 20, 8)); // prints 10: 3 * 10 > 20 -/// ``` -fn index_of(array: Array, filter: FnPtr, start: int) -> int; - -/// Find the first element in the array, starting from a particular `start` position, that -/// equals a particular `value` and return its index. If no element equals `value`, `-1` is returned. -/// -/// * If `start` < 0, position counts from the end of the array (`-1` is the last element). -/// * If `start` < -length of array, position counts from the beginning of the array. -/// * If `start` ≥ length of array, `-1` is returned. -/// -/// The operator `==` is used to compare elements with `value` and must be defined, -/// otherwise `false` is assumed. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 5]; -/// -/// print(x.index_of(4, 2)); // prints 3 -/// -/// print(x.index_of(4, 5)); // prints 7 -/// -/// print(x.index_of(4, 15)); // prints -1: nothing found past end of array -/// -/// print(x.index_of(4, -5)); // prints 11: -5 = start from index 8 -/// -/// print(x.index_of(9, 1)); // prints -1: nothing equals 9 -/// -/// print(x.index_of("foo", 1)); // prints -1: strings do not equal numbers -/// ``` -fn index_of(array: Array, value: ?, start: int) -> int; - -/// Find the specified `character` in the string, starting from the specified `start` position, -/// and return the first index where it is found. -/// If the `character` is not found, `-1` is returned. -/// -/// * If `start` < 0, position counts from the end of the string (`-1` is the last character). -/// * If `start` < -length of string, position counts from the beginning of the string. -/// * If `start` ≥ length of string, `-1` is returned. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world!"; -/// -/// print(text.index_of('l', 5)); // prints 10 (first index after 5) -/// -/// print(text.index_of('o', -7)); // prints 8 -/// -/// print(text.index_of('x', 0)); // prints -1 -/// ``` -fn index_of(string: String, character: char, start: int) -> int; - -/// Find the specified sub-string in the string, starting from the specified `start` position, -/// and return the first index where it is found. -/// If the sub-string is not found, `-1` is returned. -/// -/// * If `start` < 0, position counts from the end of the string (`-1` is the last character). -/// * If `start` < -length of string, position counts from the beginning of the string. -/// * If `start` ≥ length of string, `-1` is returned. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world! hello, foobar!"; -/// -/// print(text.index_of("ll", 5)); // prints 16 (first index after 5) -/// -/// print(text.index_of("ll", -15)); // prints 16 -/// -/// print(text.index_of("xx", 0)); // prints -1 -/// ``` -fn index_of(string: String, find_string: String, start: int) -> int; - -/// Add a new element into the array at a particular `index` position. -/// -/// * If `index` < 0, position counts from the end of the array (`-1` is the last element). -/// * If `index` < -length of array, the element is added to the beginning of the array. -/// * If `index` ≥ length of array, the element is appended to the end of the array. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3]; -/// -/// x.insert(0, "hello"); -/// -/// x.insert(2, true); -/// -/// x.insert(-2, 42); -/// -/// print(x); // prints ["hello", 1, true, 2, 42, 3] -/// ``` -fn insert(array: Array, index: int, item: ?) -> (); - -/// Add a byte `value` to the BLOB at a particular `index` position. -/// -/// * If `index` < 0, position counts from the end of the BLOB (`-1` is the last byte). -/// * If `index` < -length of BLOB, the byte value is added to the beginning of the BLOB. -/// * If `index` ≥ length of BLOB, the byte value is appended to the end of the BLOB. -/// -/// Only the lower 8 bits of the `value` are used; all other bits are ignored. -/// -/// # Example -/// -/// ```rhai -/// let b = blob(5, 0x42); -/// -/// b.insert(2, 0x18); -/// -/// print(b); // prints "[4242184242]" -/// ``` -fn insert(blob: Blob, index: int, value: int) -> (); - -/// Return the integral part of the floating-point number. -fn int(x: float) -> float; - -/// Return `true` if the function is an anonymous function. -/// -/// # Example -/// -/// ```rhai -/// let f = |x| x * 2; -/// -/// print(f.is_anonymous); // prints true -/// ``` -fn is_anonymous(fn_ptr: FnPtr) -> bool; - -/// Return true if the array is empty. -fn is_empty(array: Array) -> bool; - -/// Return true if the BLOB is empty. -fn is_empty(blob: Blob) -> bool; - -/// Return true if the map is empty. -fn is_empty(map: Map) -> bool; - -/// Return true if the range contains no items. -fn is_empty(range: ExclusiveRange) -> bool; - -/// Return true if the range contains no items. -fn is_empty(range: InclusiveRange) -> bool; - -/// Return true if the string is empty. -fn is_empty(string: String) -> bool; - -/// Return true if the number is even. -fn is_even(x: int) -> bool; - -/// Return true if the number is even. -fn is_even(x: i128) -> bool; - -/// Return true if the number is even. -fn is_even(x: i16) -> bool; - -/// Return true if the number is even. -fn is_even(x: i32) -> bool; - -/// Return true if the number is even. -fn is_even(x: i8) -> bool; - -/// Return true if the number is even. -fn is_even(x: u128) -> bool; - -/// Return true if the number is even. -fn is_even(x: u16) -> bool; - -/// Return true if the number is even. -fn is_even(x: u32) -> bool; - -/// Return true if the number is even. -fn is_even(x: u64) -> bool; - -/// Return true if the number is even. -fn is_even(x: u8) -> bool; - -/// Return `true` if the range is exclusive. -fn is_exclusive(range: ExclusiveRange) -> bool; - -/// Return `true` if the range is exclusive. -fn is_exclusive(range: InclusiveRange) -> bool; - -/// Return `true` if the floating-point number is finite. -fn is_finite(x: float) -> bool; - -/// Return `true` if the range is inclusive. -fn is_inclusive(range: ExclusiveRange) -> bool; - -/// Return `true` if the range is inclusive. -fn is_inclusive(range: InclusiveRange) -> bool; - -/// Return `true` if the floating-point number is infinite. -fn is_infinite(x: float) -> bool; - -/// Return `true` if the floating-point number is `NaN` (Not A Number). -fn is_nan(x: float) -> bool; - -/// Return true if the number is odd. -fn is_odd(x: int) -> bool; - -/// Return true if the number is odd. -fn is_odd(x: i128) -> bool; - -/// Return true if the number is odd. -fn is_odd(x: i16) -> bool; - -/// Return true if the number is odd. -fn is_odd(x: i32) -> bool; - -/// Return true if the number is odd. -fn is_odd(x: i8) -> bool; - -/// Return true if the number is odd. -fn is_odd(x: u128) -> bool; - -/// Return true if the number is odd. -fn is_odd(x: u16) -> bool; - -/// Return true if the number is odd. -fn is_odd(x: u32) -> bool; - -/// Return true if the number is odd. -fn is_odd(x: u64) -> bool; - -/// Return true if the number is odd. -fn is_odd(x: u8) -> bool; - -/// Return true if the number is zero. -fn is_zero(x: int) -> bool; - -/// Return true if the floating-point number is zero. -fn is_zero(x: f32) -> bool; - -/// Return true if the floating-point number is zero. -fn is_zero(x: float) -> bool; - -/// Return true if the number is zero. -fn is_zero(x: i128) -> bool; - -/// Return true if the number is zero. -fn is_zero(x: i16) -> bool; - -/// Return true if the number is zero. -fn is_zero(x: i32) -> bool; - -/// Return true if the number is zero. -fn is_zero(x: i8) -> bool; - -/// Return true if the number is zero. -fn is_zero(x: u128) -> bool; - -/// Return true if the number is zero. -fn is_zero(x: u16) -> bool; - -/// Return true if the number is zero. -fn is_zero(x: u32) -> bool; - -/// Return true if the number is zero. -fn is_zero(x: u64) -> bool; - -/// Return true if the number is zero. -fn is_zero(x: u8) -> bool; - -/// Return an array with all the property names in the object map. -/// -/// # Example -/// -/// ```rhai -/// let m = #{a:1, b:2, c:3}; -/// -/// print(m.keys()); // prints ["a", "b", "c"] -/// ``` -fn keys(map: Map) -> Array; - -/// Number of elements in the array. -fn len(array: Array) -> int; - -/// Return the length of the BLOB. -/// -/// # Example -/// -/// ```rhai -/// let b = blob(10, 0x42); -/// -/// print(b); // prints "[4242424242424242 4242]" -/// -/// print(b.len()); // prints 10 -/// ``` -fn len(blob: Blob) -> int; - -/// Return the number of properties in the object map. -fn len(map: Map) -> int; - -/// Return the length of the string, in number of characters. -/// -/// # Example -/// -/// ```rhai -/// let text = "朝には紅顔ありて夕べには白骨となる"; -/// -/// print(text.len); // prints 17 -/// ``` -fn len(string: String) -> int; - -/// Return the natural log of the floating-point number. -fn ln(x: float) -> float; - -/// Return the log of the floating-point number with base 10. -fn log(x: float) -> float; - -/// Return the log of the floating-point number with `base`. -fn log(x: float, base: float) -> float; - -/// Convert the character to lower-case. -/// -/// # Example -/// -/// ```rhai -/// let ch = 'A'; -/// -/// ch.make_lower(); -/// -/// print(ch); // prints 'a' -/// ``` -fn make_lower(character: char) -> (); - -/// Convert the string to all lower-case. -/// -/// # Example -/// -/// ```rhai -/// let text = "HELLO, WORLD!" -/// -/// text.make_lower(); -/// -/// print(text); // prints "hello, world!"; -/// ``` -fn make_lower(string: String) -> (); - -/// Convert the character to upper-case. -/// -/// # Example -/// -/// ```rhai -/// let ch = 'a'; -/// -/// ch.make_upper(); -/// -/// print(ch); // prints 'A' -/// ``` -fn make_upper(character: char) -> (); - -/// Convert the string to all upper-case. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world!" -/// -/// text.make_upper(); -/// -/// print(text); // prints "HELLO, WORLD!"; -/// ``` -fn make_upper(string: String) -> (); - -/// Iterate through all the elements in the array, applying a function named by `mapper` to each -/// element in turn, and return the results as a new array. -/// -/// # Function Parameters -/// -/// A function with the same name as the value of `mapper` must exist taking these parameters: -/// -/// * `element`: copy of array element -/// * `index` _(optional)_: current index in the array -/// -/// # Example -/// -/// ```rhai -/// fn square(x) { x * x } -/// -/// fn multiply(x, i) { x * i } -/// -/// let x = [1, 2, 3, 4, 5]; -/// -/// let y = x.map("square"); -/// -/// print(y); // prints "[1, 4, 9, 16, 25]" -/// -/// let y = x.map("multiply"); -/// -/// print(y); // prints "[0, 2, 6, 12, 20]" -/// ``` -fn map(array: Array, mapper: String) -> Array; - -/// Iterate through all the elements in the array, applying a `mapper` function to each element -/// in turn, and return the results as a new array. -/// -/// # Function Parameters -/// -/// * `element`: copy of array element -/// * `index` _(optional)_: current index in the array -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 5]; -/// -/// let y = x.map(|v| v * v); -/// -/// print(y); // prints "[1, 4, 9, 16, 25]" -/// -/// let y = x.map(|v, i| v * i); -/// -/// print(y); // prints "[0, 2, 6, 12, 20]" -/// ``` -fn map(array: Array, mapper: FnPtr) -> Array; - -/// Add all property values of another object map into the object map. -/// Existing property values of the same names are replaced. -/// -/// # Example -/// -/// ```rhai -/// let m = #{a:1, b:2, c:3}; -/// let n = #{a: 42, d:0}; -/// -/// m.mixin(n); -/// -/// print(m); // prints "#{a:42, b:2, c:3, d:0}" -/// ``` -fn mixin(map: Map, map2: Map) -> (); - -/// Return the name of the function. -/// -/// # Example -/// -/// ```rhai -/// fn double(x) { x * 2 } -/// -/// let f = Fn("double"); -/// -/// print(f.name); // prints "double" -/// ``` -fn name(fn_ptr: FnPtr) -> String; - -/// Pad the array to at least the specified length with copies of a specified element. -/// -/// If `len` ≤ length of array, no padding is done. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3]; -/// -/// x.pad(5, 42); -/// -/// print(x); // prints "[1, 2, 3, 42, 42]" -/// -/// x.pad(3, 123); -/// -/// print(x); // prints "[1, 2, 3, 42, 42]" -/// ``` -fn pad(array: Array, len: int, item: ?) -> (); - -/// Pad the BLOB to at least the specified length with copies of a specified byte `value`. -/// -/// If `len` ≤ length of BLOB, no padding is done. -/// -/// Only the lower 8 bits of the `value` are used; all other bits are ignored. -/// -/// # Example -/// -/// ```rhai -/// let b = blob(3, 0x42); -/// -/// b.pad(5, 0x18) -/// -/// print(b); // prints "[4242421818]" -/// -/// b.pad(3, 0xab) -/// -/// print(b); // prints "[4242421818]" -/// ``` -fn pad(blob: Blob, len: int, value: int) -> (); - -/// Pad the string to at least the specified number of characters with the specified `character`. -/// -/// If `len` ≤ length of string, no padding is done. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello"; -/// -/// text.pad(8, '!'); -/// -/// print(text); // prints "hello!!!" -/// -/// text.pad(5, '*'); -/// -/// print(text); // prints "hello!!!" -/// ``` -fn pad(string: String, len: int, character: char) -> (); - -/// Pad the string to at least the specified number of characters with the specified string. -/// -/// If `len` ≤ length of string, no padding is done. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello"; -/// -/// text.pad(10, "(!)"); -/// -/// print(text); // prints "hello(!)(!)" -/// -/// text.pad(8, '***'); -/// -/// print(text); // prints "hello(!)(!)" -/// ``` -fn pad(string: String, len: int, padding: String) -> (); - -/// Parse the bytes within an exclusive `range` in the BLOB as a `FLOAT` -/// in big-endian byte order. -/// -/// * If number of bytes in `range` < number of bytes for `FLOAT`, zeros are padded. -/// * If number of bytes in `range` > number of bytes for `FLOAT`, extra bytes are ignored. -fn parse_be_float(blob: Blob, range: Range) -> float; - -/// Parse the bytes within an inclusive `range` in the BLOB as a `FLOAT` -/// in big-endian byte order. -/// -/// * If number of bytes in `range` < number of bytes for `FLOAT`, zeros are padded. -/// * If number of bytes in `range` > number of bytes for `FLOAT`, extra bytes are ignored. -fn parse_be_float(blob: Blob, range: RangeInclusive) -> float; - -/// Parse the bytes beginning at the `start` position in the BLOB as a `FLOAT` -/// in big-endian byte order. -/// -/// * If `start` < 0, position counts from the end of the BLOB (`-1` is the last byte). -/// * If `start` < -length of BLOB, position counts from the beginning of the BLOB. -/// * If `start` ≥ length of BLOB, zero is returned. -/// * If `len` ≤ 0, zero is returned. -/// * If `start` position + `len` ≥ length of BLOB, entire portion of the BLOB after the `start` position is parsed. -/// -/// * If number of bytes in range < number of bytes for `FLOAT`, zeros are padded. -/// * If number of bytes in range > number of bytes for `FLOAT`, extra bytes are ignored. -fn parse_be_float(blob: Blob, start: int, len: int) -> float; - -/// Parse the bytes within an exclusive `range` in the BLOB as an `INT` -/// in big-endian byte order. -/// -/// * If number of bytes in `range` < number of bytes for `INT`, zeros are padded. -/// * If number of bytes in `range` > number of bytes for `INT`, extra bytes are ignored. -/// -/// ```rhai -/// let b = blob(); -/// -/// b += 1; b += 2; b += 3; b += 4; b += 5; -/// -/// let x = b.parse_be_int(1..3); // parse two bytes -/// -/// print(x.to_hex()); // prints "02030000...00" -/// ``` -fn parse_be_int(blob: Blob, range: Range) -> int; - -/// Parse the bytes within an inclusive `range` in the BLOB as an `INT` -/// in big-endian byte order. -/// -/// * If number of bytes in `range` < number of bytes for `INT`, zeros are padded. -/// * If number of bytes in `range` > number of bytes for `INT`, extra bytes are ignored. -/// -/// ```rhai -/// let b = blob(); -/// -/// b += 1; b += 2; b += 3; b += 4; b += 5; -/// -/// let x = b.parse_be_int(1..=3); // parse three bytes -/// -/// print(x.to_hex()); // prints "0203040000...00" -/// ``` -fn parse_be_int(blob: Blob, range: RangeInclusive) -> int; - -/// Parse the bytes beginning at the `start` position in the BLOB as an `INT` -/// in big-endian byte order. -/// -/// * If `start` < 0, position counts from the end of the BLOB (`-1` is the last byte). -/// * If `start` < -length of BLOB, position counts from the beginning of the BLOB. -/// * If `start` ≥ length of BLOB, zero is returned. -/// * If `len` ≤ 0, zero is returned. -/// * If `start` position + `len` ≥ length of BLOB, entire portion of the BLOB after the `start` position is parsed. -/// -/// * If number of bytes in range < number of bytes for `INT`, zeros are padded. -/// * If number of bytes in range > number of bytes for `INT`, extra bytes are ignored. -/// -/// ```rhai -/// let b = blob(); -/// -/// b += 1; b += 2; b += 3; b += 4; b += 5; -/// -/// let x = b.parse_be_int(1, 2); -/// -/// print(x.to_hex()); // prints "02030000...00" -/// ``` -fn parse_be_int(blob: Blob, start: int, len: int) -> int; - -/// Parse a string into a floating-point number. -/// -/// # Example -/// -/// ```rhai -/// let x = parse_int("123.456"); -/// -/// print(x); // prints 123.456 -/// ``` -fn parse_float(string: String) -> float; - -/// Parse a string into an integer number. -/// -/// # Example -/// -/// ```rhai -/// let x = parse_int("123"); -/// -/// print(x); // prints 123 -/// ``` -fn parse_int(string: String) -> int; - -/// Parse a string into an integer number of the specified `radix`. -/// -/// `radix` must be between 2 and 36. -/// -/// # Example -/// -/// ```rhai -/// let x = parse_int("123"); -/// -/// print(x); // prints 123 -/// -/// let y = parse_int("123abc", 16); -/// -/// print(y); // prints 1194684 (0x123abc) -/// ``` -fn parse_int(string: String, radix: int) -> int; - -/// Parse a JSON string into a value. -/// -/// # Example -/// -/// ```rhai -/// let m = parse_json(`{"a":1, "b":2, "c":3}`); -/// -/// print(m); // prints #{"a":1, "b":2, "c":3} -/// ``` -fn parse_json(json: String) -> ?; - -/// Parse the bytes within an exclusive `range` in the BLOB as a `FLOAT` -/// in little-endian byte order. -/// -/// * If number of bytes in `range` < number of bytes for `FLOAT`, zeros are padded. -/// * If number of bytes in `range` > number of bytes for `FLOAT`, extra bytes are ignored. -fn parse_le_float(blob: Blob, range: Range) -> float; - -/// Parse the bytes within an inclusive `range` in the BLOB as a `FLOAT` -/// in little-endian byte order. -/// -/// * If number of bytes in `range` < number of bytes for `FLOAT`, zeros are padded. -/// * If number of bytes in `range` > number of bytes for `FLOAT`, extra bytes are ignored. -fn parse_le_float(blob: Blob, range: RangeInclusive) -> float; - -/// Parse the bytes beginning at the `start` position in the BLOB as a `FLOAT` -/// in little-endian byte order. -/// -/// * If `start` < 0, position counts from the end of the BLOB (`-1` is the last byte). -/// * If `start` < -length of BLOB, position counts from the beginning of the BLOB. -/// * If `start` ≥ length of BLOB, zero is returned. -/// * If `len` ≤ 0, zero is returned. -/// * If `start` position + `len` ≥ length of BLOB, entire portion of the BLOB after the `start` position is parsed. -/// -/// * If number of bytes in range < number of bytes for `FLOAT`, zeros are padded. -/// * If number of bytes in range > number of bytes for `FLOAT`, extra bytes are ignored. -fn parse_le_float(blob: Blob, start: int, len: int) -> float; - -/// Parse the bytes within an exclusive `range` in the BLOB as an `INT` -/// in little-endian byte order. -/// -/// * If number of bytes in `range` < number of bytes for `INT`, zeros are padded. -/// * If number of bytes in `range` > number of bytes for `INT`, extra bytes are ignored. -/// -/// ```rhai -/// let b = blob(); -/// -/// b += 1; b += 2; b += 3; b += 4; b += 5; -/// -/// let x = b.parse_le_int(1..3); // parse two bytes -/// -/// print(x.to_hex()); // prints "0302" -/// ``` -fn parse_le_int(blob: Blob, range: Range) -> int; - -/// Parse the bytes within an inclusive `range` in the BLOB as an `INT` -/// in little-endian byte order. -/// -/// * If number of bytes in `range` < number of bytes for `INT`, zeros are padded. -/// * If number of bytes in `range` > number of bytes for `INT`, extra bytes are ignored. -/// -/// ```rhai -/// let b = blob(); -/// -/// b += 1; b += 2; b += 3; b += 4; b += 5; -/// -/// let x = b.parse_le_int(1..=3); // parse three bytes -/// -/// print(x.to_hex()); // prints "040302" -/// ``` -fn parse_le_int(blob: Blob, range: RangeInclusive) -> int; - -/// Parse the bytes beginning at the `start` position in the BLOB as an `INT` -/// in little-endian byte order. -/// -/// * If `start` < 0, position counts from the end of the BLOB (`-1` is the last byte). -/// * If `start` < -length of BLOB, position counts from the beginning of the BLOB. -/// * If `start` ≥ length of BLOB, zero is returned. -/// * If `len` ≤ 0, zero is returned. -/// * If `start` position + `len` ≥ length of BLOB, entire portion of the BLOB after the `start` position is parsed. -/// -/// * If number of bytes in range < number of bytes for `INT`, zeros are padded. -/// * If number of bytes in range > number of bytes for `INT`, extra bytes are ignored. -/// -/// ```rhai -/// let b = blob(); -/// -/// b += 1; b += 2; b += 3; b += 4; b += 5; -/// -/// let x = b.parse_le_int(1, 2); -/// -/// print(x.to_hex()); // prints "0302" -/// ``` -fn parse_le_int(blob: Blob, start: int, len: int) -> int; - -/// Remove the last element from the array and return it. -/// -/// If the array is empty, `()` is returned. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3]; -/// -/// print(x.pop()); // prints 3 -/// -/// print(x); // prints "[1, 2]" -/// ``` -fn pop(array: Array) -> ?; - -/// Remove the last byte from the BLOB and return it. -/// -/// If the BLOB is empty, zero is returned. -/// -/// # Example -/// -/// ```rhai -/// let b = blob(); -/// -/// b += 1; b += 2; b += 3; b += 4; b += 5; -/// -/// print(b.pop()); // prints 5 -/// -/// print(b); // prints "[01020304]" -/// ``` -fn pop(blob: Blob) -> int; - -/// Remove the last character from the string and return it. -/// -/// If the string is empty, `()` is returned. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world!"; -/// -/// print(text.pop()); // prints '!' -/// -/// print(text); // prints "hello, world" -/// ``` -fn pop(string: String) -> ?; - -/// Remove a specified number of characters from the end of the string and return it as a -/// new string. -/// -/// * If `len` ≤ 0, the string is not modified and an empty string is returned. -/// * If `len` ≥ length of string, the string is cleared and the entire string returned. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world!"; -/// -/// print(text.pop(4)); // prints "rld!" -/// -/// print(text); // prints "hello, wo" -/// ``` -fn pop(string: String, len: int) -> String; - -/// Return the empty string. -op print() -> String; - -/// Convert the array into a string. -op print(Array) -> String; - -/// Return the character into a string. -op print(char) -> String; - -/// Convert the value of the `item` into a string. -op print(?) -> String; - -/// Convert the object map into a string. -op print(Map) -> String; - -/// Convert the value of `number` into a string. -op print(f32) -> String; - -/// Convert the value of `number` into a string. -op print(float) -> String; - -/// Return the `string`. -op print(String) -> String; - -/// Return the empty string. -op print(()) -> String; - -/// Return the boolean value into a string. -op print(bool) -> String; - -/// Add a new element, which is not another array, to the end of the array. -/// -/// If `item` is `Array`, then `append` is more specific and will be called instead. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3]; -/// -/// x.push("hello"); -/// -/// print(x); // prints [1, 2, 3, "hello"] -/// ``` -fn push(array: Array, item: ?) -> (); - -/// Add a new byte `value` to the end of the BLOB. -/// -/// Only the lower 8 bits of the `value` are used; all other bits are ignored. -/// -/// # Example -/// -/// ```rhai -/// let b = blob(); -/// -/// b.push(0x42); -/// -/// print(b); // prints "[42]" -/// ``` -fn push(blob: Blob, value: int) -> (); - -/// Return an iterator over the exclusive range of `from..to`. -/// The value `to` is never included. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 -/// for n in range(8, 18) { -/// print(n); -/// } -/// ``` -fn range(from: i128, to: i128) -> Iterator; - -/// Return an iterator over the exclusive range of `from..to`. -/// The value `to` is never included. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 -/// for n in range(8, 18) { -/// print(n); -/// } -/// ``` -fn range(from: i16, to: i16) -> Iterator; - -/// Return an iterator over the exclusive range of `from..to`. -/// The value `to` is never included. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 -/// for n in range(8, 18) { -/// print(n); -/// } -/// ``` -fn range(from: i32, to: i32) -> Iterator; - -/// Return an iterator over the exclusive range of `from..to`. -/// The value `to` is never included. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 -/// for n in range(8, 18) { -/// print(n); -/// } -/// ``` -fn range(from: int, to: int) -> Iterator; - -/// Return an iterator over the exclusive range of `from..to`. -/// The value `to` is never included. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 -/// for n in range(8, 18) { -/// print(n); -/// } -/// ``` -fn range(from: i8, to: i8) -> Iterator; - -/// Return an iterator over the exclusive range of `from..to`. -/// The value `to` is never included. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 -/// for n in range(8, 18) { -/// print(n); -/// } -/// ``` -fn range(from: u128, to: u128) -> Iterator; - -/// Return an iterator over the exclusive range of `from..to`. -/// The value `to` is never included. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 -/// for n in range(8, 18) { -/// print(n); -/// } -/// ``` -fn range(from: u16, to: u16) -> Iterator; - -/// Return an iterator over the exclusive range of `from..to`. -/// The value `to` is never included. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 -/// for n in range(8, 18) { -/// print(n); -/// } -/// ``` -fn range(from: u32, to: u32) -> Iterator; - -/// Return an iterator over the exclusive range of `from..to`. -/// The value `to` is never included. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 -/// for n in range(8, 18) { -/// print(n); -/// } -/// ``` -fn range(from: u64, to: u64) -> Iterator; - -/// Return an iterator over the exclusive range of `from..to`. -/// The value `to` is never included. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 -/// for n in range(8, 18) { -/// print(n); -/// } -/// ``` -fn range(from: u8, to: u8) -> Iterator; - -/// Return an iterator over an exclusive range, each iteration increasing by `step`. -/// -/// If `range` is reversed and `step` < 0, iteration goes backwards. -/// -/// Otherwise, if `range` is empty, an empty iterator is returned. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 in steps of 3 -/// for n in range(8..18, 3) { -/// print(n); -/// } -/// -/// // prints all values down from 18 to 9 in steps of -3 -/// for n in range(18..8, -3) { -/// print(n); -/// } -/// ``` -fn range(range: Range, step: float) -> Iterator; - -/// Return an iterator over an exclusive range, each iteration increasing by `step`. -/// -/// If `range` is reversed and `step` < 0, iteration goes backwards. -/// -/// Otherwise, if `range` is empty, an empty iterator is returned. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 in steps of 3 -/// for n in range(8..18, 3) { -/// print(n); -/// } -/// -/// // prints all values down from 18 to 9 in steps of -3 -/// for n in range(18..8, -3) { -/// print(n); -/// } -/// ``` -fn range(range: Range, step: i128) -> Iterator; - -/// Return an iterator over an exclusive range, each iteration increasing by `step`. -/// -/// If `range` is reversed and `step` < 0, iteration goes backwards. -/// -/// Otherwise, if `range` is empty, an empty iterator is returned. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 in steps of 3 -/// for n in range(8..18, 3) { -/// print(n); -/// } -/// -/// // prints all values down from 18 to 9 in steps of -3 -/// for n in range(18..8, -3) { -/// print(n); -/// } -/// ``` -fn range(range: Range, step: i16) -> Iterator; - -/// Return an iterator over an exclusive range, each iteration increasing by `step`. -/// -/// If `range` is reversed and `step` < 0, iteration goes backwards. -/// -/// Otherwise, if `range` is empty, an empty iterator is returned. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 in steps of 3 -/// for n in range(8..18, 3) { -/// print(n); -/// } -/// -/// // prints all values down from 18 to 9 in steps of -3 -/// for n in range(18..8, -3) { -/// print(n); -/// } -/// ``` -fn range(range: Range, step: i32) -> Iterator; - -/// Return an iterator over an exclusive range, each iteration increasing by `step`. -/// -/// If `range` is reversed and `step` < 0, iteration goes backwards. -/// -/// Otherwise, if `range` is empty, an empty iterator is returned. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 in steps of 3 -/// for n in range(8..18, 3) { -/// print(n); -/// } -/// -/// // prints all values down from 18 to 9 in steps of -3 -/// for n in range(18..8, -3) { -/// print(n); -/// } -/// ``` -fn range(range: Range, step: int) -> Iterator; - -/// Return an iterator over an exclusive range, each iteration increasing by `step`. -/// -/// If `range` is reversed and `step` < 0, iteration goes backwards. -/// -/// Otherwise, if `range` is empty, an empty iterator is returned. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 in steps of 3 -/// for n in range(8..18, 3) { -/// print(n); -/// } -/// -/// // prints all values down from 18 to 9 in steps of -3 -/// for n in range(18..8, -3) { -/// print(n); -/// } -/// ``` -fn range(range: Range, step: i8) -> Iterator; - -/// Return an iterator over an exclusive range, each iteration increasing by `step`. -/// -/// If `range` is reversed and `step` < 0, iteration goes backwards. -/// -/// Otherwise, if `range` is empty, an empty iterator is returned. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 in steps of 3 -/// for n in range(8..18, 3) { -/// print(n); -/// } -/// -/// // prints all values down from 18 to 9 in steps of -3 -/// for n in range(18..8, -3) { -/// print(n); -/// } -/// ``` -fn range(range: Range, step: u128) -> Iterator; - -/// Return an iterator over an exclusive range, each iteration increasing by `step`. -/// -/// If `range` is reversed and `step` < 0, iteration goes backwards. -/// -/// Otherwise, if `range` is empty, an empty iterator is returned. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 in steps of 3 -/// for n in range(8..18, 3) { -/// print(n); -/// } -/// -/// // prints all values down from 18 to 9 in steps of -3 -/// for n in range(18..8, -3) { -/// print(n); -/// } -/// ``` -fn range(range: Range, step: u16) -> Iterator; - -/// Return an iterator over an exclusive range, each iteration increasing by `step`. -/// -/// If `range` is reversed and `step` < 0, iteration goes backwards. -/// -/// Otherwise, if `range` is empty, an empty iterator is returned. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 in steps of 3 -/// for n in range(8..18, 3) { -/// print(n); -/// } -/// -/// // prints all values down from 18 to 9 in steps of -3 -/// for n in range(18..8, -3) { -/// print(n); -/// } -/// ``` -fn range(range: Range, step: u32) -> Iterator; - -/// Return an iterator over an exclusive range, each iteration increasing by `step`. -/// -/// If `range` is reversed and `step` < 0, iteration goes backwards. -/// -/// Otherwise, if `range` is empty, an empty iterator is returned. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 in steps of 3 -/// for n in range(8..18, 3) { -/// print(n); -/// } -/// -/// // prints all values down from 18 to 9 in steps of -3 -/// for n in range(18..8, -3) { -/// print(n); -/// } -/// ``` -fn range(range: Range, step: u64) -> Iterator; - -/// Return an iterator over an exclusive range, each iteration increasing by `step`. -/// -/// If `range` is reversed and `step` < 0, iteration goes backwards. -/// -/// Otherwise, if `range` is empty, an empty iterator is returned. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 in steps of 3 -/// for n in range(8..18, 3) { -/// print(n); -/// } -/// -/// // prints all values down from 18 to 9 in steps of -3 -/// for n in range(18..8, -3) { -/// print(n); -/// } -/// ``` -fn range(range: Range, step: u8) -> Iterator; - -/// Return an iterator over the exclusive range of `from..to`, each iteration increasing by `step`. -/// The value `to` is never included. -/// -/// If `from` > `to` and `step` < 0, iteration goes backwards. -/// -/// If `from` > `to` and `step` > 0 or `from` < `to` and `step` < 0, an empty iterator is returned. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 in steps of 3 -/// for n in range(8, 18, 3) { -/// print(n); -/// } -/// -/// // prints all values down from 18 to 9 in steps of -3 -/// for n in range(18, 8, -3) { -/// print(n); -/// } -/// ``` -fn range(from: float, to: float, step: float) -> Iterator; - -/// Return an iterator over the exclusive range of `from..to`, each iteration increasing by `step`. -/// The value `to` is never included. -/// -/// If `from` > `to` and `step` < 0, iteration goes backwards. -/// -/// If `from` > `to` and `step` > 0 or `from` < `to` and `step` < 0, an empty iterator is returned. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 in steps of 3 -/// for n in range(8, 18, 3) { -/// print(n); -/// } -/// -/// // prints all values down from 18 to 9 in steps of -3 -/// for n in range(18, 8, -3) { -/// print(n); -/// } -/// ``` -fn range(from: i128, to: i128, step: i128) -> Iterator; - -/// Return an iterator over the exclusive range of `from..to`, each iteration increasing by `step`. -/// The value `to` is never included. -/// -/// If `from` > `to` and `step` < 0, iteration goes backwards. -/// -/// If `from` > `to` and `step` > 0 or `from` < `to` and `step` < 0, an empty iterator is returned. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 in steps of 3 -/// for n in range(8, 18, 3) { -/// print(n); -/// } -/// -/// // prints all values down from 18 to 9 in steps of -3 -/// for n in range(18, 8, -3) { -/// print(n); -/// } -/// ``` -fn range(from: i16, to: i16, step: i16) -> Iterator; - -/// Return an iterator over the exclusive range of `from..to`, each iteration increasing by `step`. -/// The value `to` is never included. -/// -/// If `from` > `to` and `step` < 0, iteration goes backwards. -/// -/// If `from` > `to` and `step` > 0 or `from` < `to` and `step` < 0, an empty iterator is returned. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 in steps of 3 -/// for n in range(8, 18, 3) { -/// print(n); -/// } -/// -/// // prints all values down from 18 to 9 in steps of -3 -/// for n in range(18, 8, -3) { -/// print(n); -/// } -/// ``` -fn range(from: i32, to: i32, step: i32) -> Iterator; - -/// Return an iterator over the exclusive range of `from..to`, each iteration increasing by `step`. -/// The value `to` is never included. -/// -/// If `from` > `to` and `step` < 0, iteration goes backwards. -/// -/// If `from` > `to` and `step` > 0 or `from` < `to` and `step` < 0, an empty iterator is returned. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 in steps of 3 -/// for n in range(8, 18, 3) { -/// print(n); -/// } -/// -/// // prints all values down from 18 to 9 in steps of -3 -/// for n in range(18, 8, -3) { -/// print(n); -/// } -/// ``` -fn range(from: int, to: int, step: int) -> Iterator; - -/// Return an iterator over the exclusive range of `from..to`, each iteration increasing by `step`. -/// The value `to` is never included. -/// -/// If `from` > `to` and `step` < 0, iteration goes backwards. -/// -/// If `from` > `to` and `step` > 0 or `from` < `to` and `step` < 0, an empty iterator is returned. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 in steps of 3 -/// for n in range(8, 18, 3) { -/// print(n); -/// } -/// -/// // prints all values down from 18 to 9 in steps of -3 -/// for n in range(18, 8, -3) { -/// print(n); -/// } -/// ``` -fn range(from: i8, to: i8, step: i8) -> Iterator; - -/// Return an iterator over the exclusive range of `from..to`, each iteration increasing by `step`. -/// The value `to` is never included. -/// -/// If `from` > `to` and `step` < 0, iteration goes backwards. -/// -/// If `from` > `to` and `step` > 0 or `from` < `to` and `step` < 0, an empty iterator is returned. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 in steps of 3 -/// for n in range(8, 18, 3) { -/// print(n); -/// } -/// -/// // prints all values down from 18 to 9 in steps of -3 -/// for n in range(18, 8, -3) { -/// print(n); -/// } -/// ``` -fn range(from: u128, to: u128, step: u128) -> Iterator; - -/// Return an iterator over the exclusive range of `from..to`, each iteration increasing by `step`. -/// The value `to` is never included. -/// -/// If `from` > `to` and `step` < 0, iteration goes backwards. -/// -/// If `from` > `to` and `step` > 0 or `from` < `to` and `step` < 0, an empty iterator is returned. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 in steps of 3 -/// for n in range(8, 18, 3) { -/// print(n); -/// } -/// -/// // prints all values down from 18 to 9 in steps of -3 -/// for n in range(18, 8, -3) { -/// print(n); -/// } -/// ``` -fn range(from: u16, to: u16, step: u16) -> Iterator; - -/// Return an iterator over the exclusive range of `from..to`, each iteration increasing by `step`. -/// The value `to` is never included. -/// -/// If `from` > `to` and `step` < 0, iteration goes backwards. -/// -/// If `from` > `to` and `step` > 0 or `from` < `to` and `step` < 0, an empty iterator is returned. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 in steps of 3 -/// for n in range(8, 18, 3) { -/// print(n); -/// } -/// -/// // prints all values down from 18 to 9 in steps of -3 -/// for n in range(18, 8, -3) { -/// print(n); -/// } -/// ``` -fn range(from: u32, to: u32, step: u32) -> Iterator; - -/// Return an iterator over the exclusive range of `from..to`, each iteration increasing by `step`. -/// The value `to` is never included. -/// -/// If `from` > `to` and `step` < 0, iteration goes backwards. -/// -/// If `from` > `to` and `step` > 0 or `from` < `to` and `step` < 0, an empty iterator is returned. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 in steps of 3 -/// for n in range(8, 18, 3) { -/// print(n); -/// } -/// -/// // prints all values down from 18 to 9 in steps of -3 -/// for n in range(18, 8, -3) { -/// print(n); -/// } -/// ``` -fn range(from: u64, to: u64, step: u64) -> Iterator; - -/// Return an iterator over the exclusive range of `from..to`, each iteration increasing by `step`. -/// The value `to` is never included. -/// -/// If `from` > `to` and `step` < 0, iteration goes backwards. -/// -/// If `from` > `to` and `step` > 0 or `from` < `to` and `step` < 0, an empty iterator is returned. -/// -/// # Example -/// -/// ```rhai -/// // prints all values from 8 to 17 in steps of 3 -/// for n in range(8, 18, 3) { -/// print(n); -/// } -/// -/// // prints all values down from 18 to 9 in steps of -3 -/// for n in range(18, 8, -3) { -/// print(n); -/// } -/// ``` -fn range(from: u8, to: u8, step: u8) -> Iterator; - -/// Reduce an array by iterating through all elements while applying a function named by `reducer`. -/// -/// # Function Parameters -/// -/// A function with the same name as the value of `reducer` must exist taking these parameters: -/// -/// * `result`: accumulated result, initially `()` -/// * `element`: copy of array element -/// * `index` _(optional)_: current index in the array -/// -/// # Example -/// -/// ```rhai -/// fn process(r, x) { -/// x + (r ?? 0) -/// } -/// fn process_extra(r, x, i) { -/// x + i + (r ?? 0) -/// } -/// -/// let x = [1, 2, 3, 4, 5]; -/// -/// let y = x.reduce("process"); -/// -/// print(y); // prints 15 -/// -/// let y = x.reduce("process_extra"); -/// -/// print(y); // prints 25 -/// ``` -fn reduce(array: Array, reducer: String) -> RhaiResult; - -/// Reduce an array by iterating through all elements while applying the `reducer` function. -/// -/// # Function Parameters -/// -/// * `result`: accumulated result, initially `()` -/// * `element`: copy of array element -/// * `index` _(optional)_: current index in the array -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 5]; -/// -/// let y = x.reduce(|r, v| v + (r ?? 0)); -/// -/// print(y); // prints 15 -/// -/// let y = x.reduce(|r, v, i| v + i + (r ?? 0)); -/// -/// print(y); // prints 25 -/// ``` -fn reduce(array: Array, reducer: FnPtr) -> RhaiResult; - -/// Reduce an array by iterating through all elements while applying a function named by `reducer`. -/// -/// # Function Parameters -/// -/// A function with the same name as the value of `reducer` must exist taking these parameters: -/// -/// * `result`: accumulated result, starting with the value of `initial` -/// * `element`: copy of array element -/// * `index` _(optional)_: current index in the array -/// -/// # Example -/// -/// ```rhai -/// fn process(r, x) { x + r } -/// -/// fn process_extra(r, x, i) { x + i + r } -/// -/// let x = [1, 2, 3, 4, 5]; -/// -/// let y = x.reduce("process", 5); -/// -/// print(y); // prints 20 -/// -/// let y = x.reduce("process_extra", 5); -/// -/// print(y); // prints 30 -/// ``` -fn reduce(array: Array, reducer: String, initial: ?) -> RhaiResult; - -/// Reduce an array by iterating through all elements while applying the `reducer` function. -/// -/// # Function Parameters -/// -/// * `result`: accumulated result, starting with the value of `initial` -/// * `element`: copy of array element -/// * `index` _(optional)_: current index in the array -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 5]; -/// -/// let y = x.reduce(|r, v| v + r, 5); -/// -/// print(y); // prints 20 -/// -/// let y = x.reduce(|r, v, i| v + i + r, 5); -/// -/// print(y); // prints 30 -/// ``` -fn reduce(array: Array, reducer: FnPtr, initial: ?) -> RhaiResult; - -/// Reduce an array by iterating through all elements, in _reverse_ order, -/// while applying a function named by `reducer`. -/// -/// # Function Parameters -/// -/// A function with the same name as the value of `reducer` must exist taking these parameters: -/// -/// * `result`: accumulated result, initially `()` -/// * `element`: copy of array element -/// * `index` _(optional)_: current index in the array -/// -/// # Example -/// -/// ```rhai -/// fn process(r, x) { -/// x + (r ?? 0) -/// } -/// fn process_extra(r, x, i) { -/// x + i + (r ?? 0) -/// } -/// -/// let x = [1, 2, 3, 4, 5]; -/// -/// let y = x.reduce_rev("process"); -/// -/// print(y); // prints 15 -/// -/// let y = x.reduce_rev("process_extra"); -/// -/// print(y); // prints 25 -/// ``` -fn reduce_rev(array: Array, reducer: String) -> RhaiResult; - -/// Reduce an array by iterating through all elements, in _reverse_ order, -/// while applying the `reducer` function. -/// -/// # Function Parameters -/// -/// * `result`: accumulated result, initially `()` -/// * `element`: copy of array element -/// * `index` _(optional)_: current index in the array -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 5]; -/// -/// let y = x.reduce_rev(|r, v| v + (r ?? 0)); -/// -/// print(y); // prints 15 -/// -/// let y = x.reduce_rev(|r, v, i| v + i + (r ?? 0)); -/// -/// print(y); // prints 25 -/// ``` -fn reduce_rev(array: Array, reducer: FnPtr) -> RhaiResult; - -/// Reduce an array by iterating through all elements, in _reverse_ order, -/// while applying a function named by `reducer`. -/// -/// # Function Parameters -/// -/// A function with the same name as the value of `reducer` must exist taking these parameters: -/// -/// * `result`: accumulated result, starting with the value of `initial` -/// * `element`: copy of array element -/// * `index` _(optional)_: current index in the array -/// -/// # Example -/// -/// ```rhai -/// fn process(r, x) { x + r } -/// -/// fn process_extra(r, x, i) { x + i + r } -/// -/// let x = [1, 2, 3, 4, 5]; -/// -/// let y = x.reduce_rev("process", 5); -/// -/// print(y); // prints 20 -/// -/// let y = x.reduce_rev("process_extra", 5); -/// -/// print(y); // prints 30 -/// ``` -fn reduce_rev(array: Array, reducer: String, initial: ?) -> RhaiResult; - -/// Reduce an array by iterating through all elements, in _reverse_ order, -/// while applying the `reducer` function. -/// -/// # Function Parameters -/// -/// * `result`: accumulated result, starting with the value of `initial` -/// * `element`: copy of array element -/// * `index` _(optional)_: current index in the array -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 5]; -/// -/// let y = x.reduce_rev(|r, v| v + r, 5); -/// -/// print(y); // prints 20 -/// -/// let y = x.reduce_rev(|r, v, i| v + i + r, 5); -/// -/// print(y); // prints 30 -/// ``` -fn reduce_rev(array: Array, reducer: FnPtr, initial: ?) -> RhaiResult; - -/// Remove the element at the specified `index` from the array and return it. -/// -/// * If `index` < 0, position counts from the end of the array (`-1` is the last element). -/// * If `index` < -length of array, `()` is returned. -/// * If `index` ≥ length of array, `()` is returned. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3]; -/// -/// print(x.remove(1)); // prints 2 -/// -/// print(x); // prints "[1, 3]" -/// -/// print(x.remove(-2)); // prints 1 -/// -/// print(x); // prints "[3]" -/// ``` -fn remove(array: Array, index: int) -> ?; - -/// Remove the byte at the specified `index` from the BLOB and return it. -/// -/// * If `index` < 0, position counts from the end of the BLOB (`-1` is the last byte). -/// * If `index` < -length of BLOB, zero is returned. -/// * If `index` ≥ length of BLOB, zero is returned. -/// -/// # Example -/// -/// ```rhai -/// let b = blob(); -/// -/// b += 1; b += 2; b += 3; b += 4; b += 5; -/// -/// print(x.remove(1)); // prints 2 -/// -/// print(x); // prints "[01030405]" -/// -/// print(x.remove(-2)); // prints 4 -/// -/// print(x); // prints "[010305]" -/// ``` -fn remove(blob: Blob, index: int) -> int; - -/// Remove any property of the specified `name` from the object map, returning its value. -/// -/// If the property does not exist, `()` is returned. -/// -/// # Example -/// -/// ```rhai -/// let m = #{a:1, b:2, c:3}; -/// -/// let x = m.remove("b"); -/// -/// print(x); // prints 2 -/// -/// print(m); // prints "#{a:1, c:3}" -/// ``` -fn remove(map: Map, property: String) -> ?; - -/// Remove all occurrences of a character from the string. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world! hello, foobar!"; -/// -/// text.remove("o"); -/// -/// print(text); // prints "hell, wrld! hell, fbar!" -/// ``` -fn remove(string: String, character: char) -> (); - -/// Remove all occurrences of a sub-string from the string. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world! hello, foobar!"; -/// -/// text.remove("hello"); -/// -/// print(text); // prints ", world! , foobar!" -/// ``` -fn remove(string: String, sub_string: String) -> (); - -/// Replace all occurrences of the specified character in the string with another character. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world! hello, foobar!"; -/// -/// text.replace("l", '*'); -/// -/// print(text); // prints "he**o, wor*d! he**o, foobar!" -/// ``` -fn replace(string: String, find_character: char, substitute_character: char) -> (); - -/// Replace all occurrences of the specified character in the string with another string. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world! hello, foobar!"; -/// -/// text.replace('l', "(^)"); -/// -/// print(text); // prints "he(^)(^)o, wor(^)d! he(^)(^)o, foobar!" -/// ``` -fn replace(string: String, find_character: char, substitute_string: String) -> (); - -/// Replace all occurrences of the specified sub-string in the string with the specified character. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world! hello, foobar!"; -/// -/// text.replace("hello", '*'); -/// -/// print(text); // prints "*, world! *, foobar!" -/// ``` -fn replace(string: String, find_string: String, substitute_character: char) -> (); - -/// Replace all occurrences of the specified sub-string in the string with another string. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world! hello, foobar!"; -/// -/// text.replace("hello", "hey"); -/// -/// print(text); // prints "hey, world! hey, foobar!" -/// ``` -fn replace(string: String, find_string: String, substitute_string: String) -> (); - -/// Remove all elements in the array that do not return `true` when applied a function named by -/// `filter` and return them as a new array. -/// -/// # Function Parameters -/// -/// A function with the same name as the value of `filter` must exist taking these parameters: -/// -/// * `element`: copy of array element -/// * `index` _(optional)_: current index in the array -/// -/// # Example -/// -/// ```rhai -/// fn large(x) { x >= 3 } -/// -/// fn screen(x, i) { x + i <= 5 } -/// -/// let x = [1, 2, 3, 4, 5]; -/// -/// let y = x.retain("large"); -/// -/// print(x); // prints "[3, 4, 5]" -/// -/// print(y); // prints "[1, 2]" -/// -/// let z = x.retain("screen"); -/// -/// print(x); // prints "[3, 4]" -/// -/// print(z); // prints "[5]" -/// ``` -fn retain(array: Array, filter: String) -> Array; - -/// Remove all elements in the array that do not return `true` when applied the `filter` -/// function and return them as a new array. -/// -/// # Function Parameters -/// -/// * `element`: copy of array element -/// * `index` _(optional)_: current index in the array -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 5]; -/// -/// let y = x.retain(|v| v >= 3); -/// -/// print(x); // prints "[3, 4, 5]" -/// -/// print(y); // prints "[1, 2]" -/// -/// let z = x.retain(|v, i| v + i <= 5); -/// -/// print(x); // prints "[3, 4]" -/// -/// print(z); // prints "[5]" -/// ``` -fn retain(array: Array, filter: FnPtr) -> Array; - -/// Remove all elements in the array not within an exclusive `range` and return them as a new array. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 5]; -/// -/// let y = x.retain(1..4); -/// -/// print(x); // prints "[2, 3, 4]" -/// -/// print(y); // prints "[1, 5]" -/// -/// let z = x.retain(1..3); -/// -/// print(x); // prints "[3, 4]" -/// -/// print(z); // prints "[1]" -/// ``` -fn retain(array: Array, range: Range) -> Array; - -/// Remove all elements in the array not within an inclusive `range` and return them as a new array. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 5]; -/// -/// let y = x.retain(1..=3); -/// -/// print(x); // prints "[2, 3, 4]" -/// -/// print(y); // prints "[1, 5]" -/// -/// let z = x.retain(1..=2); -/// -/// print(x); // prints "[3, 4]" -/// -/// print(z); // prints "[1]" -/// ``` -fn retain(array: Array, range: RangeInclusive) -> Array; - -/// Remove all bytes in the BLOB not within an exclusive `range` and return them as a new BLOB. -/// -/// # Example -/// -/// ```rhai -/// let b1 = blob(); -/// -/// b1 += 1; b1 += 2; b1 += 3; b1 += 4; b1 += 5; -/// -/// let b2 = b1.retain(1..4); -/// -/// print(b1); // prints "[020304]" -/// -/// print(b2); // prints "[0105]" -/// -/// let b3 = b1.retain(1..3); -/// -/// print(b1); // prints "[0304]" -/// -/// print(b2); // prints "[01]" -/// ``` -fn retain(blob: Blob, range: Range) -> Blob; - -/// Remove all bytes in the BLOB not within an inclusive `range` and return them as a new BLOB. -/// -/// # Example -/// -/// ```rhai -/// let b1 = blob(); -/// -/// b1 += 1; b1 += 2; b1 += 3; b1 += 4; b1 += 5; -/// -/// let b2 = b1.retain(1..=3); -/// -/// print(b1); // prints "[020304]" -/// -/// print(b2); // prints "[0105]" -/// -/// let b3 = b1.retain(1..=2); -/// -/// print(b1); // prints "[0304]" -/// -/// print(b2); // prints "[01]" -/// ``` -fn retain(blob: Blob, range: RangeInclusive) -> Blob; - -/// Remove all elements not within a portion of the array and return them as a new array. -/// -/// * If `start` < 0, position counts from the end of the array (`-1` is the last element). -/// * If `start` < -length of array, position counts from the beginning of the array. -/// * If `start` ≥ length of array, all elements are removed returned. -/// * If `len` ≤ 0, all elements are removed and returned. -/// * If `start` position + `len` ≥ length of array, entire portion of the array before the `start` position is removed and returned. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 5]; -/// -/// let y = x.retain(1, 2); -/// -/// print(x); // prints "[2, 3]" -/// -/// print(y); // prints "[1, 4, 5]" -/// -/// let z = x.retain(-1, 1); -/// -/// print(x); // prints "[3]" -/// -/// print(z); // prints "[2]" -/// ``` -fn retain(array: Array, start: int, len: int) -> Array; - -/// Remove all bytes not within a portion of the BLOB and return them as a new BLOB. -/// -/// * If `start` < 0, position counts from the end of the BLOB (`-1` is the last byte). -/// * If `start` < -length of BLOB, position counts from the beginning of the BLOB. -/// * If `start` ≥ length of BLOB, all elements are removed returned. -/// * If `len` ≤ 0, all elements are removed and returned. -/// * If `start` position + `len` ≥ length of BLOB, entire portion of the BLOB before the `start` position is removed and returned. -/// -/// # Example -/// -/// ```rhai -/// let b1 = blob(); -/// -/// b1 += 1; b1 += 2; b1 += 3; b1 += 4; b1 += 5; -/// -/// let b2 = b1.retain(1, 2); -/// -/// print(b1); // prints "[0203]" -/// -/// print(b2); // prints "[010405]" -/// -/// let b3 = b1.retain(-1, 1); -/// -/// print(b1); // prints "[03]" -/// -/// print(b3); // prints "[02]" -/// ``` -fn retain(blob: Blob, start: int, len: int) -> Blob; - -/// Reverse all the elements in the array. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 5]; -/// -/// x.reverse(); -/// -/// print(x); // prints "[5, 4, 3, 2, 1]" -/// ``` -fn reverse(array: Array) -> (); - -/// Reverse the BLOB. -/// -/// # Example -/// -/// ```rhai -/// let b = blob(); -/// -/// b += 1; b += 2; b += 3; b += 4; b += 5; -/// -/// print(b); // prints "[0102030405]" -/// -/// b.reverse(); -/// -/// print(b); // prints "[0504030201]" -/// ``` -fn reverse(blob: Blob) -> (); - -/// Return the nearest whole number closest to the floating-point number. -/// Rounds away from zero. -fn round(x: float) -> float; - -/// Set the element at the `index` position in the array to a new `value`. -/// -/// * If `index` < 0, position counts from the end of the array (`-1` is the last element). -/// * If `index` < -length of array, the array is not modified. -/// * If `index` ≥ length of array, the array is not modified. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3]; -/// -/// x.set(0, 42); -/// -/// print(x); // prints "[42, 2, 3]" -/// -/// x.set(-3, 0); -/// -/// print(x); // prints "[0, 2, 3]" -/// -/// x.set(99, 123); -/// -/// print(x); // prints "[0, 2, 3]" -/// ``` -fn set(array: Array, index: int, value: ?) -> (); - -/// Set the particular `index` position in the BLOB to a new byte `value`. -/// -/// * If `index` < 0, position counts from the end of the BLOB (`-1` is the last byte). -/// * If `index` < -length of BLOB, the BLOB is not modified. -/// * If `index` ≥ length of BLOB, the BLOB is not modified. -/// -/// # Example -/// -/// ```rhai -/// let b = blob(); -/// -/// b += 1; b += 2; b += 3; b += 4; b += 5; -/// -/// b.set(0, 0x42); -/// -/// print(b); // prints "[4202030405]" -/// -/// b.set(-3, 0); -/// -/// print(b); // prints "[4202000405]" -/// -/// b.set(99, 123); -/// -/// print(b); // prints "[4202000405]" -/// ``` -fn set(blob: Blob, index: int, value: int) -> (); - -/// Set the value of the `property` in the object map to a new `value`. -/// -/// If `property` does not exist in the object map, it is added. -/// -/// # Example -/// -/// ```rhai -/// let m = #{a: 1, b: 2, c: 3}; -/// -/// m.set("b", 42)' -/// -/// print(m); // prints "#{a: 1, b: 42, c: 3}" -/// -/// x.set("x", 0); -/// -/// print(m); // prints "#{a: 1, b: 42, c: 3, x: 0}" -/// ``` -fn set(map: Map, property: String, value: ?) -> (); - -/// Set the `index` position in the string to a new `character`. -/// -/// * If `index` < 0, position counts from the end of the string (`-1` is the last character). -/// * If `index` < -length of string, the string is not modified. -/// * If `index` ≥ length of string, the string is not modified. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world!"; -/// -/// text.set(3, 'x'); -/// -/// print(text); // prints "helxo, world!" -/// -/// text.set(-3, 'x'); -/// -/// print(text); // prints "hello, worxd!" -/// -/// text.set(99, 'x'); -/// -/// print(text); // prints "hello, worxd!" -/// ``` -fn set(string: String, index: int, character: char) -> (); - -/// Set the _tag_ of a `Dynamic` value. -/// -/// # Example -/// -/// ```rhai -/// let x = "hello, world!"; -/// -/// x.tag = 42; -/// -/// print(x.tag); // prints 42 -/// ``` -fn set tag(value: ?, tag: int) -> (); - -/// Set the specified `bit` in the number if the new value is `true`. -/// Clear the `bit` if the new value is `false`. -/// -/// If `bit` < 0, position counts from the MSB (Most Significant Bit). -/// -/// # Example -/// -/// ```rhai -/// let x = 123456; -/// -/// x.set_bit(5, true); -/// -/// print(x); // prints 123488 -/// -/// x.set_bit(6, false); -/// -/// print(x); // prints 123424 -/// -/// x.set_bit(-48, false); -/// -/// print(x); // prints 57888 on 64-bit -/// ``` -fn set_bit(value: int, bit: int, new_value: bool) -> (); - -/// Replace an exclusive range of bits in the number with a new value. -/// -/// # Example -/// -/// ```rhai -/// let x = 123456; -/// -/// x.set_bits(5..10, 42); -/// -/// print(x); // print 123200 -/// ``` -fn set_bits(value: int, range: Range, new_value: int) -> (); - -/// Replace an inclusive range of bits in the number with a new value. -/// -/// # Example -/// -/// ```rhai -/// let x = 123456; -/// -/// x.set_bits(5..=9, 42); -/// -/// print(x); // print 123200 -/// ``` -fn set_bits(value: int, range: RangeInclusive, new_value: int) -> (); - -/// Replace a portion of bits in the number with a new value. -/// -/// * If `start` < 0, position counts from the MSB (Most Significant Bit). -/// * If `bits` ≤ 0, the number is not modified. -/// * If `start` position + `bits` ≥ total number of bits, the bits after the `start` position are replaced. -/// -/// # Example -/// -/// ```rhai -/// let x = 123456; -/// -/// x.set_bits(5, 8, 42); -/// -/// print(x); // prints 124224 -/// -/// x.set_bits(-16, 10, 42); -/// -/// print(x); // prints 11821949021971776 on 64-bit -/// ``` -fn set_bits(value: int, bit: int, bits: int, new_value: int) -> (); - -/// Set the _tag_ of a `Dynamic` value. -/// -/// # Example -/// -/// ```rhai -/// let x = "hello, world!"; -/// -/// x.tag = 42; -/// -/// print(x.tag); // prints 42 -/// ``` -fn set_tag(value: ?, tag: int) -> (); - -/// Remove the first element from the array and return it. -/// -/// If the array is empty, `()` is returned. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3]; -/// -/// print(x.shift()); // prints 1 -/// -/// print(x); // prints "[2, 3]" -/// ``` -fn shift(array: Array) -> ?; - -/// Remove the first byte from the BLOB and return it. -/// -/// If the BLOB is empty, zero is returned. -/// -/// # Example -/// -/// ```rhai -/// let b = blob(); -/// -/// b += 1; b += 2; b += 3; b += 4; b += 5; -/// -/// print(b.shift()); // prints 1 -/// -/// print(b); // prints "[02030405]" -/// ``` -fn shift(blob: Blob) -> int; - -/// Return the sign (as an integer) of the number according to the following: -/// -/// * `0` if the number is zero -/// * `1` if the number is positive -/// * `-1` if the number is negative -fn sign(x: int) -> int; - -/// Return the sign (as an integer) of the floating-point number according to the following: -/// -/// * `0` if the number is zero -/// * `1` if the number is positive -/// * `-1` if the number is negative -fn sign(x: f32) -> int; - -/// Return the sign (as an integer) of the floating-point number according to the following: -/// -/// * `0` if the number is zero -/// * `1` if the number is positive -/// * `-1` if the number is negative -fn sign(x: float) -> int; - -/// Return the sign (as an integer) of the number according to the following: -/// -/// * `0` if the number is zero -/// * `1` if the number is positive -/// * `-1` if the number is negative -fn sign(x: i128) -> int; - -/// Return the sign (as an integer) of the number according to the following: -/// -/// * `0` if the number is zero -/// * `1` if the number is positive -/// * `-1` if the number is negative -fn sign(x: i16) -> int; - -/// Return the sign (as an integer) of the number according to the following: -/// -/// * `0` if the number is zero -/// * `1` if the number is positive -/// * `-1` if the number is negative -fn sign(x: i32) -> int; - -/// Return the sign (as an integer) of the number according to the following: -/// -/// * `0` if the number is zero -/// * `1` if the number is positive -/// * `-1` if the number is negative -fn sign(x: i8) -> int; - -/// Return the sine of the floating-point number in radians. -fn sin(x: float) -> float; - -/// Return the hyperbolic sine of the floating-point number in radians. -fn sinh(x: float) -> float; - -/// Block the current thread for a particular number of `seconds`. -fn sleep(seconds: int) -> (); - -/// Block the current thread for a particular number of `seconds`. -fn sleep(seconds: float) -> (); - -/// Return `true` if any element in the array that returns `true` when applied a function named -/// by `filter`. -/// -/// # Function Parameters -/// -/// A function with the same name as the value of `filter` must exist taking these parameters: -/// -/// * `element`: copy of array element -/// * `index` _(optional)_: current index in the array -/// -/// # Example -/// -/// ```rhai -/// fn large(x) { x > 3 } -/// -/// fn huge(x) { x > 10 } -/// -/// fn screen(x, i) { i > x } -/// -/// let x = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 5]; -/// -/// print(x.some("large")); // prints true -/// -/// print(x.some("huge")); // prints false -/// -/// print(x.some("screen")); // prints true -/// ``` -fn some(array: Array, filter: String) -> bool; - -/// Return `true` if any element in the array that returns `true` when applied the `filter` function. -/// -/// # Function Parameters -/// -/// * `element`: copy of array element -/// * `index` _(optional)_: current index in the array -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 5]; -/// -/// print(x.some(|v| v > 3)); // prints true -/// -/// print(x.some(|v| v > 10)); // prints false -/// -/// print(x.some(|v, i| i > v)); // prints true -/// ``` -fn some(array: Array, filter: FnPtr) -> bool; - -/// Sort the array. -/// -/// All elements in the array must be of the same data type. -/// -/// # Supported Data Types -/// -/// * integer numbers -/// * floating-point numbers -/// * decimal numbers -/// * characters -/// * strings -/// * booleans -/// * `()` -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 3, 5, 7, 9, 2, 4, 6, 8, 10]; -/// -/// x.sort(); -/// -/// print(x); // prints "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]" -/// ``` -fn sort(array: Array) -> (); - -/// Sort the array based on applying a function named by `comparer`. -/// -/// # Function Parameters -/// -/// A function with the same name as the value of `comparer` must exist taking these parameters: -/// -/// * `element1`: copy of the current array element to compare -/// * `element2`: copy of the next array element to compare -/// -/// ## Return Value -/// -/// * Any integer > 0 if `element1 > element2` -/// * Zero if `element1 == element2` -/// * Any integer < 0 if `element1 < element2` -/// -/// # Example -/// -/// ```rhai -/// fn reverse(a, b) { -/// if a > b { -/// -1 -/// } else if a < b { -/// 1 -/// } else { -/// 0 -/// } -/// } -/// let x = [1, 3, 5, 7, 9, 2, 4, 6, 8, 10]; -/// -/// x.sort("reverse"); -/// -/// print(x); // prints "[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]" -/// ``` -fn sort(array: Array, comparer: String) -> (); - -/// Sort the array based on applying the `comparer` function. -/// -/// # Function Parameters -/// -/// * `element1`: copy of the current array element to compare -/// * `element2`: copy of the next array element to compare -/// -/// ## Return Value -/// -/// * Any integer > 0 if `element1 > element2` -/// * Zero if `element1 == element2` -/// * Any integer < 0 if `element1 < element2` -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 3, 5, 7, 9, 2, 4, 6, 8, 10]; -/// -/// // Do comparisons in reverse -/// x.sort(|a, b| if a > b { -1 } else if a < b { 1 } else { 0 }); -/// -/// print(x); // prints "[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]" -/// ``` -fn sort(array: Array, comparer: FnPtr) -> (); - -/// Replace an exclusive range of the array with another array. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 5]; -/// let y = [7, 8, 9, 10]; -/// -/// x.splice(1..3, y); -/// -/// print(x); // prints "[1, 7, 8, 9, 10, 4, 5]" -/// ``` -fn splice(array: Array, range: Range, replace: Array) -> (); - -/// Replace an inclusive range of the array with another array. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 5]; -/// let y = [7, 8, 9, 10]; -/// -/// x.splice(1..=3, y); -/// -/// print(x); // prints "[1, 7, 8, 9, 10, 5]" -/// ``` -fn splice(array: Array, range: RangeInclusive, replace: Array) -> (); - -/// Replace an exclusive `range` of the BLOB with another BLOB. -/// -/// # Example -/// -/// ```rhai -/// let b1 = blob(10, 0x42); -/// let b2 = blob(5, 0x18); -/// -/// b1.splice(1..4, b2); -/// -/// print(b1); // prints "[4218181818184242 42424242]" -/// ``` -fn splice(blob: Blob, range: Range, replace: Blob) -> (); - -/// Replace an inclusive `range` of the BLOB with another BLOB. -/// -/// # Example -/// -/// ```rhai -/// let b1 = blob(10, 0x42); -/// let b2 = blob(5, 0x18); -/// -/// b1.splice(1..=4, b2); -/// -/// print(b1); // prints "[4218181818184242 424242]" -/// ``` -fn splice(blob: Blob, range: RangeInclusive, replace: Blob) -> (); - -/// Replace a portion of the array with another array. -/// -/// * If `start` < 0, position counts from the end of the array (`-1` is the last element). -/// * If `start` < -length of array, position counts from the beginning of the array. -/// * If `start` ≥ length of array, the other array is appended to the end of the array. -/// * If `len` ≤ 0, the other array is inserted into the array at the `start` position without replacing any element. -/// * If `start` position + `len` ≥ length of array, entire portion of the array after the `start` position is replaced. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 5]; -/// let y = [7, 8, 9, 10]; -/// -/// x.splice(1, 2, y); -/// -/// print(x); // prints "[1, 7, 8, 9, 10, 4, 5]" -/// -/// x.splice(-5, 4, y); -/// -/// print(x); // prints "[1, 7, 7, 8, 9, 10, 5]" -/// ``` -fn splice(array: Array, start: int, len: int, replace: Array) -> (); - -/// Replace a portion of the BLOB with another BLOB. -/// -/// * If `start` < 0, position counts from the end of the BLOB (`-1` is the last byte). -/// * If `start` < -length of BLOB, position counts from the beginning of the BLOB. -/// * If `start` ≥ length of BLOB, the other BLOB is appended to the end of the BLOB. -/// * If `len` ≤ 0, the other BLOB is inserted into the BLOB at the `start` position without replacing anything. -/// * If `start` position + `len` ≥ length of BLOB, entire portion of the BLOB after the `start` position is replaced. -/// -/// # Example -/// -/// ```rhai -/// let b1 = blob(10, 0x42); -/// let b2 = blob(5, 0x18); -/// -/// b1.splice(1, 3, b2); -/// -/// print(b1); // prints "[4218181818184242 42424242]" -/// -/// b1.splice(-5, 4, b2); -/// -/// print(b1); // prints "[4218181818184218 1818181842]" -/// ``` -fn splice(blob: Blob, start: int, len: int, replace: Blob) -> (); - -/// Split the string into segments based on whitespaces, returning an array of the segments. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world! hello, foo!"; -/// -/// print(text.split()); // prints ["hello,", "world!", "hello,", "foo!"] -/// ``` -fn split(string: String) -> Array; - -/// Cut off the array at `index` and return it as a new array. -/// -/// * If `index` < 0, position counts from the end of the array (`-1` is the last element). -/// * If `index` is zero, the entire array is cut and returned. -/// * If `index` < -length of array, the entire array is cut and returned. -/// * If `index` ≥ length of array, nothing is cut from the array and an empty array is returned. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 5]; -/// -/// let y = x.split(2); -/// -/// print(y); // prints "[3, 4, 5]" -/// -/// print(x); // prints "[1, 2]" -/// ``` -fn split(array: Array, index: int) -> Array; - -/// Cut off the BLOB at `index` and return it as a new BLOB. -/// -/// * If `index` < 0, position counts from the end of the BLOB (`-1` is the last byte). -/// * If `index` is zero, the entire BLOB is cut and returned. -/// * If `index` < -length of BLOB, the entire BLOB is cut and returned. -/// * If `index` ≥ length of BLOB, nothing is cut from the BLOB and an empty BLOB is returned. -/// -/// # Example -/// -/// ```rhai -/// let b1 = blob(); -/// -/// b1 += 1; b1 += 2; b1 += 3; b1 += 4; b1 += 5; -/// -/// let b2 = b1.split(2); -/// -/// print(b2); // prints "[030405]" -/// -/// print(b1); // prints "[0102]" -/// ``` -fn split(blob: Blob, index: int) -> Blob; - -/// Split the string into two at the specified `index` position and return it both strings -/// as an array. -/// -/// The character at the `index` position (if any) is returned in the _second_ string. -/// -/// * If `index` < 0, position counts from the end of the string (`-1` is the last character). -/// * If `index` < -length of string, it is equivalent to cutting at position 0. -/// * If `index` ≥ length of string, it is equivalent to cutting at the end of the string. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world!"; -/// -/// print(text.split(6)); // prints ["hello,", " world!"] -/// -/// print(text.split(13)); // prints ["hello, world!", ""] -/// -/// print(text.split(-6)); // prints ["hello, ", "world!"] -/// -/// print(text.split(-99)); // prints ["", "hello, world!"] -/// ``` -fn split(string: String, index: int) -> Array; - -/// Split the string into segments based on a `delimiter` string, returning an array of the segments. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world! hello, foo!"; -/// -/// print(text.split("ll")); // prints ["he", "o, world! he", "o, foo!"] -/// ``` -fn split(string: String, delimiter: String) -> Array; - -/// Split the string into segments based on a `delimiter` character, returning an array of the segments. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world! hello, foo!"; -/// -/// print(text.split('l')); // prints ["he", "", "o, wor", "d! he", "", "o, foo!"] -/// ``` -fn split(string: String, delimiter: char) -> Array; - -/// Split the string into at most the specified number of `segments` based on a `delimiter` string, -/// returning an array of the segments. -/// -/// If `segments` < 1, only one segment is returned. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world! hello, foo!"; -/// -/// print(text.split("ll", 2)); // prints ["he", "o, world! hello, foo!"] -/// ``` -fn split(string: String, delimiter: String, segments: int) -> Array; - -/// Split the string into at most the specified number of `segments` based on a `delimiter` character, -/// returning an array of the segments. -/// -/// If `segments` < 1, only one segment is returned. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world! hello, foo!"; -/// -/// print(text.split('l', 3)); // prints ["he", "", "o, world! hello, foo!"] -/// ``` -fn split(string: String, delimiter: char, segments: int) -> Array; - -/// Split the string into segments based on a `delimiter` string, returning an array of the -/// segments in _reverse_ order. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world! hello, foo!"; -/// -/// print(text.split_rev("ll")); // prints ["o, foo!", "o, world! he", "he"] -/// ``` -fn split_rev(string: String, delimiter: String) -> Array; - -/// Split the string into segments based on a `delimiter` character, returning an array of -/// the segments in _reverse_ order. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world! hello, foo!"; -/// -/// print(text.split_rev('l')); // prints ["o, foo!", "", "d! he", "o, wor", "", "he"] -/// ``` -fn split_rev(string: String, delimiter: char) -> Array; - -/// Split the string into at most a specified number of `segments` based on a `delimiter` string, -/// returning an array of the segments in _reverse_ order. -/// -/// If `segments` < 1, only one segment is returned. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world! hello, foo!"; -/// -/// print(text.split_rev("ll", 2)); // prints ["o, foo!", "hello, world! he"] -/// ``` -fn split_rev(string: String, delimiter: String, segments: int) -> Array; - -/// Split the string into at most the specified number of `segments` based on a `delimiter` character, -/// returning an array of the segments. -/// -/// If `segments` < 1, only one segment is returned. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world! hello, foo!"; -/// -/// print(text.split('l', 3)); // prints ["o, foo!", "", "hello, world! he" -/// ``` -fn split_rev(string: String, delimiter: char, segments: int) -> Array; - -/// Return the square root of the floating-point number. -fn sqrt(x: float) -> float; - -/// Return the start of the exclusive range. -fn start(range: ExclusiveRange) -> int; - -/// Return the start of the inclusive range. -fn start(range: InclusiveRange) -> int; - -/// Return `true` if the string starts with a specified string. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world!"; -/// -/// print(text.starts_with("hello")); // prints true -/// -/// print(text.starts_with("world")); // prints false -/// ``` -fn starts_with(string: String, match_string: String) -> bool; - -/// Copy an exclusive range of characters from the string and return it as a new string. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world!"; -/// -/// print(text.sub_string(3..7)); // prints "lo, " -/// ``` -fn sub_string(string: String, range: Range) -> String; - -/// Copy an inclusive range of characters from the string and return it as a new string. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world!"; -/// -/// print(text.sub_string(3..=7)); // prints "lo, w" -/// ``` -fn sub_string(string: String, range: RangeInclusive) -> String; - -/// Copy a portion of the string beginning at the `start` position till the end and return it as -/// a new string. -/// -/// * If `start` < 0, position counts from the end of the string (`-1` is the last character). -/// * If `start` < -length of string, the entire string is copied and returned. -/// * If `start` ≥ length of string, an empty string is returned. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world!"; -/// -/// print(text.sub_string(5)); // prints ", world!" -/// -/// print(text.sub_string(-5)); // prints "orld!" -/// ``` -fn sub_string(string: String, start: int) -> String; - -/// Copy a portion of the string and return it as a new string. -/// -/// * If `start` < 0, position counts from the end of the string (`-1` is the last character). -/// * If `start` < -length of string, position counts from the beginning of the string. -/// * If `start` ≥ length of string, an empty string is returned. -/// * If `len` ≤ 0, an empty string is returned. -/// * If `start` position + `len` ≥ length of string, entire portion of the string after the `start` position is copied and returned. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world!"; -/// -/// print(text.sub_string(3, 4)); // prints "lo, " -/// -/// print(text.sub_string(-8, 3)); // prints ", w" -/// ``` -fn sub_string(string: String, start: int, len: int) -> String; - -/// Return the _tag_ of a `Dynamic` value. -/// -/// # Example -/// -/// ```rhai -/// let x = "hello, world!"; -/// -/// x.tag = 42; -/// -/// print(x.tag); // prints 42 -/// ``` -fn tag(value: ?) -> int; - -/// Return the tangent of the floating-point number in radians. -fn tan(x: float) -> float; - -/// Return the hyperbolic tangent of the floating-point number in radians. -fn tanh(x: float) -> float; - -/// Create a timestamp containing the current system time. -/// -/// # Example -/// -/// ```rhai -/// let now = timestamp(); -/// -/// sleep(10.0); // sleep for 10 seconds -/// -/// print(now.elapsed); // prints 10.??? -/// ``` -fn timestamp() -> Instant; - -/// Convert the BLOB into an array of integers. -/// -/// # Example -/// -/// ```rhai -/// let b = blob(5, 0x42); -/// -/// let x = b.to_array(); -/// -/// print(x); // prints "[66, 66, 66, 66, 66]" -/// ``` -fn to_array(blob: Blob) -> Array; - -/// Convert the `value` into a string in binary format. -fn to_binary(value: i128) -> String; - -/// Convert the `value` into a string in binary format. -fn to_binary(value: i16) -> String; - -/// Convert the `value` into a string in binary format. -fn to_binary(value: i32) -> String; - -/// Convert the `value` into a string in binary format. -fn to_binary(value: int) -> String; - -/// Convert the `value` into a string in binary format. -fn to_binary(value: i8) -> String; - -/// Convert the `value` into a string in binary format. -fn to_binary(value: u128) -> String; - -/// Convert the `value` into a string in binary format. -fn to_binary(value: u16) -> String; - -/// Convert the `value` into a string in binary format. -fn to_binary(value: u32) -> String; - -/// Convert the `value` into a string in binary format. -fn to_binary(value: u64) -> String; - -/// Convert the `value` into a string in binary format. -fn to_binary(value: u8) -> String; - -/// Convert the string into an UTF-8 encoded byte-stream as a BLOB. -/// -/// # Example -/// -/// ```rhai -/// let text = "朝には紅顔ありて夕べには白骨となる"; -/// -/// let bytes = text.to_blob(); -/// -/// print(bytes.len()); // prints 51 -/// ``` -fn to_blob(string: String) -> Blob; - -/// Return an array containing all the characters of the string. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello"; -/// -/// print(text.to_chars()); // prints "['h', 'e', 'l', 'l', 'o']" -/// ``` -fn to_chars(string: String) -> Array; - -/// Convert the array into a string. -fn to_debug(array: Array) -> String; - -/// Convert the string into debug format. -fn to_debug(character: char) -> String; - -/// Convert the function pointer into a string in debug format. -fn to_debug(f: FnPtr) -> String; - -/// Convert the value of the `item` into a string in debug format. -fn to_debug(item: ?) -> String; - -/// Convert the object map into a string. -fn to_debug(map: Map) -> String; - -/// Convert the value of `number` into a string. -fn to_debug(number: f32) -> String; - -/// Convert the value of `number` into a string. -fn to_debug(number: float) -> String; - -/// Convert the string into debug format. -fn to_debug(string: String) -> String; - -/// Convert the unit into a string in debug format. -fn to_debug(unit: ()) -> String; - -/// Convert the boolean value into a string in debug format. -fn to_debug(value: bool) -> String; - -/// Convert radians to degrees. -fn to_degrees(x: float) -> float; - -/// Convert the 32-bit floating-point number to 64-bit. -fn to_float(x: f32) -> float; - -fn to_float(x: i128) -> float; - -fn to_float(x: i16) -> float; - -fn to_float(x: i32) -> float; - -fn to_float(x: int) -> float; - -fn to_float(x: i8) -> float; - -fn to_float(x: u128) -> float; - -fn to_float(x: u16) -> float; - -fn to_float(x: u32) -> float; - -fn to_float(x: u8) -> float; - -/// Convert the `value` into a string in hex format. -fn to_hex(value: i128) -> String; - -/// Convert the `value` into a string in hex format. -fn to_hex(value: i16) -> String; - -/// Convert the `value` into a string in hex format. -fn to_hex(value: i32) -> String; - -/// Convert the `value` into a string in hex format. -fn to_hex(value: int) -> String; - -/// Convert the `value` into a string in hex format. -fn to_hex(value: i8) -> String; - -/// Convert the `value` into a string in hex format. -fn to_hex(value: u128) -> String; - -/// Convert the `value` into a string in hex format. -fn to_hex(value: u16) -> String; - -/// Convert the `value` into a string in hex format. -fn to_hex(value: u32) -> String; - -/// Convert the `value` into a string in hex format. -fn to_hex(value: u64) -> String; - -/// Convert the `value` into a string in hex format. -fn to_hex(value: u8) -> String; - -fn to_int(x: char) -> int; - -/// Convert the floating-point number into an integer. -fn to_int(x: f32) -> int; - -/// Convert the floating-point number into an integer. -fn to_int(x: float) -> int; - -fn to_int(x: i128) -> int; - -fn to_int(x: i16) -> int; - -fn to_int(x: i32) -> int; - -fn to_int(x: int) -> int; - -fn to_int(x: i8) -> int; - -fn to_int(x: u128) -> int; - -fn to_int(x: u16) -> int; - -fn to_int(x: u32) -> int; - -fn to_int(x: u64) -> int; - -fn to_int(x: u8) -> int; - -/// Return the JSON representation of the object map. -/// -/// # Data types -/// -/// Only the following data types should be kept inside the object map: -/// `INT`, `FLOAT`, `ImmutableString`, `char`, `bool`, `()`, `Array`, `Map`. -/// -/// # Errors -/// -/// Data types not supported by JSON serialize into formats that may -/// invalidate the result. -/// -/// # Example -/// -/// ```rhai -/// let m = #{a:1, b:2, c:3}; -/// -/// print(m.to_json()); // prints {"a":1, "b":2, "c":3} -/// ``` -fn to_json(map: Map) -> String; - -/// Convert the character to lower-case and return it as a new character. -/// -/// # Example -/// -/// ```rhai -/// let ch = 'A'; -/// -/// print(ch.to_lower()); // prints 'a' -/// -/// print(ch); // prints 'A' -/// ``` -fn to_lower(character: char) -> char; - -/// Convert the string to all lower-case and return it as a new string. -/// -/// # Example -/// -/// ```rhai -/// let text = "HELLO, WORLD!" -/// -/// print(text.to_lower()); // prints "hello, world!" -/// -/// print(text); // prints "HELLO, WORLD!" -/// ``` -fn to_lower(string: String) -> String; - -/// Convert the `value` into a string in octal format. -fn to_octal(value: i128) -> String; - -/// Convert the `value` into a string in octal format. -fn to_octal(value: i16) -> String; - -/// Convert the `value` into a string in octal format. -fn to_octal(value: i32) -> String; - -/// Convert the `value` into a string in octal format. -fn to_octal(value: int) -> String; - -/// Convert the `value` into a string in octal format. -fn to_octal(value: i8) -> String; - -/// Convert the `value` into a string in octal format. -fn to_octal(value: u128) -> String; - -/// Convert the `value` into a string in octal format. -fn to_octal(value: u16) -> String; - -/// Convert the `value` into a string in octal format. -fn to_octal(value: u32) -> String; - -/// Convert the `value` into a string in octal format. -fn to_octal(value: u64) -> String; - -/// Convert the `value` into a string in octal format. -fn to_octal(value: u8) -> String; - -/// Convert degrees to radians. -fn to_radians(x: float) -> float; - -/// Convert the array into a string. -fn to_string(array: Array) -> String; - -/// Return the character into a string. -fn to_string(character: char) -> String; - -/// Convert the value of the `item` into a string. -fn to_string(item: ?) -> String; - -/// Convert the object map into a string. -fn to_string(map: Map) -> String; - -/// Convert the value of `number` into a string. -fn to_string(number: f32) -> String; - -/// Convert the value of `number` into a string. -fn to_string(number: float) -> String; - -/// Return the `string`. -fn to_string(string: String) -> String; - -/// Return the empty string. -fn to_string(unit: ()) -> String; - -/// Return the boolean value into a string. -fn to_string(value: bool) -> String; - -/// Convert the character to upper-case and return it as a new character. -/// -/// # Example -/// -/// ```rhai -/// let ch = 'a'; -/// -/// print(ch.to_upper()); // prints 'A' -/// -/// print(ch); // prints 'a' -/// ``` -fn to_upper(character: char) -> char; - -/// Convert the string to all upper-case and return it as a new string. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world!" -/// -/// print(text.to_upper()); // prints "HELLO, WORLD!" -/// -/// print(text); // prints "hello, world!" -/// ``` -fn to_upper(string: String) -> String; - -/// Remove whitespace characters from both ends of the string. -/// -/// # Example -/// -/// ```rhai -/// let text = " hello "; -/// -/// text.trim(); -/// -/// print(text); // prints "hello" -/// ``` -fn trim(string: String) -> (); - -/// Cut off the array at the specified length. -/// -/// * If `len` ≤ 0, the array is cleared. -/// * If `len` ≥ length of array, the array is not truncated. -/// -/// # Example -/// -/// ```rhai -/// let x = [1, 2, 3, 4, 5]; -/// -/// x.truncate(3); -/// -/// print(x); // prints "[1, 2, 3]" -/// -/// x.truncate(10); -/// -/// print(x); // prints "[1, 2, 3]" -/// ``` -fn truncate(array: Array, len: int) -> (); - -/// Cut off the BLOB at the specified length. -/// -/// * If `len` ≤ 0, the BLOB is cleared. -/// * If `len` ≥ length of BLOB, the BLOB is not truncated. -/// -/// # Example -/// -/// ```rhai -/// let b = blob(); -/// -/// b += 1; b += 2; b += 3; b += 4; b += 5; -/// -/// b.truncate(3); -/// -/// print(b); // prints "[010203]" -/// -/// b.truncate(10); -/// -/// print(b); // prints "[010203]" -/// ``` -fn truncate(blob: Blob, len: int) -> (); - -/// Cut off the string at the specified number of characters. -/// -/// * If `len` ≤ 0, the string is cleared. -/// * If `len` ≥ length of string, the string is not truncated. -/// -/// # Example -/// -/// ```rhai -/// let text = "hello, world! hello, foobar!"; -/// -/// text.truncate(13); -/// -/// print(text); // prints "hello, world!" -/// -/// x.truncate(10); -/// -/// print(text); // prints "hello, world!" -/// ``` -fn truncate(string: String, len: int) -> (); - -/// Return an array with all the property values in the object map. -/// -/// # Example -/// -/// ```rhai -/// let m = #{a:1, b:2, c:3}; -/// -/// print(m.values()); // prints "[1, 2, 3]"" -/// ``` -fn values(map: Map) -> Array; - -/// Write an ASCII string to the bytes within an exclusive `range` in the BLOB. -/// -/// Each ASCII character encodes to one single byte in the BLOB. -/// Non-ASCII characters are ignored. -/// -/// * If number of bytes in `range` < length of `string`, extra bytes in `string` are not written. -/// * If number of bytes in `range` > length of `string`, extra bytes in `range` are not modified. -/// -/// ```rhai -/// let b = blob(8); -/// -/// b.write_ascii(1..5, "hello, world!"); -/// -/// print(b); // prints "[0068656c6c000000]" -/// ``` -fn write_ascii(blob: Blob, range: Range, string: String) -> (); - -/// Write an ASCII string to the bytes within an inclusive `range` in the BLOB. -/// -/// Each ASCII character encodes to one single byte in the BLOB. -/// Non-ASCII characters are ignored. -/// -/// * If number of bytes in `range` < length of `string`, extra bytes in `string` are not written. -/// * If number of bytes in `range` > length of `string`, extra bytes in `range` are not modified. -/// -/// ```rhai -/// let b = blob(8); -/// -/// b.write_ascii(1..=5, "hello, world!"); -/// -/// print(b); // prints "[0068656c6c6f0000]" -/// ``` -fn write_ascii(blob: Blob, range: RangeInclusive, string: String) -> (); - -/// Write an ASCII string to the bytes within an exclusive `range` in the BLOB. -/// -/// * If `start` < 0, position counts from the end of the BLOB (`-1` is the last byte). -/// * If `start` < -length of BLOB, position counts from the beginning of the BLOB. -/// * If `start` ≥ length of BLOB, the BLOB is not modified. -/// * If `len` ≤ 0, the BLOB is not modified. -/// * If `start` position + `len` ≥ length of BLOB, only the portion of the BLOB after the `start` position is modified. -/// -/// * If number of bytes in `range` < length of `string`, extra bytes in `string` are not written. -/// * If number of bytes in `range` > length of `string`, extra bytes in `range` are not modified. -/// -/// ```rhai -/// let b = blob(8); -/// -/// b.write_ascii(1, 5, "hello, world!"); -/// -/// print(b); // prints "[0068656c6c6f0000]" -/// ``` -fn write_ascii(blob: Blob, start: int, len: int, string: String) -> (); - -/// Write a `FLOAT` value to the bytes within an exclusive `range` in the BLOB -/// in big-endian byte order. -/// -/// * If number of bytes in `range` < number of bytes for `FLOAT`, extra bytes in `FLOAT` are not written. -/// * If number of bytes in `range` > number of bytes for `FLOAT`, extra bytes in `range` are not modified. -fn write_be(blob: Blob, range: Range, value: float) -> (); - -/// Write an `INT` value to the bytes within an exclusive `range` in the BLOB -/// in big-endian byte order. -/// -/// * If number of bytes in `range` < number of bytes for `INT`, extra bytes in `INT` are not written. -/// * If number of bytes in `range` > number of bytes for `INT`, extra bytes in `range` are not modified. -/// -/// ```rhai -/// let b = blob(8, 0x42); -/// -/// b.write_be_int(1..3, 0x99); -/// -/// print(b); // prints "[4200004242424242]" -/// ``` -fn write_be(blob: Blob, range: Range, value: int) -> (); - -/// Write a `FLOAT` value to the bytes within an inclusive `range` in the BLOB -/// in big-endian byte order. -/// -/// * If number of bytes in `range` < number of bytes for `FLOAT`, extra bytes in `FLOAT` are not written. -/// * If number of bytes in `range` > number of bytes for `FLOAT`, extra bytes in `range` are not modified. -fn write_be(blob: Blob, range: RangeInclusive, value: float) -> (); - -/// Write an `INT` value to the bytes within an inclusive `range` in the BLOB -/// in big-endian byte order. -/// -/// * If number of bytes in `range` < number of bytes for `INT`, extra bytes in `INT` are not written. -/// * If number of bytes in `range` > number of bytes for `INT`, extra bytes in `range` are not modified. -/// -/// ```rhai -/// let b = blob(8, 0x42); -/// -/// b.write_be_int(1..=3, 0x99); -/// -/// print(b); // prints "[4200000042424242]" -/// ``` -fn write_be(blob: Blob, range: RangeInclusive, value: int) -> (); - -/// Write a `FLOAT` value to the bytes beginning at the `start` position in the BLOB -/// in big-endian byte order. -/// -/// * If `start` < 0, position counts from the end of the BLOB (`-1` is the last byte). -/// * If `start` < -length of BLOB, position counts from the beginning of the BLOB. -/// * If `start` ≥ length of BLOB, zero is returned. -/// * If `len` ≤ 0, zero is returned. -/// * If `start` position + `len` ≥ length of BLOB, entire portion of the BLOB after the `start` position is parsed. -/// -/// * If number of bytes in `range` < number of bytes for `FLOAT`, extra bytes in `FLOAT` are not written. -/// * If number of bytes in `range` > number of bytes for `FLOAT`, extra bytes in `range` are not modified. -fn write_be(blob: Blob, start: int, len: int, value: float) -> (); - -/// Write an `INT` value to the bytes beginning at the `start` position in the BLOB -/// in big-endian byte order. -/// -/// * If `start` < 0, position counts from the end of the BLOB (`-1` is the last byte). -/// * If `start` < -length of BLOB, position counts from the beginning of the BLOB. -/// * If `start` ≥ length of BLOB, zero is returned. -/// * If `len` ≤ 0, zero is returned. -/// * If `start` position + `len` ≥ length of BLOB, entire portion of the BLOB after the `start` position is parsed. -/// -/// * If number of bytes in `range` < number of bytes for `INT`, extra bytes in `INT` are not written. -/// * If number of bytes in `range` > number of bytes for `INT`, extra bytes in `range` are not modified. -/// -/// ```rhai -/// let b = blob(8, 0x42); -/// -/// b.write_be_int(1, 3, 0x99); -/// -/// print(b); // prints "[4200000042424242]" -/// ``` -fn write_be(blob: Blob, start: int, len: int, value: int) -> (); - -/// Write a `FLOAT` value to the bytes within an exclusive `range` in the BLOB -/// in little-endian byte order. -/// -/// * If number of bytes in `range` < number of bytes for `FLOAT`, extra bytes in `FLOAT` are not written. -/// * If number of bytes in `range` > number of bytes for `FLOAT`, extra bytes in `range` are not modified. -fn write_le(blob: Blob, range: Range, value: float) -> (); - -/// Write an `INT` value to the bytes within an exclusive `range` in the BLOB -/// in little-endian byte order. -/// -/// * If number of bytes in `range` < number of bytes for `INT`, extra bytes in `INT` are not written. -/// * If number of bytes in `range` > number of bytes for `INT`, extra bytes in `range` are not modified. -/// -/// ```rhai -/// let b = blob(8); -/// -/// b.write_le_int(1..3, 0x12345678); -/// -/// print(b); // prints "[0078560000000000]" -/// ``` -fn write_le(blob: Blob, range: Range, value: int) -> (); - -/// Write a `FLOAT` value to the bytes within an inclusive `range` in the BLOB -/// in little-endian byte order. -/// -/// * If number of bytes in `range` < number of bytes for `FLOAT`, extra bytes in `FLOAT` are not written. -/// * If number of bytes in `range` > number of bytes for `FLOAT`, extra bytes in `range` are not modified. -fn write_le(blob: Blob, range: RangeInclusive, value: float) -> (); - -/// Write an `INT` value to the bytes within an inclusive `range` in the BLOB -/// in little-endian byte order. -/// -/// * If number of bytes in `range` < number of bytes for `INT`, extra bytes in `INT` are not written. -/// * If number of bytes in `range` > number of bytes for `INT`, extra bytes in `range` are not modified. -/// -/// ```rhai -/// let b = blob(8); -/// -/// b.write_le_int(1..=3, 0x12345678); -/// -/// print(b); // prints "[0078563400000000]" -/// ``` -fn write_le(blob: Blob, range: RangeInclusive, value: int) -> (); - -/// Write a `FLOAT` value to the bytes beginning at the `start` position in the BLOB -/// in little-endian byte order. -/// -/// * If `start` < 0, position counts from the end of the BLOB (`-1` is the last byte). -/// * If `start` < -length of BLOB, position counts from the beginning of the BLOB. -/// * If `start` ≥ length of BLOB, zero is returned. -/// * If `len` ≤ 0, zero is returned. -/// * If `start` position + `len` ≥ length of BLOB, entire portion of the BLOB after the `start` position is parsed. -/// -/// * If number of bytes in `range` < number of bytes for `FLOAT`, extra bytes in `FLOAT` are not written. -/// * If number of bytes in `range` > number of bytes for `FLOAT`, extra bytes in `range` are not modified. -fn write_le(blob: Blob, start: int, len: int, value: float) -> (); - -/// Write an `INT` value to the bytes beginning at the `start` position in the BLOB -/// in little-endian byte order. -/// -/// * If `start` < 0, position counts from the end of the BLOB (`-1` is the last byte). -/// * If `start` < -length of BLOB, position counts from the beginning of the BLOB. -/// * If `start` ≥ length of BLOB, zero is returned. -/// * If `len` ≤ 0, zero is returned. -/// * If `start` position + `len` ≥ length of BLOB, entire portion of the BLOB after the `start` position is parsed. -/// -/// * If number of bytes in `range` < number of bytes for `INT`, extra bytes in `INT` are not written. -/// * If number of bytes in `range` > number of bytes for `INT`, extra bytes in `range` are not modified. -/// -/// ```rhai -/// let b = blob(8); -/// -/// b.write_le_int(1, 3, 0x12345678); -/// -/// print(b); // prints "[0078563400000000]" -/// ``` -fn write_le(blob: Blob, start: int, len: int, value: int) -> (); - -/// Write a string to the bytes within an exclusive `range` in the BLOB in UTF-8 encoding. -/// -/// * If number of bytes in `range` < length of `string`, extra bytes in `string` are not written. -/// * If number of bytes in `range` > length of `string`, extra bytes in `range` are not modified. -/// -/// ```rhai -/// let b = blob(8); -/// -/// b.write_utf8(1..5, "朝には紅顔ありて夕べには白骨となる"); -/// -/// print(b); // prints "[00e69c9de3000000]" -/// ``` -fn write_utf8(blob: Blob, range: Range, string: String) -> (); - -/// Write a string to the bytes within an inclusive `range` in the BLOB in UTF-8 encoding. -/// -/// * If number of bytes in `range` < length of `string`, extra bytes in `string` are not written. -/// * If number of bytes in `range` > length of `string`, extra bytes in `range` are not modified. -/// -/// ```rhai -/// let b = blob(8); -/// -/// b.write_utf8(1..=5, "朝には紅顔ありて夕べには白骨となる"); -/// -/// print(b); // prints "[00e69c9de3810000]" -/// ``` -fn write_utf8(blob: Blob, range: RangeInclusive, string: String) -> (); - -/// Write a string to the bytes within an inclusive `range` in the BLOB in UTF-8 encoding. -/// -/// * If `start` < 0, position counts from the end of the BLOB (`-1` is the last byte). -/// * If `start` < -length of BLOB, position counts from the beginning of the BLOB. -/// * If `start` ≥ length of BLOB, the BLOB is not modified. -/// * If `len` ≤ 0, the BLOB is not modified. -/// * If `start` position + `len` ≥ length of BLOB, only the portion of the BLOB after the `start` position is modified. -/// -/// * If number of bytes in `range` < length of `string`, extra bytes in `string` are not written. -/// * If number of bytes in `range` > length of `string`, extra bytes in `range` are not modified. -/// -/// ```rhai -/// let b = blob(8); -/// -/// b.write_utf8(1, 5, "朝には紅顔ありて夕べには白骨となる"); -/// -/// print(b); // prints "[00e69c9de3810000]" -/// ``` -fn write_utf8(blob: Blob, start: int, len: int, string: String) -> (); - -op |(i128, i128) -> i128; - -op |(i16, i16) -> i16; - -op |(i32, i32) -> i32; - -op |(i8, i8) -> i8; - -op |(u128, u128) -> u128; - -op |(u16, u16) -> u16; - -op |(u32, u32) -> u32; - -op |(u64, u64) -> u64; - -op |(u8, u8) -> u8; \ No newline at end of file diff --git a/examples/definitions/.rhai/definitions/general_kenobi.d.rhai b/examples/definitions/.rhai/definitions/general_kenobi.d.rhai deleted file mode 100644 index 6257c2a6c..000000000 --- a/examples/definitions/.rhai/definitions/general_kenobi.d.rhai +++ /dev/null @@ -1,6 +0,0 @@ -module general_kenobi; - -const CONSTANT: int; - -/// Returns a string where "hello there" is repeated `n` times. -fn hello_there(n: int) -> String; \ No newline at end of file diff --git a/examples/definitions/.rhai/defs.json b/examples/definitions/.rhai/defs.json deleted file mode 100644 index 467a55076..000000000 --- a/examples/definitions/.rhai/defs.json +++ /dev/null @@ -1,49 +0,0 @@ -{ - "modules": { - "general_kenobi": { - "functions": [ - { - "baseHash": 3873007749982070651, - "fullHash": 5865213555928423624, - "namespace": "internal", - "access": "public", - "name": "hello_there", - "type": "native", - "numParams": 1, - "params": [ - { - "name": "n", - "type": "i64" - } - ], - "returnType": "String", - "signature": "hello_there(n: i64) -> String", - "docComments": [ - "/// Returns a string where \"hello there\" is repeated `n` times." - ] - } - ] - } - }, - "functions": [ - { - "baseHash": 12461724250411739075, - "fullHash": 14530626537296006176, - "namespace": "global", - "access": "public", - "name": "minus", - "type": "native", - "numParams": 2, - "params": [ - { - "type": "i64" - }, - { - "type": "i64" - } - ], - "returnType": "i64", - "signature": "minus(_: i64, _: i64) -> i64" - } - ] -} \ No newline at end of file diff --git a/examples/definitions/main.rs b/examples/definitions/main.rs deleted file mode 100644 index f0bf52add..000000000 --- a/examples/definitions/main.rs +++ /dev/null @@ -1,70 +0,0 @@ -use spo_rhai::plugin::*; -use spo_rhai::{Engine, EvalAltResult, Scope}; - -#[export_module] -pub mod general_kenobi { - /// General Kenobi's Constant. - pub const CONSTANT: i64 = 42; - - /// Returns a string where "hello there" is repeated `n` times. - pub fn hello_there(n: i64) -> String { - use std::convert::TryInto; - "hello there ".repeat(n.try_into().unwrap()) - } -} - -fn main() -> Result<(), Box> { - let mut engine = Engine::new(); - let mut scope = Scope::new(); - - // This variable will also show up in the definitions, since it will be part of the scope. - scope.push("hello_there", "hello there"); - - // This constant will also show up in the definitions, since it will be part of the scope. - scope.push_constant("HELLO", "hello there"); - - #[cfg(not(feature = "no_module"))] - engine.register_static_module("general_kenobi", exported_module!(general_kenobi).into()); - - // Custom operators also show up in definitions. - #[cfg(not(feature = "no_custom_syntax"))] - { - engine.register_custom_operator("minus", 100).unwrap(); - engine.register_fn("minus", |a: i64, b: i64| a - b); - } - - engine.run_with_scope( - &mut scope, - "hello_there = general_kenobi::hello_there(4 minus 2);", - )?; - - // Generate definitions for the contents of the engine and the scope. - engine - .definitions_with_scope(&scope) - .write_to_dir("examples/definitions/.rhai/definitions") - .unwrap(); - - // Alternatively we can write all of the above to a single file. - engine - .definitions_with_scope(&scope) - .write_to_file("examples/definitions/.rhai/all_in_one.d.rhai") - .unwrap(); - - // Skip standard packages if not needed (e.g. they are provided elsewhere). - engine - .definitions_with_scope(&scope) - .include_standard_packages(false) - .write_to_file("examples/definitions/.rhai/all_in_one_without_standard.d.rhai") - .unwrap(); - - // Write function definitions as JSON. - let json = engine - .definitions() - .include_standard_packages(false) - .json() - .unwrap(); - - std::fs::write("examples/definitions/.rhai/defs.json", json).unwrap(); - - Ok(()) -} diff --git a/examples/definitions/script.rhai b/examples/definitions/script.rhai deleted file mode 100644 index 1b8da1aa8..000000000 --- a/examples/definitions/script.rhai +++ /dev/null @@ -1,3 +0,0 @@ -// The following will be valid based on the definitions. -hello_there = general_kenobi::hello_there(123); -print(hello_there); From 9ee294c39cae4faa1d33404156f0eab8fadaa1a3 Mon Sep 17 00:00:00 2001 From: Duy Do Date: Wed, 14 Feb 2024 16:07:34 +0700 Subject: [PATCH 6/9] Remove example --- Cargo.toml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 78b6acd39..4f8d84565 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -144,10 +144,6 @@ name = "rhai-run" name = "rhai-dbg" required-features = ["debugging"] -[[example]] -name = "definitions" -required-features = ["metadata", "internals"] - [profile.release] lto = "fat" codegen-units = 1 From 96ba0bbfd7e650d9b9efd77c49291f5711b312eb Mon Sep 17 00:00:00 2001 From: Duy Do Date: Wed, 14 Feb 2024 16:10:56 +0700 Subject: [PATCH 7/9] bump --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 4f8d84565..a61050f5d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ members = [".", "codegen"] [package] name = "spo-rhai" -version = "1.17.1" +version = "1.17.2" rust-version = "1.66.0" edition = "2018" resolver = "2" From 339445306376320e3fc22f6d82ebc8df5cd78e8e Mon Sep 17 00:00:00 2001 From: Duy Do Date: Wed, 14 Feb 2024 16:18:04 +0700 Subject: [PATCH 8/9] revert --- benches/engine.rs | 4 ++-- benches/eval_array.rs | 2 +- benches/eval_expression.rs | 2 +- benches/eval_map.rs | 2 +- benches/eval_module.rs | 2 +- benches/eval_scope.rs | 2 +- benches/eval_type.rs | 2 +- benches/iterations.rs | 2 +- benches/parsing.rs | 2 +- benches/primes.rs | 2 +- examples/arrays_and_structs.rs | 2 +- examples/callback.rs | 2 +- examples/custom_types.rs | 2 +- examples/custom_types_and_methods.rs | 2 +- examples/event_handler_js/main.rs | 2 +- examples/event_handler_main/main.rs | 2 +- examples/event_handler_map/main.rs | 2 +- examples/hello.rs | 2 +- examples/pause_and_resume.rs | 2 +- examples/reuse_scope.rs | 2 +- examples/serde.rs | 4 ++-- examples/simple_fn.rs | 2 +- examples/strings.rs | 2 +- examples/threading.rs | 2 +- src/bin/rhai-dbg.rs | 4 ++-- src/bin/rhai-repl.rs | 4 ++-- src/bin/rhai-run.rs | 4 ++-- tests/arrays.rs | 2 +- tests/assignments.rs | 2 +- tests/binary_ops.rs | 4 ++-- tests/bit_fields.rs | 2 +- tests/blobs.rs | 2 +- tests/bool_op.rs | 2 +- tests/build_type.rs | 2 +- tests/call_fn.rs | 2 +- tests/chars.rs | 2 +- tests/closures.rs | 4 ++-- tests/comments.rs | 2 +- tests/compound_equality.rs | 2 +- tests/constants.rs | 2 +- tests/custom_syntax.rs | 2 +- tests/data_size.rs | 6 +++--- tests/debugging.rs | 6 +++--- tests/decrement.rs | 2 +- tests/eval.rs | 2 +- tests/expressions.rs | 2 +- tests/float.rs | 2 +- tests/fn_ptr.rs | 2 +- tests/for.rs | 4 ++-- tests/functions.rs | 4 ++-- tests/get_set.rs | 4 ++-- tests/if_block.rs | 2 +- tests/increment.rs | 2 +- tests/looping.rs | 2 +- tests/maps.rs | 2 +- tests/math.rs | 4 ++-- tests/method_call.rs | 4 ++-- tests/mismatched_op.rs | 2 +- tests/modules.rs | 18 +++++++++--------- tests/native.rs | 2 +- tests/not.rs | 2 +- tests/number_literals.rs | 2 +- tests/operations.rs | 8 ++++---- tests/ops.rs | 2 +- tests/optimizer.rs | 2 +- tests/options.rs | 2 +- tests/packages.rs | 4 ++-- tests/plugins.rs | 8 ++++---- tests/plugins_register.rs | 4 ++-- tests/plugins_unroll.rs | 6 +++--- tests/power_of.rs | 4 ++-- tests/print.rs | 2 +- tests/side_effects.rs | 2 +- tests/stack.rs | 2 +- tests/string.rs | 2 +- tests/switch.rs | 4 ++-- tests/throw.rs | 2 +- tests/time.rs | 6 +++--- tests/tokens.rs | 2 +- tests/types.rs | 2 +- tests/unary_after_binary.rs | 2 +- tests/unary_minus.rs | 2 +- tests/unit.rs | 2 +- tests/var_scope.rs | 2 +- tests/while_loop.rs | 2 +- 85 files changed, 123 insertions(+), 123 deletions(-) diff --git a/benches/engine.rs b/benches/engine.rs index 1f13a17c8..d725699a7 100644 --- a/benches/engine.rs +++ b/benches/engine.rs @@ -3,7 +3,7 @@ ///! Test evaluating expressions extern crate test; -use spo_rhai::{Array, Engine, Map, INT}; +use rhai::{Array, Engine, Map, INT}; use test::Bencher; #[bench] @@ -18,7 +18,7 @@ fn bench_engine_new_raw(bench: &mut Bencher) { #[bench] fn bench_engine_new_raw_core(bench: &mut Bencher) { - use spo_rhai::packages::*; + use rhai::packages::*; let package = CorePackage::new(); bench.iter(|| { diff --git a/benches/eval_array.rs b/benches/eval_array.rs index 9a6e99052..7287f2224 100644 --- a/benches/eval_array.rs +++ b/benches/eval_array.rs @@ -3,7 +3,7 @@ ///! Test evaluating expressions extern crate test; -use spo_rhai::{Engine, OptimizationLevel}; +use rhai::{Engine, OptimizationLevel}; use test::Bencher; #[bench] diff --git a/benches/eval_expression.rs b/benches/eval_expression.rs index b460b831c..dfcdbb06e 100644 --- a/benches/eval_expression.rs +++ b/benches/eval_expression.rs @@ -3,7 +3,7 @@ ///! Test evaluating expressions extern crate test; -use spo_rhai::{Engine, OptimizationLevel}; +use rhai::{Engine, OptimizationLevel}; use test::Bencher; #[bench] diff --git a/benches/eval_map.rs b/benches/eval_map.rs index 20f01de08..df49dcdfc 100644 --- a/benches/eval_map.rs +++ b/benches/eval_map.rs @@ -3,7 +3,7 @@ ///! Test evaluating expressions extern crate test; -use spo_rhai::{Engine, OptimizationLevel}; +use rhai::{Engine, OptimizationLevel}; use test::Bencher; #[bench] diff --git a/benches/eval_module.rs b/benches/eval_module.rs index 71bc1c34d..55fb0fb49 100644 --- a/benches/eval_module.rs +++ b/benches/eval_module.rs @@ -3,7 +3,7 @@ ///! Test evaluating with scope extern crate test; -use spo_rhai::{Engine, Module, OptimizationLevel, Scope}; +use rhai::{Engine, Module, OptimizationLevel, Scope}; use test::Bencher; #[bench] diff --git a/benches/eval_scope.rs b/benches/eval_scope.rs index d408c6a9d..2237fa8a6 100644 --- a/benches/eval_scope.rs +++ b/benches/eval_scope.rs @@ -3,7 +3,7 @@ ///! Test evaluating with scope extern crate test; -use spo_rhai::{Engine, OptimizationLevel, Scope, INT}; +use rhai::{Engine, OptimizationLevel, Scope, INT}; use test::Bencher; #[bench] diff --git a/benches/eval_type.rs b/benches/eval_type.rs index 8ee74d97d..7cee4394e 100644 --- a/benches/eval_type.rs +++ b/benches/eval_type.rs @@ -3,7 +3,7 @@ ///! Test evaluating expressions extern crate test; -use spo_rhai::{Engine, OptimizationLevel, Scope, INT}; +use rhai::{Engine, OptimizationLevel, Scope, INT}; use test::Bencher; #[derive(Debug, Clone)] diff --git a/benches/iterations.rs b/benches/iterations.rs index 4e6f6ac41..33ac414f4 100644 --- a/benches/iterations.rs +++ b/benches/iterations.rs @@ -3,7 +3,7 @@ ///! Test 1,000 iterations extern crate test; -use spo_rhai::{Engine, OptimizationLevel, INT}; +use rhai::{Engine, OptimizationLevel, INT}; use test::Bencher; #[bench] diff --git a/benches/parsing.rs b/benches/parsing.rs index 1ce0077d9..d45b22529 100644 --- a/benches/parsing.rs +++ b/benches/parsing.rs @@ -3,7 +3,7 @@ ///! Test parsing expressions extern crate test; -use spo_rhai::{Engine, OptimizationLevel}; +use rhai::{Engine, OptimizationLevel}; use test::Bencher; #[bench] diff --git a/benches/primes.rs b/benches/primes.rs index 708d1d368..40c047a05 100644 --- a/benches/primes.rs +++ b/benches/primes.rs @@ -3,7 +3,7 @@ ///! Test evaluating expressions extern crate test; -use spo_rhai::{Engine, OptimizationLevel}; +use rhai::{Engine, OptimizationLevel}; use test::Bencher; // This script uses the Sieve of Eratosthenes to calculate prime numbers. diff --git a/examples/arrays_and_structs.rs b/examples/arrays_and_structs.rs index 3ba0e5e5b..b5a7889a7 100644 --- a/examples/arrays_and_structs.rs +++ b/examples/arrays_and_structs.rs @@ -5,7 +5,7 @@ fn main() { panic!("This example does not run under 'no_index' or 'no_object'.") } -use spo_rhai::{Engine, EvalAltResult}; +use rhai::{Engine, EvalAltResult}; #[cfg(not(feature = "no_index"))] #[cfg(not(feature = "no_object"))] diff --git a/examples/callback.rs b/examples/callback.rs index ffcea0594..999846910 100644 --- a/examples/callback.rs +++ b/examples/callback.rs @@ -1,6 +1,6 @@ //! This example stores a Rhai closure for later use as a callback. -use spo_rhai::{Engine, EvalAltResult, FnPtr}; +use rhai::{Engine, EvalAltResult, FnPtr}; // To call a Rhai closure at a later time, you'd need three things: // 1) an `Engine` (with all needed functions registered), diff --git a/examples/custom_types.rs b/examples/custom_types.rs index 44d9c4f3a..c4d7804fa 100644 --- a/examples/custom_types.rs +++ b/examples/custom_types.rs @@ -5,7 +5,7 @@ fn main() { panic!("This example does not run under 'no_object'."); } -use spo_rhai::{CustomType, Engine, EvalAltResult, TypeBuilder}; +use rhai::{CustomType, Engine, EvalAltResult, TypeBuilder}; #[cfg(not(feature = "no_object"))] fn main() -> Result<(), Box> { diff --git a/examples/custom_types_and_methods.rs b/examples/custom_types_and_methods.rs index 27c24147f..4dd0f5618 100644 --- a/examples/custom_types_and_methods.rs +++ b/examples/custom_types_and_methods.rs @@ -5,7 +5,7 @@ fn main() { panic!("This example does not run under 'no_object'."); } -use spo_rhai::{CustomType, Engine, EvalAltResult, TypeBuilder}; +use rhai::{CustomType, Engine, EvalAltResult, TypeBuilder}; #[cfg(not(feature = "no_object"))] fn main() -> Result<(), Box> { diff --git a/examples/event_handler_js/main.rs b/examples/event_handler_js/main.rs index 942088a4d..efed0107f 100644 --- a/examples/event_handler_js/main.rs +++ b/examples/event_handler_js/main.rs @@ -8,7 +8,7 @@ pub fn main() { #[cfg(not(feature = "no_function"))] #[cfg(not(feature = "no_object"))] pub fn main() { - use spo_rhai::{CallFnOptions, Dynamic, Engine, Map, Scope, AST}; + use rhai::{CallFnOptions, Dynamic, Engine, Map, Scope, AST}; use std::io::{stdin, stdout, Write}; const SCRIPT_FILE: &str = "event_handler_js/script.rhai"; diff --git a/examples/event_handler_main/main.rs b/examples/event_handler_main/main.rs index b4be54c22..2a1d8f797 100644 --- a/examples/event_handler_main/main.rs +++ b/examples/event_handler_main/main.rs @@ -7,7 +7,7 @@ pub fn main() { #[cfg(not(feature = "no_function"))] pub fn main() { - use spo_rhai::{CallFnOptions, Dynamic, Engine, Scope, AST}; + use rhai::{CallFnOptions, Dynamic, Engine, Scope, AST}; use std::io::{stdin, stdout, Write}; const SCRIPT_FILE: &str = "event_handler_main/script.rhai"; diff --git a/examples/event_handler_map/main.rs b/examples/event_handler_map/main.rs index 72d89830b..dc9c2ff7c 100644 --- a/examples/event_handler_map/main.rs +++ b/examples/event_handler_map/main.rs @@ -8,7 +8,7 @@ pub fn main() { #[cfg(not(feature = "no_function"))] #[cfg(not(feature = "no_object"))] pub fn main() { - use spo_rhai::{Dynamic, Engine, Map, Scope, AST}; + use rhai::{Dynamic, Engine, Map, Scope, AST}; use std::io::{stdin, stdout, Write}; const SCRIPT_FILE: &str = "event_handler_map/script.rhai"; diff --git a/examples/hello.rs b/examples/hello.rs index d6eaaf913..dba66e5b2 100644 --- a/examples/hello.rs +++ b/examples/hello.rs @@ -1,6 +1,6 @@ //! A simple example that evaluates an expression and prints the result. -use spo_rhai::{Engine, EvalAltResult}; +use rhai::{Engine, EvalAltResult}; fn main() -> Result<(), Box> { let engine = Engine::new(); diff --git a/examples/pause_and_resume.rs b/examples/pause_and_resume.rs index 1595a9f88..8b336d637 100644 --- a/examples/pause_and_resume.rs +++ b/examples/pause_and_resume.rs @@ -5,7 +5,7 @@ fn main() { panic!("This example does not run under 'unchecked'."); } -use spo_rhai::{Dynamic, Engine}; +use rhai::{Dynamic, Engine}; #[cfg(feature = "sync")] use std::sync::Mutex; diff --git a/examples/reuse_scope.rs b/examples/reuse_scope.rs index b7a9a6aaf..486382a24 100644 --- a/examples/reuse_scope.rs +++ b/examples/reuse_scope.rs @@ -1,6 +1,6 @@ //! An example that evaluates two pieces of code in separate runs, but using a common `Scope`. -use spo_rhai::{Engine, EvalAltResult, Scope}; +use rhai::{Engine, EvalAltResult, Scope}; fn main() -> Result<(), Box> { let engine = Engine::new(); diff --git a/examples/serde.rs b/examples/serde.rs index f6f9da711..cbdab2b2d 100644 --- a/examples/serde.rs +++ b/examples/serde.rs @@ -7,8 +7,8 @@ fn main() { #[cfg(not(feature = "no_object"))] fn main() { - use spo_rhai::serde::{from_dynamic, to_dynamic}; - use spo_rhai::{Dynamic, Engine, Map}; + use rhai::serde::{from_dynamic, to_dynamic}; + use rhai::{Dynamic, Engine, Map}; use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] diff --git a/examples/simple_fn.rs b/examples/simple_fn.rs index 3f862d988..887cad30b 100644 --- a/examples/simple_fn.rs +++ b/examples/simple_fn.rs @@ -1,6 +1,6 @@ //! An example showing how to register a simple Rust function. -use spo_rhai::{Engine, EvalAltResult}; +use rhai::{Engine, EvalAltResult}; fn add(x: i64, y: i64) -> i64 { x + y diff --git a/examples/strings.rs b/examples/strings.rs index db969d616..b9c7285ad 100644 --- a/examples/strings.rs +++ b/examples/strings.rs @@ -1,7 +1,7 @@ //! An example that registers a variety of functions that operate on strings. //! Remember to use `ImmutableString` or `&str` instead of `String` as parameters. -use spo_rhai::{Engine, EvalAltResult, ImmutableString, Scope}; +use rhai::{Engine, EvalAltResult, ImmutableString, Scope}; use std::io::{stdin, stdout, Write}; /// Trim whitespace from a string. The original string argument is changed. diff --git a/examples/threading.rs b/examples/threading.rs index f974c46ac..adcf9bea2 100644 --- a/examples/threading.rs +++ b/examples/threading.rs @@ -1,7 +1,7 @@ //! An advanced example showing how to communicate with an `Engine` running in a separate thread via //! an MPSC channel. -use spo_rhai::Engine; +use rhai::Engine; #[cfg(feature = "sync")] use std::sync::Mutex; diff --git a/src/bin/rhai-dbg.rs b/src/bin/rhai-dbg.rs index 37b8a889c..cecb2ad5c 100644 --- a/src/bin/rhai-dbg.rs +++ b/src/bin/rhai-dbg.rs @@ -1,5 +1,5 @@ -use spo_rhai::debugger::{BreakPoint, DebuggerCommand, DebuggerEvent}; -use spo_rhai::{Dynamic, Engine, EvalAltResult, ImmutableString, Position, Scope, INT}; +use rhai::debugger::{BreakPoint, DebuggerCommand, DebuggerEvent}; +use rhai::{Dynamic, Engine, EvalAltResult, ImmutableString, Position, Scope, INT}; use std::{ env, diff --git a/src/bin/rhai-repl.rs b/src/bin/rhai-repl.rs index 96e89bb70..a8df52a95 100644 --- a/src/bin/rhai-repl.rs +++ b/src/bin/rhai-repl.rs @@ -1,5 +1,5 @@ -use spo_rhai::plugin::*; -use spo_rhai::{Dynamic, Engine, EvalAltResult, Module, Scope, AST, INT}; +use rhai::plugin::*; +use rhai::{Dynamic, Engine, EvalAltResult, Module, Scope, AST, INT}; use rustyline::config::Builder; use rustyline::error::ReadlineError; use rustyline::history::{History, SearchDirection}; diff --git a/src/bin/rhai-run.rs b/src/bin/rhai-run.rs index 31cacf369..b8503db0f 100644 --- a/src/bin/rhai-run.rs +++ b/src/bin/rhai-run.rs @@ -1,4 +1,4 @@ -use spo_rhai::{Engine, EvalAltResult, Position}; +use rhai::{Engine, EvalAltResult, Position}; use std::{env, fs::File, io::Read, path::Path, process::exit}; @@ -55,7 +55,7 @@ fn main() { let mut engine = Engine::new(); #[cfg(not(feature = "no_optimize"))] - engine.set_optimization_level(spo_rhai::OptimizationLevel::Simple); + engine.set_optimization_level(rhai::OptimizationLevel::Simple); let mut f = match File::open(&filename) { Err(err) => { diff --git a/tests/arrays.rs b/tests/arrays.rs index ca3a9d720..2563bfca6 100644 --- a/tests/arrays.rs +++ b/tests/arrays.rs @@ -1,5 +1,5 @@ #![cfg(not(feature = "no_index"))] -use spo_rhai::{Array, Dynamic, Engine, ParseErrorType, INT}; +use rhai::{Array, Dynamic, Engine, ParseErrorType, INT}; use std::iter::FromIterator; #[test] diff --git a/tests/assignments.rs b/tests/assignments.rs index 70387c163..c8803bb9a 100644 --- a/tests/assignments.rs +++ b/tests/assignments.rs @@ -1,4 +1,4 @@ -use spo_rhai::{Engine, ParseErrorType, INT}; +use rhai::{Engine, ParseErrorType, INT}; #[test] fn test_assignments() { diff --git a/tests/binary_ops.rs b/tests/binary_ops.rs index 907bd7ec7..e63bd78ec 100644 --- a/tests/binary_ops.rs +++ b/tests/binary_ops.rs @@ -1,4 +1,4 @@ -use spo_rhai::{Engine, INT}; +use rhai::{Engine, INT}; #[test] fn test_binary_ops() { @@ -39,7 +39,7 @@ fn test_binary_ops() { #[cfg(not(feature = "no_float"))] { - use spo_rhai::FLOAT; + use rhai::FLOAT; assert_eq!(engine.eval::("10.0 + 4.0").unwrap(), 14.0); assert_eq!(engine.eval::("10.0 - 4.0").unwrap(), 6.0); diff --git a/tests/bit_fields.rs b/tests/bit_fields.rs index 9dd7b4435..4802c24b9 100644 --- a/tests/bit_fields.rs +++ b/tests/bit_fields.rs @@ -1,4 +1,4 @@ -use spo_rhai::{Engine, INT}; +use rhai::{Engine, INT}; #[test] fn test_left_shift() { diff --git a/tests/blobs.rs b/tests/blobs.rs index 4b97c30ee..d739ad61b 100644 --- a/tests/blobs.rs +++ b/tests/blobs.rs @@ -1,5 +1,5 @@ #![cfg(not(feature = "no_index"))] -use spo_rhai::{Blob, Engine, Scope, INT}; +use rhai::{Blob, Engine, Scope, INT}; use std::iter::FromIterator; #[test] diff --git a/tests/bool_op.rs b/tests/bool_op.rs index 53e7106dd..c938beaa9 100644 --- a/tests/bool_op.rs +++ b/tests/bool_op.rs @@ -1,4 +1,4 @@ -use spo_rhai::Engine; +use rhai::Engine; #[test] fn test_bool_op1() { diff --git a/tests/build_type.rs b/tests/build_type.rs index 9bd0db59f..4c7190cd3 100644 --- a/tests/build_type.rs +++ b/tests/build_type.rs @@ -1,5 +1,5 @@ #![cfg(not(feature = "no_object"))] -use spo_rhai::{CustomType, Engine, EvalAltResult, Position, TypeBuilder, INT}; +use rhai::{CustomType, Engine, EvalAltResult, Position, TypeBuilder, INT}; #[test] fn test_build_type() { diff --git a/tests/call_fn.rs b/tests/call_fn.rs index b07ff0708..23273dcd0 100644 --- a/tests/call_fn.rs +++ b/tests/call_fn.rs @@ -1,5 +1,5 @@ #![cfg(not(feature = "no_function"))] -use spo_rhai::{CallFnOptions, Dynamic, Engine, EvalAltResult, FnPtr, Func, FuncArgs, Scope, AST, INT}; +use rhai::{CallFnOptions, Dynamic, Engine, EvalAltResult, FnPtr, Func, FuncArgs, Scope, AST, INT}; use std::any::TypeId; #[test] diff --git a/tests/chars.rs b/tests/chars.rs index aa3c75e51..772a58d90 100644 --- a/tests/chars.rs +++ b/tests/chars.rs @@ -1,4 +1,4 @@ -use spo_rhai::Engine; +use rhai::Engine; #[test] fn test_chars() { diff --git a/tests/closures.rs b/tests/closures.rs index 37e30610e..89585d8ff 100644 --- a/tests/closures.rs +++ b/tests/closures.rs @@ -1,12 +1,12 @@ #![cfg(not(feature = "no_function"))] -use spo_rhai::{Dynamic, Engine, EvalAltResult, FnPtr, ParseErrorType, Scope, INT}; +use rhai::{Dynamic, Engine, EvalAltResult, FnPtr, ParseErrorType, Scope, INT}; use std::any::TypeId; use std::cell::RefCell; use std::mem::take; use std::rc::Rc; #[cfg(not(feature = "no_object"))] -use spo_rhai::Map; +use rhai::Map; #[test] fn test_fn_ptr_curry_call() { diff --git a/tests/comments.rs b/tests/comments.rs index 29ea643a1..1a7a23b9f 100644 --- a/tests/comments.rs +++ b/tests/comments.rs @@ -1,4 +1,4 @@ -use spo_rhai::{Engine, INT}; +use rhai::{Engine, INT}; #[test] fn test_comments() { diff --git a/tests/compound_equality.rs b/tests/compound_equality.rs index 767cd1885..d21f19821 100644 --- a/tests/compound_equality.rs +++ b/tests/compound_equality.rs @@ -1,4 +1,4 @@ -use spo_rhai::{Engine, INT}; +use rhai::{Engine, INT}; #[test] fn test_or_equals() { diff --git a/tests/constants.rs b/tests/constants.rs index 46f27a38d..cb8c810b2 100644 --- a/tests/constants.rs +++ b/tests/constants.rs @@ -1,4 +1,4 @@ -use spo_rhai::{Engine, EvalAltResult, ParseErrorType, Scope, INT}; +use rhai::{Engine, EvalAltResult, ParseErrorType, Scope, INT}; #[test] fn test_constant() { diff --git a/tests/custom_syntax.rs b/tests/custom_syntax.rs index 3025c738a..42fc637ca 100644 --- a/tests/custom_syntax.rs +++ b/tests/custom_syntax.rs @@ -1,6 +1,6 @@ #![cfg(not(feature = "no_custom_syntax"))] -use spo_rhai::{Dynamic, Engine, EvalAltResult, ImmutableString, LexError, ParseErrorType, Position, Scope, INT}; +use rhai::{Dynamic, Engine, EvalAltResult, ImmutableString, LexError, ParseErrorType, Position, Scope, INT}; #[test] fn test_custom_syntax() { diff --git a/tests/data_size.rs b/tests/data_size.rs index 76620af3e..4285def0c 100644 --- a/tests/data_size.rs +++ b/tests/data_size.rs @@ -1,11 +1,11 @@ #![cfg(not(feature = "unchecked"))] -use spo_rhai::{Engine, EvalAltResult, ParseErrorType, INT}; +use rhai::{Engine, EvalAltResult, ParseErrorType, INT}; #[cfg(not(feature = "no_index"))] -use spo_rhai::Array; +use rhai::Array; #[cfg(not(feature = "no_object"))] -use spo_rhai::Map; +use rhai::Map; #[test] fn test_max_string_size() { diff --git a/tests/debugging.rs b/tests/debugging.rs index af730be3e..811666e8f 100644 --- a/tests/debugging.rs +++ b/tests/debugging.rs @@ -1,11 +1,11 @@ #![cfg(feature = "debugging")] -use spo_rhai::{Engine, INT}; +use rhai::{Engine, INT}; #[cfg(not(feature = "no_index"))] -use spo_rhai::Array; +use rhai::Array; #[cfg(not(feature = "no_object"))] -use spo_rhai::Map; +use rhai::Map; #[test] fn test_debugging() { diff --git a/tests/decrement.rs b/tests/decrement.rs index 3227331cc..7a3109967 100644 --- a/tests/decrement.rs +++ b/tests/decrement.rs @@ -1,4 +1,4 @@ -use spo_rhai::{Engine, INT}; +use rhai::{Engine, INT}; #[test] fn test_decrement() { diff --git a/tests/eval.rs b/tests/eval.rs index fe7e21eb5..91e86ae97 100644 --- a/tests/eval.rs +++ b/tests/eval.rs @@ -1,4 +1,4 @@ -use spo_rhai::{Engine, LexError, ParseErrorType, Scope, INT}; +use rhai::{Engine, LexError, ParseErrorType, Scope, INT}; #[test] fn test_eval() { diff --git a/tests/expressions.rs b/tests/expressions.rs index 0de965078..99c43875e 100644 --- a/tests/expressions.rs +++ b/tests/expressions.rs @@ -1,4 +1,4 @@ -use spo_rhai::{Engine, Scope, INT}; +use rhai::{Engine, Scope, INT}; #[test] fn test_expressions() { diff --git a/tests/float.rs b/tests/float.rs index b0cd9ea0f..8796b296b 100644 --- a/tests/float.rs +++ b/tests/float.rs @@ -1,5 +1,5 @@ #![cfg(not(feature = "no_float"))] -use spo_rhai::{Engine, FLOAT}; +use rhai::{Engine, FLOAT}; const EPSILON: FLOAT = 0.000_000_000_1; diff --git a/tests/fn_ptr.rs b/tests/fn_ptr.rs index 985bb3baa..f18c63386 100644 --- a/tests/fn_ptr.rs +++ b/tests/fn_ptr.rs @@ -1,4 +1,4 @@ -use spo_rhai::{Engine, EvalAltResult, FnPtr, INT}; +use rhai::{Engine, EvalAltResult, FnPtr, INT}; #[test] fn test_fn_ptr() { diff --git a/tests/for.rs b/tests/for.rs index 896d07c2b..1d30c352a 100644 --- a/tests/for.rs +++ b/tests/for.rs @@ -1,7 +1,7 @@ -use spo_rhai::{Engine, Module, INT}; +use rhai::{Engine, Module, INT}; #[cfg(not(feature = "no_float"))] -use spo_rhai::FLOAT; +use rhai::FLOAT; #[cfg(feature = "decimal")] #[cfg(not(feature = "no_float"))] diff --git a/tests/functions.rs b/tests/functions.rs index a9994641e..8089abf93 100644 --- a/tests/functions.rs +++ b/tests/functions.rs @@ -1,5 +1,5 @@ #![cfg(not(feature = "no_function"))] -use spo_rhai::{Dynamic, Engine, EvalAltResult, FnNamespace, FuncRegistration, Module, NativeCallContext, ParseErrorType, Shared, INT}; +use rhai::{Dynamic, Engine, EvalAltResult, FnNamespace, FuncRegistration, Module, NativeCallContext, ParseErrorType, Shared, INT}; #[test] fn test_functions() { @@ -135,7 +135,7 @@ fn test_functions_global_module() { if matches!(&*err, EvalAltResult::ErrorVariableNotFound(v, ..) if v == "global::ANSWER") )); - engine.register_fn("do_stuff", |context: NativeCallContext, callback: spo_rhai::FnPtr| -> Result { callback.call_within_context(&context, ()) }); + engine.register_fn("do_stuff", |context: NativeCallContext, callback: rhai::FnPtr| -> Result { callback.call_within_context(&context, ()) }); #[cfg(not(feature = "no_closure"))] assert!(matches!(*engine.run( diff --git a/tests/get_set.rs b/tests/get_set.rs index 2fd22c4e4..d5d7e591f 100644 --- a/tests/get_set.rs +++ b/tests/get_set.rs @@ -1,5 +1,5 @@ #![cfg(not(feature = "no_object"))] -use spo_rhai::{Engine, EvalAltResult, NativeCallContext, Scope, INT}; +use rhai::{Engine, EvalAltResult, NativeCallContext, Scope, INT}; #[test] fn test_get_set() { @@ -239,7 +239,7 @@ fn test_get_set_indexer() { engine .register_type_with_name::("MyMap") .register_fn("new_map", MyMap::new) - .register_indexer_get(|map: &mut MyMap, index: &str| -> Result<_, Box> { map.get(index).cloned().ok_or_else(|| EvalAltResult::ErrorIndexNotFound(index.into(), spo_rhai::Position::NONE).into()) }) + .register_indexer_get(|map: &mut MyMap, index: &str| -> Result<_, Box> { map.get(index).cloned().ok_or_else(|| EvalAltResult::ErrorIndexNotFound(index.into(), rhai::Position::NONE).into()) }) .register_indexer_set(|map: &mut MyMap, index: &str, value: INT| { map.insert(index.to_string(), value); }); diff --git a/tests/if_block.rs b/tests/if_block.rs index a3ab96a75..754bc1adf 100644 --- a/tests/if_block.rs +++ b/tests/if_block.rs @@ -1,4 +1,4 @@ -use spo_rhai::{Engine, INT}; +use rhai::{Engine, INT}; #[test] fn test_if() { diff --git a/tests/increment.rs b/tests/increment.rs index 6c4ee88c4..4dee82aea 100644 --- a/tests/increment.rs +++ b/tests/increment.rs @@ -1,4 +1,4 @@ -use spo_rhai::{Engine, INT}; +use rhai::{Engine, INT}; #[test] fn test_increment() { diff --git a/tests/looping.rs b/tests/looping.rs index 296b7cb39..dc142ee8d 100644 --- a/tests/looping.rs +++ b/tests/looping.rs @@ -1,4 +1,4 @@ -use spo_rhai::{Engine, ParseErrorType, INT}; +use rhai::{Engine, ParseErrorType, INT}; #[test] fn test_loop() { diff --git a/tests/maps.rs b/tests/maps.rs index d04592d40..23e4f7a85 100644 --- a/tests/maps.rs +++ b/tests/maps.rs @@ -1,5 +1,5 @@ #![cfg(not(feature = "no_object"))] -use spo_rhai::{Engine, EvalAltResult, Map, ParseErrorType, Scope, INT}; +use rhai::{Engine, EvalAltResult, Map, ParseErrorType, Scope, INT}; #[test] fn test_map_indexing() { diff --git a/tests/math.rs b/tests/math.rs index d95c249a7..a1f1b155a 100644 --- a/tests/math.rs +++ b/tests/math.rs @@ -1,7 +1,7 @@ -use spo_rhai::{Engine, EvalAltResult, INT}; +use rhai::{Engine, EvalAltResult, INT}; #[cfg(not(feature = "no_float"))] -use spo_rhai::FLOAT; +use rhai::FLOAT; #[test] fn test_math() { diff --git a/tests/method_call.rs b/tests/method_call.rs index c16b5816d..46013a919 100644 --- a/tests/method_call.rs +++ b/tests/method_call.rs @@ -1,5 +1,5 @@ #![cfg(not(feature = "no_object"))] -use spo_rhai::{Engine, EvalAltResult, INT}; +use rhai::{Engine, EvalAltResult, INT}; #[derive(Debug, Clone, Eq, PartialEq)] struct TestStruct { @@ -38,7 +38,7 @@ fn test_method_call_style() { fn test_method_call_with_full_optimization() { let mut engine = Engine::new(); - engine.set_optimization_level(spo_rhai::OptimizationLevel::Full); + engine.set_optimization_level(rhai::OptimizationLevel::Full); engine .register_fn("new_ts", TestStruct::new) diff --git a/tests/mismatched_op.rs b/tests/mismatched_op.rs index 0a4312345..6a692613e 100644 --- a/tests/mismatched_op.rs +++ b/tests/mismatched_op.rs @@ -1,4 +1,4 @@ -use spo_rhai::{Engine, EvalAltResult, INT}; +use rhai::{Engine, EvalAltResult, INT}; #[test] fn test_mismatched_op() { diff --git a/tests/modules.rs b/tests/modules.rs index dd17ce926..c06bf14c4 100644 --- a/tests/modules.rs +++ b/tests/modules.rs @@ -1,11 +1,11 @@ #![cfg(not(feature = "no_module"))] -use spo_rhai::{ +use rhai::{ module_resolvers::{DummyModuleResolver, StaticModuleResolver}, Dynamic, Engine, EvalAltResult, FnNamespace, FuncRegistration, ImmutableString, Module, ParseError, ParseErrorType, Scope, INT, }; // #[cfg(all(not(feature = "no_function"), feature = "internals"))] -use spo_rhai::{FnPtr, NativeCallContext}; +use rhai::{FnPtr, NativeCallContext}; #[test] fn test_module() { @@ -96,7 +96,7 @@ fn test_module_resolver() { FuncRegistration::new("double").with_namespace(FnNamespace::Global).set_into_module(&mut module, f); #[cfg(not(feature = "no_float"))] - module.set_native_fn("sum_of_three_args", |target: &mut INT, a: INT, b: INT, c: spo_rhai::FLOAT| { + module.set_native_fn("sum_of_three_args", |target: &mut INT, a: INT, b: INT, c: rhai::FLOAT| { *target = a + b + c as INT; Ok(()) }); @@ -405,13 +405,13 @@ fn test_module_str() { Ok(input.len() as INT) } - let mut engine = spo_rhai::Engine::new(); + let mut engine = rhai::Engine::new(); let mut module = Module::new(); module.set_native_fn("test", test_fn); module.set_native_fn("test2", test_fn2); module.set_native_fn("test3", test_fn3); - let mut static_modules = spo_rhai::module_resolvers::StaticModuleResolver::new(); + let mut static_modules = rhai::module_resolvers::StaticModuleResolver::new(); static_modules.insert("test", module); engine.set_module_resolver(static_modules); @@ -447,7 +447,7 @@ fn test_module_ast_namespace() { #[cfg(not(feature = "no_function"))] #[test] fn test_module_ast_namespace2() { - use spo_rhai::{Engine, Module, Scope}; + use rhai::{Engine, Module, Scope}; const MODULE_TEXT: &str = " fn run_function(function) { @@ -468,7 +468,7 @@ fn test_module_ast_namespace2() { let mut engine = Engine::new(); let module_ast = engine.compile(MODULE_TEXT).unwrap(); let module = Module::eval_ast_as_new(Scope::new(), &module_ast, &engine).unwrap(); - let mut static_modules = spo_rhai::module_resolvers::StaticModuleResolver::new(); + let mut static_modules = rhai::module_resolvers::StaticModuleResolver::new(); static_modules.insert("test_module", module); engine.set_module_resolver(static_modules); @@ -572,11 +572,11 @@ fn test_module_dynamic() { Ok(s.len() as INT + x) } - let mut engine = spo_rhai::Engine::new(); + let mut engine = rhai::Engine::new(); let mut module = Module::new(); module.set_native_fn("test", test_fn); - let mut static_modules = spo_rhai::module_resolvers::StaticModuleResolver::new(); + let mut static_modules = rhai::module_resolvers::StaticModuleResolver::new(); static_modules.insert("test", module); engine.set_module_resolver(static_modules); engine.register_fn("test2", test_fn); diff --git a/tests/native.rs b/tests/native.rs index 37e535442..e2579482c 100644 --- a/tests/native.rs +++ b/tests/native.rs @@ -1,4 +1,4 @@ -use spo_rhai::{Dynamic, Engine, EvalAltResult, ImmutableString, NativeCallContext, INT}; +use rhai::{Dynamic, Engine, EvalAltResult, ImmutableString, NativeCallContext, INT}; use std::any::TypeId; #[cfg(not(feature = "no_module"))] diff --git a/tests/not.rs b/tests/not.rs index 397ee2633..2eb299d2f 100644 --- a/tests/not.rs +++ b/tests/not.rs @@ -1,4 +1,4 @@ -use spo_rhai::Engine; +use rhai::Engine; #[test] fn test_not() { diff --git a/tests/number_literals.rs b/tests/number_literals.rs index be0a443bd..e222dea46 100644 --- a/tests/number_literals.rs +++ b/tests/number_literals.rs @@ -1,4 +1,4 @@ -use spo_rhai::{Engine, INT}; +use rhai::{Engine, INT}; #[test] fn test_number_literal() { diff --git a/tests/operations.rs b/tests/operations.rs index 14d60e8e7..2657b9a1c 100644 --- a/tests/operations.rs +++ b/tests/operations.rs @@ -1,11 +1,11 @@ #![cfg(not(feature = "unchecked"))] -use spo_rhai::{Engine, EvalAltResult, INT}; +use rhai::{Engine, EvalAltResult, INT}; #[test] fn test_max_operations() { let mut engine = Engine::new(); #[cfg(not(feature = "no_optimize"))] - engine.set_optimization_level(spo_rhai::OptimizationLevel::None); + engine.set_optimization_level(rhai::OptimizationLevel::None); engine.set_max_operations(500); engine.on_progress(|count| { @@ -28,7 +28,7 @@ fn test_max_operations() { fn test_max_operations_literal() { let mut engine = Engine::new(); #[cfg(not(feature = "no_optimize"))] - engine.set_optimization_level(spo_rhai::OptimizationLevel::None); + engine.set_optimization_level(rhai::OptimizationLevel::None); engine.set_max_operations(10); #[cfg(not(feature = "no_index"))] @@ -131,7 +131,7 @@ fn test_max_operations_eval() { fn test_max_operations_progress() { let mut engine = Engine::new(); #[cfg(not(feature = "no_optimize"))] - engine.set_optimization_level(spo_rhai::OptimizationLevel::None); + engine.set_optimization_level(rhai::OptimizationLevel::None); engine.set_max_operations(500); engine.on_progress(|count| if count < 100 { None } else { Some((42 as INT).into()) }); diff --git a/tests/ops.rs b/tests/ops.rs index 8b7ee5559..af0d6dafe 100644 --- a/tests/ops.rs +++ b/tests/ops.rs @@ -1,4 +1,4 @@ -use spo_rhai::{Engine, EvalAltResult, Scope, INT}; +use rhai::{Engine, EvalAltResult, Scope, INT}; #[test] fn test_ops() { diff --git a/tests/optimizer.rs b/tests/optimizer.rs index dd3e9b789..e51ced358 100644 --- a/tests/optimizer.rs +++ b/tests/optimizer.rs @@ -1,5 +1,5 @@ #![cfg(not(feature = "no_optimize"))] -use spo_rhai::{Engine, FuncRegistration, Module, OptimizationLevel, Scope, INT}; +use rhai::{Engine, FuncRegistration, Module, OptimizationLevel, Scope, INT}; #[test] fn test_optimizer() { diff --git a/tests/options.rs b/tests/options.rs index 0f2790ee5..fe330574c 100644 --- a/tests/options.rs +++ b/tests/options.rs @@ -1,4 +1,4 @@ -use spo_rhai::{Engine, Scope, INT}; +use rhai::{Engine, Scope, INT}; #[test] fn test_options_allow() { diff --git a/tests/packages.rs b/tests/packages.rs index da659de1e..99055164d 100644 --- a/tests/packages.rs +++ b/tests/packages.rs @@ -1,5 +1,5 @@ -use spo_rhai::packages::{Package, StandardPackage as SSS}; -use spo_rhai::{def_package, Engine, Module, Scope, INT}; +use rhai::packages::{Package, StandardPackage as SSS}; +use rhai::{def_package, Engine, Module, Scope, INT}; #[cfg(not(feature = "no_module"))] #[cfg(not(feature = "no_custom_syntax"))] diff --git a/tests/plugins.rs b/tests/plugins.rs index c2c503a33..2ba8d2f51 100644 --- a/tests/plugins.rs +++ b/tests/plugins.rs @@ -1,20 +1,20 @@ #![cfg(not(feature = "no_index"))] #![cfg(not(feature = "no_module"))] -use spo_rhai::plugin::*; -use spo_rhai::{Engine, Scope, INT}; +use rhai::plugin::*; +use rhai::{Engine, Scope, INT}; mod test { use super::*; #[export_module] pub mod special_array_package { - use spo_rhai::{Array, INT}; + use rhai::{Array, INT}; pub const MYSTIC_NUMBER: INT = 42; #[cfg(not(feature = "no_object"))] pub mod feature { - use spo_rhai::{Array, Dynamic, EvalAltResult}; + use rhai::{Array, Dynamic, EvalAltResult}; #[rhai_fn(get = "foo", return_raw)] #[inline(always)] diff --git a/tests/plugins_register.rs b/tests/plugins_register.rs index 27e26c326..cd580e1aa 100644 --- a/tests/plugins_register.rs +++ b/tests/plugins_register.rs @@ -1,5 +1,5 @@ -use spo_rhai::plugin::*; -use spo_rhai::{Engine, INT}; +use rhai::plugin::*; +use rhai::{Engine, INT}; #[export_fn] pub fn add_together(x: INT, y: INT) -> INT { diff --git a/tests/plugins_unroll.rs b/tests/plugins_unroll.rs index cbab21ae4..8e612ab05 100644 --- a/tests/plugins_unroll.rs +++ b/tests/plugins_unroll.rs @@ -1,7 +1,7 @@ #![cfg(not(feature = "no_index"))] #![cfg(not(feature = "no_module"))] -use spo_rhai::plugin::*; -use spo_rhai::{Engine, Module, INT}; +use rhai::plugin::*; +use rhai::{Engine, Module, INT}; pub fn add_generic>(x: T, y: T) -> T { x + y @@ -16,7 +16,7 @@ macro_rules! generate_ops { pub mod $op_name { $( pub mod $type_names { - use spo_rhai::plugin::*; + use rhai::plugin::*; use super::super::$op_fn; #[export_fn] pub fn op(x: $type_names, y: $type_names) -> $type_names { diff --git a/tests/power_of.rs b/tests/power_of.rs index 1f3e637ce..2d80b0778 100644 --- a/tests/power_of.rs +++ b/tests/power_of.rs @@ -1,7 +1,7 @@ -use spo_rhai::{Engine, INT}; +use rhai::{Engine, INT}; #[cfg(not(feature = "no_float"))] -use spo_rhai::FLOAT; +use rhai::FLOAT; #[cfg(not(feature = "no_float"))] const EPSILON: FLOAT = FLOAT::EPSILON; diff --git a/tests/print.rs b/tests/print.rs index d2f06138c..21657ab31 100644 --- a/tests/print.rs +++ b/tests/print.rs @@ -1,4 +1,4 @@ -use spo_rhai::{Engine, Scope, INT}; +use rhai::{Engine, Scope, INT}; use std::sync::{Arc, RwLock}; #[cfg(not(feature = "only_i32"))] diff --git a/tests/side_effects.rs b/tests/side_effects.rs index 189d84c0a..31e55bbfa 100644 --- a/tests/side_effects.rs +++ b/tests/side_effects.rs @@ -1,5 +1,5 @@ ///! This test simulates an external command object that is driven by a script. -use spo_rhai::{Engine, Scope, INT}; +use rhai::{Engine, Scope, INT}; use std::sync::{Arc, Mutex, RwLock}; /// Simulate a command object. diff --git a/tests/stack.rs b/tests/stack.rs index cf052098e..1128d2544 100644 --- a/tests/stack.rs +++ b/tests/stack.rs @@ -1,5 +1,5 @@ #![cfg(not(feature = "unchecked"))] -use spo_rhai::{Dynamic, Engine, EvalAltResult, ParseErrorType, INT}; +use rhai::{Dynamic, Engine, EvalAltResult, ParseErrorType, INT}; #[test] #[cfg(not(feature = "no_function"))] diff --git a/tests/string.rs b/tests/string.rs index 8736f0d8e..1af0083d2 100644 --- a/tests/string.rs +++ b/tests/string.rs @@ -1,4 +1,4 @@ -use spo_rhai::{Engine, EvalAltResult, ImmutableString, Scope, INT}; +use rhai::{Engine, EvalAltResult, ImmutableString, Scope, INT}; #[test] fn test_string() { diff --git a/tests/switch.rs b/tests/switch.rs index 7bc07b37c..94915713c 100644 --- a/tests/switch.rs +++ b/tests/switch.rs @@ -1,4 +1,4 @@ -use spo_rhai::{Engine, ParseErrorType, Scope, INT}; +use rhai::{Engine, ParseErrorType, Scope, INT}; #[test] fn test_switch() { @@ -136,7 +136,7 @@ fn test_switch_condition() { #[cfg(not(feature = "no_object"))] mod test_switch_enum { use super::*; - use spo_rhai::Array; + use rhai::Array; #[derive(Debug, Clone)] #[allow(dead_code)] enum MyEnum { diff --git a/tests/throw.rs b/tests/throw.rs index 29d3db0e9..1580eee51 100644 --- a/tests/throw.rs +++ b/tests/throw.rs @@ -1,4 +1,4 @@ -use spo_rhai::{Engine, EvalAltResult, INT}; +use rhai::{Engine, EvalAltResult, INT}; #[test] fn test_throw() { diff --git a/tests/time.rs b/tests/time.rs index 9d82c95bb..d10258d21 100644 --- a/tests/time.rs +++ b/tests/time.rs @@ -1,9 +1,9 @@ #![cfg(not(feature = "no_time"))] -use spo_rhai::Engine; +use rhai::Engine; #[cfg(not(feature = "no_float"))] -use spo_rhai::FLOAT; +use rhai::FLOAT; #[cfg(feature = "no_float")] -use spo_rhai::INT; +use rhai::INT; #[test] fn test_timestamp() { diff --git a/tests/tokens.rs b/tests/tokens.rs index c97a85225..5c74fb239 100644 --- a/tests/tokens.rs +++ b/tests/tokens.rs @@ -1,4 +1,4 @@ -use spo_rhai::{Engine, ParseErrorType, INT}; +use rhai::{Engine, ParseErrorType, INT}; #[test] fn test_tokens_disabled() { diff --git a/tests/types.rs b/tests/types.rs index 39293f6ae..820f2eb19 100644 --- a/tests/types.rs +++ b/tests/types.rs @@ -1,4 +1,4 @@ -use spo_rhai::{Engine, INT}; +use rhai::{Engine, INT}; #[test] fn test_type_of() { diff --git a/tests/unary_after_binary.rs b/tests/unary_after_binary.rs index 0470ac886..518d0d509 100644 --- a/tests/unary_after_binary.rs +++ b/tests/unary_after_binary.rs @@ -1,4 +1,4 @@ -use spo_rhai::{Engine, INT}; +use rhai::{Engine, INT}; #[test] // TODO also add test case for unary after compound diff --git a/tests/unary_minus.rs b/tests/unary_minus.rs index a5957ba7b..c6f6e9a6b 100644 --- a/tests/unary_minus.rs +++ b/tests/unary_minus.rs @@ -1,4 +1,4 @@ -use spo_rhai::{Engine, INT}; +use rhai::{Engine, INT}; #[test] fn test_unary_minus() { diff --git a/tests/unit.rs b/tests/unit.rs index 170d16ed0..aafb64243 100644 --- a/tests/unit.rs +++ b/tests/unit.rs @@ -1,4 +1,4 @@ -use spo_rhai::Engine; +use rhai::Engine; #[test] fn test_unit() { diff --git a/tests/var_scope.rs b/tests/var_scope.rs index 45133ecad..1ea3a5f2f 100644 --- a/tests/var_scope.rs +++ b/tests/var_scope.rs @@ -1,4 +1,4 @@ -use spo_rhai::{Dynamic, Engine, EvalAltResult, Module, ParseErrorType, Position, Scope, INT}; +use rhai::{Dynamic, Engine, EvalAltResult, Module, ParseErrorType, Position, Scope, INT}; #[test] fn test_var_scope() { diff --git a/tests/while_loop.rs b/tests/while_loop.rs index 0f394b199..301ade660 100644 --- a/tests/while_loop.rs +++ b/tests/while_loop.rs @@ -1,4 +1,4 @@ -use spo_rhai::{Engine, INT}; +use rhai::{Engine, INT}; #[test] fn test_while() { From b39d2bfb1b74127783baddbebedc612311c86c7b Mon Sep 17 00:00:00 2001 From: Duy Do Date: Wed, 14 Feb 2024 16:21:59 +0700 Subject: [PATCH 9/9] Revert --- Cargo.toml | 4 ++-- codegen/Cargo.toml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a61050f5d..1ea335a83 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ members = [".", "codegen"] [package] -name = "spo-rhai" +name = "rhai" version = "1.17.2" rust-version = "1.66.0" edition = "2018" @@ -25,7 +25,7 @@ num-traits = { version = "0.2.0", default-features = false } once_cell = { version = "1.7.0", default-features = false, features = ["race"] } bitflags = { version = "2.0.0", default-features = false } smartstring = { version = "1.0.0", default-features = false } -rhai_codegen = { version = "2.0.0", path = "codegen", package = "spo-rhai_codegen" } +rhai_codegen = { version = "2.0.0", path = "codegen", package = "rhai_codegen" } no-std-compat = { git = "https://gitlab.com/jD91mZM2/no-std-compat", version = "0.4.1", default-features = false, features = ["alloc"], optional = true } libm = { version = "0.2.0", default-features = false, optional = true } diff --git a/codegen/Cargo.toml b/codegen/Cargo.toml index feaa71d28..505a06c50 100644 --- a/codegen/Cargo.toml +++ b/codegen/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "spo-rhai_codegen" +name = "rhai_codegen" version = "2.0.0" edition = "2018" resolver = "2" @@ -24,5 +24,5 @@ syn = { version = "2.0.0", features = ["full", "parsing", "printing", "proc-macr quote = "1.0.0" [dev-dependencies] -rhai = { path = "..", features = ["metadata"], package = "spo-rhai" } +rhai = { path = "..", features = ["metadata"], package = "rhai" } trybuild = "1.0.0"