From b7b9ff29e484315aef889d83a3028e26e43dfbda Mon Sep 17 00:00:00 2001 From: tamasfe Date: Mon, 25 Jul 2022 19:01:06 +0200 Subject: [PATCH 01/11] feat: basic definitions --- Cargo.toml | 4 + examples/README.md | 23 +- .../.rhai/definitions/__scope__.d.rhai | 3 + .../.rhai/definitions/__static__.d.rhai | 5731 +++++++++++++++++ .../.rhai/definitions/general_kenobi.d.rhai | 5 + examples/definitions/main.rs | 40 + examples/definitions/script.rhai | 3 + src/definitions.rs | 306 + src/lib.rs | 5 + 9 files changed, 6109 insertions(+), 11 deletions(-) create mode 100644 examples/definitions/.rhai/definitions/__scope__.d.rhai create mode 100644 examples/definitions/.rhai/definitions/__static__.d.rhai create mode 100644 examples/definitions/.rhai/definitions/general_kenobi.d.rhai create mode 100644 examples/definitions/main.rs create mode 100644 examples/definitions/script.rhai create mode 100644 src/definitions.rs diff --git a/Cargo.toml b/Cargo.toml index 7678fb27..75c8a39e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -82,6 +82,10 @@ name = "rhai-run" name = "rhai-dbg" required-features = ["debugging"] +[[example]] +name = "definitions" +required-features = ["metadata"] + [profile.release] lto = "fat" codegen-units = 1 diff --git a/examples/README.md b/examples/README.md index 182b46a5..033be2af 100644 --- a/examples/README.md +++ b/examples/README.md @@ -4,17 +4,18 @@ Sample Applications Standard Examples ----------------- -| Example | Description | -| --------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- | -| [`arrays_and_structs`](arrays_and_structs.rs) | shows how to register a Rust type and using it with arrays | -| [`callback`](callback.rs) | shows how to store a Rhai closure and call it later within Rust | -| [`custom_types_and_methods`](custom_types_and_methods.rs) | shows how to register a Rust type and methods/getters/setters for it | -| [`hello`](hello.rs) | simple example that evaluates an expression and prints the result | -| [`reuse_scope`](reuse_scope.rs) | evaluates two pieces of code in separate runs, but using a common `Scope` | -| [`serde`](serde.rs) | example to serialize and deserialize Rust types with [`serde`](https://crates.io/crates/serde) (requires the `serde` feature) | -| [`simple_fn`](simple_fn.rs) | shows how to register a simple Rust function | -| [`strings`](strings.rs) | shows different ways to register Rust functions taking string arguments | -| [`threading`](threading.rs) | shows how to communicate with an `Engine` running in a separate thread via an MPSC channel | +| Example | Description | +| --------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | +| [`arrays_and_structs`](arrays_and_structs.rs) | shows how to register a Rust type and using it with arrays | +| [`callback`](callback.rs) | shows how to store a Rhai closure and call it later within Rust | +| [`custom_types_and_methods`](custom_types_and_methods.rs) | shows how to register a Rust type and methods/getters/setters for it | +| [`hello`](hello.rs) | simple example that evaluates an expression and prints the result | +| [`reuse_scope`](reuse_scope.rs) | evaluates two pieces of code in separate runs, but using a common `Scope` | +| [`serde`](serde.rs) | example to serialize and deserialize Rust types with [`serde`](https://crates.io/crates/serde) (requires the `serde` feature) | +| [`simple_fn`](simple_fn.rs) | shows how to register a simple Rust function | +| [`strings`](strings.rs) | shows different ways to register Rust functions taking string arguments | +| [`threading`](threading.rs) | shows how to communicate with an `Engine` running in a separate thread via an MPSC channel | +| [`definitions`](./definitions) | shows how to generate definition files for manual inspection or for use with [Rhai LSP](https://github.com/rhaiscript/lsp), requires the `metadata` feature | Scriptable Event Handler With State Examples diff --git a/examples/definitions/.rhai/definitions/__scope__.d.rhai b/examples/definitions/.rhai/definitions/__scope__.d.rhai new file mode 100644 index 00000000..d66567c1 --- /dev/null +++ b/examples/definitions/.rhai/definitions/__scope__.d.rhai @@ -0,0 +1,3 @@ +module static; + +let hello_there; \ No newline at end of file diff --git a/examples/definitions/.rhai/definitions/__static__.d.rhai b/examples/definitions/.rhai/definitions/__static__.d.rhai new file mode 100644 index 00000000..10d7b8c4 --- /dev/null +++ b/examples/definitions/.rhai/definitions/__static__.d.rhai @@ -0,0 +1,5731 @@ +module static; + +op minus(i64, i64) -> i64; + +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; + +op !=(u16, u16) -> bool; + +op !=(f32, f32) -> bool; + +op !=(int, f32) -> bool; + +op !=(i32, i32) -> 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; + +op !=(u64, u64) -> bool; + +op !=(u32, u32) -> bool; + +op !=(i8, i8) -> bool; + +op !=(f32, int) -> bool; + +op !=(i16, i16) -> bool; + +/// Return `true` if two timestamps are not equal. +op !=(Instant, Instant) -> bool; + +op !=(u128, u128) -> bool; + +op !=(u8, u8) -> bool; + +op !=(f64, int) -> bool; + +op !=(int, f64) -> bool; + +op !=(i128, i128) -> bool; + +op %(u8, u8) -> u8; + +op %(i128, i128) -> i128; + +op %(i32, i32) -> i32; + +op %(int, f32) -> f32; + +op %(f32, f32) -> f32; + +op %(u32, u32) -> u32; + +op %(u64, u64) -> u64; + +op %(u16, u16) -> u16; + +op %(i16, i16) -> i16; + +op %(u128, u128) -> u128; + +op %(i8, i8) -> i8; + +op %(f32, int) -> f32; + +op &(i128, i128) -> i128; + +op &(u8, u8) -> u8; + +op &(i8, i8) -> i8; + +op &(u128, u128) -> u128; + +op &(i16, i16) -> i16; + +op &(u16, u16) -> u16; + +op &(u32, u32) -> u32; + +op &(u64, u64) -> u64; + +op &(i32, i32) -> i32; + +op *(i8, i8) -> i8; + +op *(f32, int) -> f32; + +op *(i16, i16) -> i16; + +op *(u128, u128) -> u128; + +op *(u16, u16) -> u16; + +op *(f32, f32) -> f32; + +op *(int, f32) -> f32; + +op *(i32, i32) -> i32; + +op *(u64, u64) -> u64; + +op *(u32, u32) -> u32; + +op *(i128, i128) -> i128; + +op *(u8, u8) -> u8; + +op **(f32, int) -> f32; + +op **(u32, int) -> u32; + +op **(i128, int) -> i128; + +op **(f32, f32) -> f32; + +op **(u8, int) -> u8; + +op **(i8, int) -> i8; + +op **(u64, int) -> u64; + +op **(u128, int) -> u128; + +op **(u16, int) -> u16; + +op **(i16, int) -> i16; + +op **(i32, int) -> i32; + +op +(i128, i128) -> i128; + +op +(String, ()) -> String; + +/// Add the specified number of `seconds` to the timestamp and return it as a new timestamp. +op +(Instant, int) -> Instant; + +op +(char, String) -> String; + +op +(i32) -> i32; + +op +(f32) -> f32; + +op +(String, String) -> String; + +op +(u8, u8) -> u8; + +/// Add the specified number of `seconds` to the timestamp and return it as a new timestamp. +op +(Instant, float) -> Instant; + +op +(String, ?) -> String; + +op +(f64) -> f64; + +op +(int) -> int; + +op +(u128, u128) -> u128; + +op +(Blob, String) -> String; + +op +(i16, i16) -> i16; + +op +((), String) -> String; + +op +(i16) -> i16; + +op +(i8) -> i8; + +op +(f32, int) -> f32; + +op +(i8, i8) -> i8; + +op +(?, String) -> String; + +op +(u32, u32) -> u32; + +/// 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 +(u64, u64) -> u64; + +op +(i32, i32) -> i32; + +op +(String, Blob) -> String; + +op +(int, f32) -> f32; + +op +(f32, f32) -> f32; + +op +(u16, u16) -> u16; + +op +(i128) -> i128; + +/// 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 +(String, char) -> String; + +/// Add the specified number of `seconds` to the timestamp. +op +=(Instant, int) -> (); + +/// Add the specified number of `seconds` to the timestamp. +op +=(Instant, float) -> (); + +op +=(String, ?) -> (); + +/// 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, Blob) -> (); + +op -(i128, i128) -> i128; + +op -(f32) -> f32; + +/// Subtract the specified number of `seconds` from the timestamp and return it as a new timestamp. +op -(Instant, int) -> Instant; + +op -(i32) -> i32; + +/// Subtract the specified number of `seconds` from the timestamp and return it as a new timestamp. +op -(Instant, float) -> Instant; + +op -(u8, u8) -> u8; + +op -(f64) -> f64; + +op -(int) -> int; + +op -(i16, i16) -> i16; + +op -(i16) -> i16; + +/// Return the number of seconds between two timestamps. +op -(Instant, Instant) -> RhaiResult; + +op -(u128, u128) -> u128; + +op -(i8, i8) -> i8; + +op -(i8) -> i8; + +op -(f32, int) -> f32; + +op -(f32, f32) -> f32; + +op -(i32, i32) -> i32; + +op -(int, f32) -> f32; + +op -(u64, u64) -> u64; + +op -(u32, u32) -> u32; + +op -(i128) -> i128; + +op -(u16, u16) -> u16; + +/// 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 /(u8, u8) -> u8; + +op /(i128, i128) -> i128; + +op /(u32, u32) -> u32; + +op /(u64, u64) -> u64; + +op /(int, f32) -> f32; + +op /(i32, i32) -> i32; + +op /(f32, f32) -> f32; + +op /(u16, u16) -> u16; + +op /(u128, u128) -> u128; + +op /(i16, i16) -> i16; + +op /(f32, int) -> f32; + +op /(i8, i8) -> i8; + +op <(i16, i16) -> bool; + +/// Return `true` if the first timestamp is earlier than the second. +op <(Instant, Instant) -> bool; + +op <(u128, u128) -> bool; + +op <(i8, i8) -> bool; + +op <(f32, int) -> bool; + +op <(f32, f32) -> bool; + +op <(int, f32) -> bool; + +op <(i32, i32) -> bool; + +op <(u64, u64) -> bool; + +op <(u32, u32) -> bool; + +op <(u16, u16) -> bool; + +op <(int, f64) -> bool; + +op <(i128, i128) -> bool; + +op <(f64, int) -> bool; + +op <(u8, u8) -> bool; + +op <<(u32, int) -> u32; + +op <<(i128, int) -> i128; + +op <<(u8, int) -> u8; + +op <<(i8, int) -> i8; + +op <<(u64, int) -> u64; + +op <<(u128, int) -> u128; + +op <<(u16, int) -> u16; + +op <<(i16, int) -> i16; + +op <<(i32, int) -> i32; + +op <=(int, f64) -> bool; + +op <=(i128, i128) -> bool; + +op <=(f64, int) -> bool; + +op <=(u8, u8) -> bool; + +op <=(i16, i16) -> bool; + +/// Return `true` if the first timestamp is earlier than or equals to the second. +op <=(Instant, Instant) -> bool; + +op <=(u128, u128) -> bool; + +op <=(i8, i8) -> bool; + +op <=(f32, int) -> bool; + +op <=(f32, f32) -> bool; + +op <=(i32, i32) -> bool; + +op <=(int, f32) -> bool; + +op <=(u64, u64) -> bool; + +op <=(u32, u32) -> bool; + +op <=(u16, u16) -> bool; + +/// Return `true` if two timestamps are equal. +op ==(Instant, Instant) -> bool; + +op ==(i16, i16) -> bool; + +op ==(u128, u128) -> bool; + +op ==(i8, i8) -> bool; + +op ==(f32, int) -> bool; + +op ==(int, f32) -> bool; + +op ==(i32, i32) -> bool; + +op ==(f32, f32) -> bool; + +op ==(u32, u32) -> 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; + +op ==(u64, u64) -> 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; + +op ==(u16, u16) -> bool; + +op ==(i128, i128) -> bool; + +op ==(int, f64) -> bool; + +op ==(f64, int) -> bool; + +op ==(u8, u8) -> bool; + +op >(f64, int) -> bool; + +op >(i128, i128) -> bool; + +op >(int, f64) -> bool; + +op >(u8, u8) -> bool; + +op >(f32, int) -> bool; + +op >(i8, i8) -> bool; + +op >(u128, u128) -> bool; + +/// Return `true` if the first timestamp is later than the second. +op >(Instant, Instant) -> bool; + +op >(i16, i16) -> bool; + +op >(u16, u16) -> bool; + +op >(u32, u32) -> bool; + +op >(u64, u64) -> bool; + +op >(i32, i32) -> bool; + +op >(int, f32) -> bool; + +op >(f32, f32) -> bool; + +op >=(u16, u16) -> bool; + +op >=(u32, u32) -> bool; + +op >=(u64, u64) -> bool; + +op >=(int, f32) -> bool; + +op >=(i32, i32) -> bool; + +op >=(f32, f32) -> bool; + +op >=(f32, int) -> bool; + +op >=(i8, i8) -> bool; + +op >=(u128, u128) -> bool; + +/// Return `true` if the first timestamp is later than or equals to the second. +op >=(Instant, Instant) -> bool; + +op >=(i16, i16) -> bool; + +op >=(u8, u8) -> bool; + +op >=(f64, int) -> bool; + +op >=(i128, i128) -> bool; + +op >=(int, f64) -> bool; + +op >>(u128, int) -> u128; + +op >>(u64, int) -> u64; + +op >>(i8, int) -> i8; + +op >>(u8, int) -> u8; + +op >>(i32, int) -> i32; + +op >>(i16, int) -> i16; + +op >>(u16, int) -> u16; + +op >>(i128, int) -> i128; + +op >>(u32, int) -> u32; + +/// Return the natural number _e_. +fn E() -> float; + +/// Return the number π. +fn PI() -> float; + +op ^(u8, u8) -> u8; + +op ^(i128, i128) -> i128; + +op ^(u16, u16) -> u16; + +op ^(u64, u64) -> u64; + +op ^(u32, u32) -> u32; + +op ^(i32, i32) -> i32; + +op ^(i8, i8) -> i8; + +op ^(u128, u128) -> u128; + +op ^(i16, i16) -> i16; + +/// Return the absolute value of the number. +fn abs(x: int) -> int; + +/// Return the absolute value of the floating-point number. +fn abs(x: f64) -> f64; + +/// Return the absolute value of the floating-point number. +fn abs(x: f32) -> f32; + +/// Return the absolute value of the number. +fn abs(x: i32) -> i32; + +/// 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: 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 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 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 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) -> (); + +fn append(string: String, utf8: Blob) -> (); + +/// 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.push(y); +/// +/// print(x); // prints "[1, 2, 3, true, 'x']" +/// ``` +fn append(array: Array, new_array: Array) -> (); + +/// 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: ?) -> (); + +/// 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 numbers `x` and `y`, in radians. +fn atan(x: float, y: float) -> float; + +/// Return the arc-tangent of the floating-point number, in radians. +fn atan(x: float) -> float; + +/// Return the arc-hyperbolic-tangent of the floating-point number, in radians. +fn atanh(x: float) -> float; + +/// 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 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 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 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 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 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 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 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 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 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 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 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) -> (); + +/// 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) -> (); + +/// Clear the object map. +fn clear(map: Map) -> (); + +/// Clear the string, making it empty. +fn clear(string: String) -> (); + +/// Clear the BLOB. +fn clear(blob: Blob) -> (); + +/// Clear the array. +fn clear(array: Array) -> (); + +/// 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 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 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) -> (); + +/// 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: ExclusiveRange) -> (); + +/// 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: InclusiveRange) -> (); + +/// Convert the boolean value into a string in debug format. +fn debug(value: bool) -> String; + +/// Convert the array into a string. +fn debug(array: Array) -> String; + +/// Convert the string into debug format. +fn debug(character: char) -> String; + +/// Convert the unit into a string in debug format. +fn debug(unit: ()) -> String; + +/// Return the empty string. +fn debug() -> String; + +/// Convert the value of the `item` into a string in debug format. +fn debug(item: ?) -> String; + +/// Convert the function pointer into a string in debug format. +fn debug(f: FnPtr) -> String; + +/// Convert the object map into a string. +fn debug(map: Map) -> String; + +/// Convert the value of `number` into a string. +fn debug(number: f32) -> String; + +/// Convert the string into debug format. +fn debug(string: String) -> String; + +/// Convert the value of `number` into a string. +fn debug(number: f64) -> String; + +/// 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. +/// +/// 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 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 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: ExclusiveRange) -> Blob; + +/// 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; + +/// 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 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: InclusiveRange) -> Array; + +/// 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: InclusiveRange) -> 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 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: ExclusiveRange) -> Array; + +/// 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 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: InclusiveRange) -> Blob; + +/// 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: InclusiveRange) -> Array; + +/// 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 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 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 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: ExclusiveRange) -> Blob; + +/// 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: ExclusiveRange) -> 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 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) -> ?; + +/// 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 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) -> ?; + +/// 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 inclusive range. +fn get end(range: InclusiveRange) -> int; + +/// Return the end of the exclusive range. +fn get end(range: ExclusiveRange) -> 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 number is even. +fn get is_even(x: i128) -> 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: i8) -> 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: i16) -> 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: u8) -> 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: i32) -> bool; + +/// Return true if the number is even. +fn get is_even(x: u64) -> 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: u32) -> 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: u16) -> 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: u8) -> 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: u64) -> bool; + +/// Return true if the number is odd. +fn get is_odd(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: u16) -> 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: i128) -> 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: i32) -> bool; + +/// Return true if the floating-point number is zero. +fn get is_zero(x: f32) -> 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: int) -> bool; + +/// Return true if the floating-point number is zero. +fn get is_zero(x: f64) -> bool; + +/// Return true if the number is zero. +fn get is_zero(x: u8) -> bool; + +/// Return true if the number is zero. +fn get is_zero(x: u128) -> bool; + +/// 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 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; + +/// Number of elements in the array. +fn get len(array: Array) -> 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 inclusive range. +fn get start(range: InclusiveRange) -> int; + +/// Return the start of the exclusive range. +fn get start(range: ExclusiveRange) -> 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 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; + +/// 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: InclusiveRange) -> int; + +/// 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: ExclusiveRange) -> int; + +fn get_fn_metadata_list(name: String) -> Array; + +fn get_fn_metadata_list(name: String, params: int) -> Array; + +fn get_fn_metadata_list() -> Array; + +/// Return the hypotenuse of a triangle with sides `x` and `y`. +fn hypot(x: float, y: float) -> float; + +/// 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; + +/// 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 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; + +/// 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; + +/// 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 `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 `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 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; + +/// 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; + +/// 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; + +/// 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 number is even. +fn is_even(x: i128) -> 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: u16) -> 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: i16) -> 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: u128) -> bool; + +/// Return true if the number is even. +fn is_even(x: u8) -> 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: i32) -> bool; + +/// Return `true` if the range is exclusive. +fn is_exclusive(range: InclusiveRange) -> bool; + +/// Return `true` if the range is exclusive. +fn is_exclusive(range: ExclusiveRange) -> 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: u8) -> 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: int) -> 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: u64) -> 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: 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: i8) -> bool; + +/// Return true if the number is odd. +fn is_odd(x: u16) -> bool; + +/// Return true if the number is zero. +fn is_zero(x: u8) -> 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: int) -> bool; + +/// Return true if the floating-point number is zero. +fn is_zero(x: f64) -> bool; + +/// Return true if the floating-point number is zero. +fn is_zero(x: f32) -> 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: u64) -> 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: 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: i8) -> bool; + +/// Return true if the number is zero. +fn is_zero(x: u16) -> 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; + +/// 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 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; + +/// Number of elements in the array. +fn len(array: Array) -> 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`. +fn log(x: float, base: float) -> float; + +/// Return the log of the floating-point number with base 10. +fn log(x: float) -> float; + +/// 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 lower-case. +/// +/// # Example +/// +/// ```rhai +/// let ch = 'A'; +/// +/// ch.make_lower(); +/// +/// print(ch); // prints 'a' +/// ``` +fn make_lower(character: char) -> (); + +/// 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 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) -> (); + +/// 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 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 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) -> (); + +/// 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: InclusiveRange) -> float; + +/// 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: ExclusiveRange) -> 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 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 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: ExclusiveRange) -> 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: InclusiveRange) -> 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 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: InclusiveRange) -> 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 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: ExclusiveRange) -> 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: ExclusiveRange) -> 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; + +/// 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: InclusiveRange) -> int; + +/// 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; + +/// 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 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 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) -> ?; + +/// Return the `string`. +fn print(string: String) -> String; + +/// Return the empty string. +fn print() -> String; + +/// Convert the value of `number` into a string. +fn print(number: f64) -> String; + +/// Convert the object map into a string. +fn print(map: Map) -> String; + +/// Convert the value of `number` into a string. +fn print(number: f32) -> String; + +/// Convert the value of the `item` into a string. +fn print(item: ?) -> String; + +/// Return the boolean value into a string. +fn print(value: bool) -> String; + +/// Convert the array into a string. +fn print(array: Array) -> String; + +/// Return the character into a string. +fn print(character: char) -> String; + +/// Return the empty string. +fn print(unit: ()) -> 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 push(blob: Blob, value: int) -> (); + +/// 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: ?) -> (); + +/// 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: i8, to: i8, step: 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: u16, to: 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: i32, to: i32, 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: 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: 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: u64, to: 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: 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: u32, to: 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: i128, to: i128, 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: 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: i8, to: 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: 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: u8) -> 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`, 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 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 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`, 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: ?, to: ?, step: ?) -> 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: i64, to: i64, step: i64) -> 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 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; + +/// 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: 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: ?, step: ?) -> 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: i64) -> 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`. +/// 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: i64, to: i64) -> 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`. +/// 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 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 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; + +/// 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 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 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, 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, 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; + +/// 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, 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; + +/// 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 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) -> (); + +/// 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 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) -> (); + +/// 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 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) -> (); + +/// 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 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) -> (); + +/// 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; + +/// 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: InclusiveRange) -> Blob; + +/// 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: InclusiveRange) -> Array; + +/// 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 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: ExclusiveRange) -> Blob; + +/// 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: ExclusiveRange) -> Array; + +/// 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 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; + +/// 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) -> (); + +/// 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) -> (); + +/// Return the nearest whole number closest to the floating-point number. +/// Rounds away from zero. +fn round(x: float) -> float; + +/// 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 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 _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: ExclusiveRange, 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: InclusiveRange, 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 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; + +/// 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) -> ?; + +/// 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 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: 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: i32) -> 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 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: f64) -> 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: ?) -> (); + +/// Block the current thread for a particular number of `seconds`. +fn sleep(seconds: int) -> (); + +/// 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 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) -> (); + +/// 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) -> (); + +/// 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: ExclusiveRange, 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: InclusiveRange, replace: Blob) -> (); + +/// 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: ExclusiveRange, replace: Array) -> (); + +/// 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 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: InclusiveRange, 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) -> (); + +/// 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 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; + +/// 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; + +/// 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; + +/// 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 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` 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 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; + +/// 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; + +/// 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 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 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: ExclusiveRange) -> 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; + +/// 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: InclusiveRange) -> 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. +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: u8) -> 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: i64) -> 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: u64) -> 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: 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: i8) -> String; + +/// Convert the `value` into a string in binary format. +fn to_binary(value: u16) -> 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 value of `number` into a string. +fn to_debug(number: f32) -> 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: f64) -> String; + +/// Convert the string into debug format. +fn to_debug(string: String) -> String; + +/// Convert the string into debug format. +fn to_debug(character: char) -> 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 the array into a string. +fn to_debug(array: Array) -> 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 radians to degrees. +fn to_degrees(x: float) -> float; + +fn to_float(x: u8) -> float; + +fn to_float(x: u128) -> float; + +fn to_float(x: i64) -> float; + +/// Convert the 32-bit floating-point number to 64-bit. +fn to_float(x: f32) -> f64; + +fn to_float(x: i32) -> float; + +fn to_float(x: u32) -> float; + +fn to_float(x: i128) -> float; + +fn to_float(x: i16) -> float; + +fn to_float(x: i8) -> float; + +fn to_float(x: u16) -> float; + +/// 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: u64) -> String; + +/// Convert the `value` into a string in hex format. +fn to_hex(value: i64) -> String; + +/// Convert the `value` into a string in hex format. +fn to_hex(value: u8) -> 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: i8) -> 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: i16) -> String; + +/// 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: u32) -> String; + +fn to_int(x: i128) -> int; + +fn to_int(x: u32) -> int; + +fn to_int(x: i8) -> int; + +fn to_int(x: char) -> int; + +fn to_int(x: u16) -> int; + +fn to_int(x: i16) -> int; + +/// Convert the floating-point number into an integer. +fn to_int(x: f64) -> int; + +fn to_int(x: i64) -> int; + +fn to_int(x: u8) -> int; + +fn to_int(x: u128) -> int; + +fn to_int(x: i32) -> int; + +/// Convert the floating-point number into an integer. +fn to_int(x: f32) -> int; + +fn to_int(x: u64) -> 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: u32) -> 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: u16) -> 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: i64) -> String; + +/// Convert the `value` into a string in octal format. +fn to_octal(value: u8) -> 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: i32) -> String; + +/// Convert the `value` into a string in octal format. +fn to_octal(value: u64) -> String; + +/// Convert degrees to radians. +fn to_radians(x: float) -> float; + +/// Return the `string`. +fn to_string(string: String) -> String; + +/// Convert the value of `number` into a string. +fn to_string(number: f64) -> 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 the `item` into a string. +fn to_string(item: ?) -> String; + +/// Return the boolean value into a string. +fn to_string(value: bool) -> String; + +/// Convert the array into a string. +fn to_string(array: Array) -> String; + +/// Return the empty string. +fn to_string(unit: ()) -> String; + +/// Return the character into a string. +fn to_string(character: char) -> String; + +/// 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; + +/// 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; + +/// 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 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) -> (); + +/// 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) -> (); + +/// 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 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: InclusiveRange, string: String) -> (); + +/// 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: ExclusiveRange, 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 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: InclusiveRange, value: int) -> (); + +/// 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: ExclusiveRange, value: float) -> (); + +/// 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: InclusiveRange, 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: ExclusiveRange, value: int) -> (); + +/// 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 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 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 `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: InclusiveRange, 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: InclusiveRange, 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 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: ExclusiveRange, 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: ExclusiveRange, value: int) -> (); + +/// 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: InclusiveRange, string: String) -> (); + +/// 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: ExclusiveRange, 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 |(i32, i32) -> i32; + +op |(u64, u64) -> u64; + +op |(u32, u32) -> u32; + +op |(u16, u16) -> u16; + +op |(i16, i16) -> i16; + +op |(u128, u128) -> u128; + +op |(i8, i8) -> i8; + +op |(u8, u8) -> u8; + +op |(i128, i128) -> i128; \ 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 new file mode 100644 index 00000000..c6485585 --- /dev/null +++ b/examples/definitions/.rhai/definitions/general_kenobi.d.rhai @@ -0,0 +1,5 @@ +module general_kenobi; + +/// Returns a string where `hello there ` +/// is repeated `n` times. +fn hello_there(n: i64) -> String; \ No newline at end of file diff --git a/examples/definitions/main.rs b/examples/definitions/main.rs new file mode 100644 index 00000000..0638f8e8 --- /dev/null +++ b/examples/definitions/main.rs @@ -0,0 +1,40 @@ +use rhai::{plugin::*, Engine, Scope}; + +#[export_module] +pub mod general_kenobi { + /// 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() { + 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"); + + engine.register_static_module("general_kenobi", exported_module!(general_kenobi).into()); + + // Custom operators also show up in definitions. + engine.register_custom_operator("minus", 100).unwrap(); + engine.register_fn("minus", |a: i64, b: i64| a - b); + + engine + .eval_with_scope::<()>( + &mut scope, + r#" +hello_there = general_kenobi::hello_there(4 minus 2); +"#, + ) + .unwrap(); + + engine + .definitions_with_scope(&scope) + .write_to_dir("examples/definitions/.rhai/definitions") + .unwrap(); +} diff --git a/examples/definitions/script.rhai b/examples/definitions/script.rhai new file mode 100644 index 00000000..1b8da1aa --- /dev/null +++ b/examples/definitions/script.rhai @@ -0,0 +1,3 @@ +// The following will be valid based on the definitions. +hello_there = general_kenobi::hello_there(123); +print(hello_there); diff --git a/src/definitions.rs b/src/definitions.rs new file mode 100644 index 00000000..b44c28d1 --- /dev/null +++ b/src/definitions.rs @@ -0,0 +1,306 @@ +use crate::{ + module::FuncInfo, plugin::*, tokenizer::is_valid_function_name, Engine, Module, Scope, +}; +use core::fmt; +use std::{borrow::Cow, fs, io, path::Path}; + +impl Engine { + /// Return [`Definitions`] that can be used to + /// generate definition files that contain all + /// the visible items in the engine. + /// + /// # Example + /// + /// ```no_run + /// # use rhai::Engine; + /// # fn main() -> io::Result<()> { + /// let engine = Engine::new(); + /// engine + /// .definitions() + /// .write_to_dir(".rhai/definitions")?; + /// # Ok(()) + /// # } + /// ``` + pub fn definitions(&self) -> Definitions { + Definitions { + engine: self, + scope: None, + } + } + + /// Return [`Definitions`] that can be used to + /// generate definition files that contain all + /// the visible items in the engine and the + /// given scope. + /// + /// # Example + /// + /// ```no_run + /// # use rhai::{Engine, Scope}; + /// # fn main() -> io::Result<()> { + /// let engine = Engine::new(); + /// let scope = Scope::new(); + /// engine + /// .definitions_with_scope(&scope) + /// .write_to_dir(".rhai/definitions")?; + /// # Ok(()) + /// # } + /// ``` + pub fn definitions_with_scope<'e>(&'e self, scope: &'e Scope<'e>) -> Definitions<'e> { + Definitions { + engine: self, + scope: Some(scope), + } + } +} + +/// Definitions helper that is used to generate +/// definition files based on the contents of an [`Engine`]. +#[must_use] +pub struct Definitions<'e> { + engine: &'e Engine, + scope: Option<&'e Scope<'e>>, +} + +impl<'e> Definitions<'e> { + /// Write all the definition files to a directory. + /// + /// The following separate definition files are generated: + /// + /// - `__static__.d.rhai`: globally available items of the engine + /// - `__scope__.d.rhai`: items in the given scope, if any + /// - a separate file for each registered module + pub fn write_to_dir(&self, path: impl AsRef) -> io::Result<()> { + let path = path.as_ref(); + + fs::create_dir_all(path)?; + + fs::write(path.join("__static__.d.rhai"), self.static_module())?; + + if self.scope.is_some() { + fs::write(path.join("__scope__.d.rhai"), self.scope())?; + } + + for (name, decl) in self.modules() { + fs::write(path.join(format!("{name}.d.rhai")), decl)?; + } + + Ok(()) + } + + /// Return the definitions for the globally available + /// items of the engine. + /// + /// The definitions will always start with `module static;`. + #[must_use] + pub fn static_module(&self) -> String { + let mut s = String::from("module static;\n\n"); + + let mut first = true; + for m in &self.engine.global_modules { + if !first { + s += "\n\n"; + } + first = false; + m.write_declaration(&mut s, self).unwrap(); + } + + s + } + + /// Return the definitions for the available + /// items of the scope. + /// + /// The definitions will always start with `module static;`, + /// even if the scope is empty or none was provided. + #[must_use] + pub fn scope(&self) -> String { + let mut s = String::from("module static;\n\n"); + + if let Some(scope) = self.scope { + scope.write_declaration(&mut s).unwrap(); + } + + s + } + + /// Return name and definition pairs for each registered module. + /// + /// The definitions will always start with `module ;`. + #[cfg(not(feature = "no_module"))] + pub fn modules(&self) -> impl Iterator + '_ { + let mut m = self + .engine + .global_sub_modules + .iter() + .map(move |(name, module)| { + ( + name.to_string(), + format!("module {name};\n\n{}", module.declaration(self)), + ) + }) + .collect::>(); + + m.sort_by(|(name1, _), (name2, _)| name1.cmp(name2)); + + m.into_iter() + } +} + +impl Module { + fn declaration(&self, decl: &Definitions) -> String { + let mut s = String::new(); + self.write_declaration(&mut s, decl).unwrap(); + s + } + + fn write_declaration(&self, writer: &mut dyn fmt::Write, decl: &Definitions) -> fmt::Result { + let mut first = true; + + let mut vars = self.iter_var().collect::>(); + vars.sort_by(|(a, _), (b, _)| a.cmp(b)); + + for (name, _) in vars { + if !first { + writer.write_str("\n\n")?; + } + first = false; + + write!(writer, "const {name}: ?;")?; + } + + let mut func_infos = self.iter_fn().collect::>(); + func_infos.sort_by(|a, b| a.metadata.name.cmp(&b.metadata.name)); + + for f in func_infos { + if !first { + writer.write_str("\n\n")?; + } + first = false; + + if f.metadata.access == FnAccess::Private { + continue; + } + + f.write_declaration( + writer, + decl.engine.custom_keywords.contains_key(&f.metadata.name) + || (!f.metadata.name.contains('$') + && !is_valid_function_name(&f.metadata.name)), + )?; + } + + Ok(()) + } +} + +impl FuncInfo { + fn write_declaration(&self, writer: &mut dyn fmt::Write, operator: bool) -> fmt::Result { + for comment in &*self.metadata.comments { + writeln!(writer, "{comment}")?; + } + + if operator { + writer.write_str("op ")?; + } else { + writer.write_str("fn ")?; + } + + if let Some(name) = self.metadata.name.strip_prefix("get$") { + write!(writer, "get {name}(")?; + } else if let Some(name) = self.metadata.name.strip_prefix("set$") { + write!(writer, "set {name}(")?; + } else { + write!(writer, "{}(", self.metadata.name)?; + } + + let mut first = true; + for i in 0..self.metadata.params { + if !first { + writer.write_str(", ")?; + } + first = false; + + let (param_name, param_type) = self + .metadata + .params_info + .get(i) + .map(|s| { + let mut s = s.split(':'); + ( + s.next().unwrap_or("_").split(' ').last().unwrap(), + s.next().map(decl_type_name).unwrap_or(Cow::Borrowed("?")), + ) + }) + .unwrap_or(("_", "?".into())); + + if operator { + write!(writer, "{param_type}")?; + } else { + write!(writer, "{param_name}: {param_type}")?; + } + } + + write!( + writer, + ") -> {};", + decl_type_name(&self.metadata.return_type) + )?; + + Ok(()) + } +} + +/// We have to transform some of the types. +/// +/// This is highly inefficient and is currently based on +/// trial and error with the core packages. +/// +/// It tries to flatten types, removing `&` and `&mut`, +/// and paths, while keeping generics. +/// +/// Associated generic types are also rewritten into regular +/// generic type parameters. +fn decl_type_name(ty: &str) -> Cow { + let ty = ty.replace("crate::", ""); + let ty = ty.split("::").last().unwrap(); + let ty = ty.trim(); + let ty = ty.strip_prefix("&mut").unwrap_or(ty).trim(); + + let ty = ty + .strip_prefix("RhaiResultOf<") + .and_then(|s| s.strip_suffix('>')) + .map(str::trim) + .unwrap_or(ty); + + // FIXME(tamasfe): some of the given types are unusable, + // e.g. "Range { + fn write_declaration(&self, writer: &mut dyn fmt::Write) -> fmt::Result { + let mut first = true; + for (name, constant, _) in self.iter_raw() { + if !first { + writer.write_str("\n\n")?; + } + first = false; + + let kw = if constant { "const" } else { "let" }; + + write!(writer, "{kw} {name};")?; + } + + Ok(()) + } +} diff --git a/src/lib.rs b/src/lib.rs index e476fb15..cc3b6d7d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -82,6 +82,8 @@ mod reify; mod tests; mod tokenizer; mod types; +#[cfg(feature = "metadata")] +mod definitions; /// Error encountered when parsing a script. type PERR = ParseErrorType; @@ -258,6 +260,9 @@ pub mod serde; #[cfg(not(feature = "no_optimize"))] pub use optimizer::OptimizationLevel; +#[cfg(feature = "metadata")] +pub use definitions::Definitions; + /// Placeholder for the optimization level. #[cfg(feature = "no_optimize")] pub type OptimizationLevel = (); From c0785f7004a4cc960bdf3b7df74e4a098f7396f7 Mon Sep 17 00:00:00 2001 From: tamasfe Date: Tue, 26 Jul 2022 10:26:23 +0200 Subject: [PATCH 02/11] fix(definitions): no_std and type names --- src/definitions.rs | 67 +++++++++++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 27 deletions(-) diff --git a/src/definitions.rs b/src/definitions.rs index b44c28d1..ef58a146 100644 --- a/src/definitions.rs +++ b/src/definitions.rs @@ -2,7 +2,15 @@ use crate::{ module::FuncInfo, plugin::*, tokenizer::is_valid_function_name, Engine, Module, Scope, }; use core::fmt; -use std::{borrow::Cow, fs, io, path::Path}; + +#[cfg(feature = "no_std")] +use alloc::borrow::Cow; + +#[cfg(feature = "no_std")] +use alloc::string::String; + +#[cfg(not(feature = "no_std"))] +use std::borrow::Cow; impl Engine { /// Return [`Definitions`] that can be used to @@ -13,7 +21,7 @@ impl Engine { /// /// ```no_run /// # use rhai::Engine; - /// # fn main() -> io::Result<()> { + /// # fn main() -> std::io::Result<()> { /// let engine = Engine::new(); /// engine /// .definitions() @@ -37,7 +45,7 @@ impl Engine { /// /// ```no_run /// # use rhai::{Engine, Scope}; - /// # fn main() -> io::Result<()> { + /// # fn main() -> std::io::Result<()> { /// let engine = Engine::new(); /// let scope = Scope::new(); /// engine @@ -70,7 +78,10 @@ impl<'e> Definitions<'e> { /// - `__static__.d.rhai`: globally available items of the engine /// - `__scope__.d.rhai`: items in the given scope, if any /// - a separate file for each registered module - pub fn write_to_dir(&self, path: impl AsRef) -> io::Result<()> { + #[cfg(not(feature = "no_std"))] + pub fn write_to_dir(&self, path: impl AsRef) -> std::io::Result<()> { + use std::fs; + let path = path.as_ref(); fs::create_dir_all(path)?; @@ -102,7 +113,7 @@ impl<'e> Definitions<'e> { s += "\n\n"; } first = false; - m.write_declaration(&mut s, self).unwrap(); + m.write_definition(&mut s, self).unwrap(); } s @@ -118,7 +129,7 @@ impl<'e> Definitions<'e> { let mut s = String::from("module static;\n\n"); if let Some(scope) = self.scope { - scope.write_declaration(&mut s).unwrap(); + scope.write_definition(&mut s).unwrap(); } s @@ -136,7 +147,7 @@ impl<'e> Definitions<'e> { .map(move |(name, module)| { ( name.to_string(), - format!("module {name};\n\n{}", module.declaration(self)), + format!("module {name};\n\n{}", module.definition(self)), ) }) .collect::>(); @@ -148,13 +159,13 @@ impl<'e> Definitions<'e> { } impl Module { - fn declaration(&self, decl: &Definitions) -> String { + fn definition(&self, def: &Definitions) -> String { let mut s = String::new(); - self.write_declaration(&mut s, decl).unwrap(); + self.write_definition(&mut s, def).unwrap(); s } - fn write_declaration(&self, writer: &mut dyn fmt::Write, decl: &Definitions) -> fmt::Result { + fn write_definition(&self, writer: &mut dyn fmt::Write, def: &Definitions) -> fmt::Result { let mut first = true; let mut vars = self.iter_var().collect::>(); @@ -182,9 +193,10 @@ impl Module { continue; } - f.write_declaration( + f.write_definition( writer, - decl.engine.custom_keywords.contains_key(&f.metadata.name) + def, + def.engine.custom_keywords.contains_key(&f.metadata.name) || (!f.metadata.name.contains('$') && !is_valid_function_name(&f.metadata.name)), )?; @@ -195,7 +207,12 @@ impl Module { } impl FuncInfo { - fn write_declaration(&self, writer: &mut dyn fmt::Write, operator: bool) -> fmt::Result { + fn write_definition( + &self, + writer: &mut dyn fmt::Write, + def: &Definitions, + operator: bool, + ) -> fmt::Result { for comment in &*self.metadata.comments { writeln!(writer, "{comment}")?; } @@ -226,10 +243,12 @@ impl FuncInfo { .params_info .get(i) .map(|s| { - let mut s = s.split(':'); + let mut s = s.splitn(2, ':'); ( s.next().unwrap_or("_").split(' ').last().unwrap(), - s.next().map(decl_type_name).unwrap_or(Cow::Borrowed("?")), + s.next() + .map(|ty| def_type_name(ty, def.engine)) + .unwrap_or(Cow::Borrowed("?")), ) }) .unwrap_or(("_", "?".into())); @@ -244,7 +263,7 @@ impl FuncInfo { write!( writer, ") -> {};", - decl_type_name(&self.metadata.return_type) + def_type_name(&self.metadata.return_type, def.engine) )?; Ok(()) @@ -261,11 +280,10 @@ impl FuncInfo { /// /// Associated generic types are also rewritten into regular /// generic type parameters. -fn decl_type_name(ty: &str) -> Cow { - let ty = ty.replace("crate::", ""); +fn def_type_name<'a>(ty: &'a str, engine: &'a Engine) -> Cow<'a, str> { + let ty = engine.format_type_name(ty).replace("crate::", ""); + let ty = ty.strip_prefix("&mut").unwrap_or(&*ty).trim(); let ty = ty.split("::").last().unwrap(); - let ty = ty.trim(); - let ty = ty.strip_prefix("&mut").unwrap_or(ty).trim(); let ty = ty .strip_prefix("RhaiResultOf<") @@ -273,12 +291,7 @@ fn decl_type_name(ty: &str) -> Cow { .map(str::trim) .unwrap_or(ty); - // FIXME(tamasfe): some of the given types are unusable, - // e.g. "Range Cow { } impl Scope<'_> { - fn write_declaration(&self, writer: &mut dyn fmt::Write) -> fmt::Result { + fn write_definition(&self, writer: &mut dyn fmt::Write) -> fmt::Result { let mut first = true; for (name, constant, _) in self.iter_raw() { if !first { From 8ebc50bea850131b8d9b13dcd101da311f1f0b81 Mon Sep 17 00:00:00 2001 From: tamasfe Date: Tue, 26 Jul 2022 13:39:50 +0200 Subject: [PATCH 03/11] feat(defs): builtin definitions --- .../definitions/__builtin-operators__.d.rhai | 251 + .../.rhai/definitions/__builtin__.d.rhai | 170 + .../.rhai/definitions/__static__.d.rhai | 4202 ++++++++--------- src/definitions/builtin-operators.d.rhai | 251 + src/definitions/builtin.d.rhai | 170 + src/{definitions.rs => definitions/mod.rs} | 3 + 6 files changed, 2946 insertions(+), 2101 deletions(-) create mode 100644 examples/definitions/.rhai/definitions/__builtin-operators__.d.rhai create mode 100644 examples/definitions/.rhai/definitions/__builtin__.d.rhai create mode 100644 src/definitions/builtin-operators.d.rhai create mode 100644 src/definitions/builtin.d.rhai rename src/{definitions.rs => definitions/mod.rs} (97%) diff --git a/examples/definitions/.rhai/definitions/__builtin-operators__.d.rhai b/examples/definitions/.rhai/definitions/__builtin-operators__.d.rhai new file mode 100644 index 00000000..d907afcf --- /dev/null +++ b/examples/definitions/.rhai/definitions/__builtin-operators__.d.rhai @@ -0,0 +1,251 @@ +module static; + +op ==(i64, i64) -> bool; +op !=(i64, i64) -> bool; +op >(i64, i64) -> bool; +op >=(i64, i64) -> bool; +op <(i64, i64) -> bool; +op <=(i64, i64) -> bool; +op &(i64, i64) -> i64; +op |(i64, i64) -> i64; +op ^(i64, i64) -> i64; +op ..(i64, i64) -> Range; +op ..=(i64, i64) -> 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 +(i64, i64) -> i64; +op -(i64, i64) -> i64; +op *(i64, i64) -> i64; +op /(i64, i64) -> i64; +op %(i64, i64) -> i64; +op **(i64, i64) -> i64; +op >>(i64, i64) -> i64; +op <<(i64, i64) -> i64; + +op +(f64, f64) -> f64; +op -(f64, f64) -> f64; +op *(f64, f64) -> f64; +op /(f64, f64) -> f64; +op %(f64, f64) -> f64; +op **(f64, f64) -> f64; +op ==(f64, f64) -> bool; +op !=(f64, f64) -> bool; +op >(f64, f64) -> bool; +op >=(f64, f64) -> bool; +op <(f64, f64) -> bool; +op <=(f64, f64) -> bool; + +op +(f64, i64) -> f64; +op -(f64, i64) -> f64; +op *(f64, i64) -> f64; +op /(f64, i64) -> f64; +op %(f64, i64) -> f64; +op **(f64, i64) -> f64; +op ==(f64, i64) -> bool; +op !=(f64, i64) -> bool; +op >(f64, i64) -> bool; +op >=(f64, i64) -> bool; +op <(f64, i64) -> bool; +op <=(f64, i64) -> bool; + +op +(i64, f64) -> f64; +op -(i64, f64) -> f64; +op *(i64, f64) -> f64; +op /(i64, f64) -> f64; +op %(i64, f64) -> f64; +op **(i64, f64) -> f64; +op ==(i64, f64) -> bool; +op !=(i64, f64) -> bool; +op >(i64, f64) -> bool; +op >=(i64, f64) -> bool; +op <(i64, f64) -> bool; +op <=(i64, f64) -> 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, i64) -> Decimal; +op -(Decimal, i64) -> Decimal; +op *(Decimal, i64) -> Decimal; +op /(Decimal, i64) -> Decimal; +op %(Decimal, i64) -> Decimal; +op **(Decimal, i64) -> Decimal; +op ==(Decimal, i64) -> bool; +op !=(Decimal, i64) -> bool; +op >(Decimal, i64) -> bool; +op >=(Decimal, i64) -> bool; +op <(Decimal, i64) -> bool; +op <=(Decimal, i64) -> bool; + +op +(i64, Decimal) -> Decimal; +op -(i64, Decimal) -> Decimal; +op *(i64, Decimal) -> Decimal; +op /(i64, Decimal) -> Decimal; +op %(i64, Decimal) -> Decimal; +op **(i64, Decimal) -> Decimal; +op ==(i64, Decimal) -> bool; +op !=(i64, Decimal) -> bool; +op >(i64, Decimal) -> bool; +op >=(i64, Decimal) -> bool; +op <(i64, Decimal) -> bool; +op <=(i64, 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 +=(i64, i64); +op -=(i64, i64); +op *=(i64, i64); +op /=(i64, i64); +op %=(i64, i64); +op **=(i64, i64); +op >>=(i64, i64); +op <<=(i64, i64); +op &=(i64, i64); +op |=(i64, i64); +op ^=(i64, i64); + +op +=(f64, f64); +op -=(f64, f64); +op *=(f64, f64); +op /=(f64, f64); +op %=(f64, f64); +op **=(f64, f64); + +op +=(f64, i64); +op -=(f64, i64); +op *=(f64, i64); +op /=(f64, i64); +op %=(f64, i64); +op **=(f64, i64); + +op +=(Decimal, Decimal); +op -=(Decimal, Decimal); +op *=(Decimal, Decimal); +op /=(Decimal, Decimal); +op %=(Decimal, Decimal); +op **=(Decimal, Decimal); + +op +=(Decimal, i64); +op -=(Decimal, i64); +op *=(Decimal, i64); +op /=(Decimal, i64); +op %=(Decimal, i64); +op **=(Decimal, i64); + +op +=(String, String); +op -=(String, String); +op +=(String, char); +op -=(String, char); +op +=(char, String); +op +=(char, char); + +op +=(arraArray, item: Array); +op +=(arraArray, item: ?); + +op +=(Blob, Blob); +op +=(Blob, value: i64); +op +=(Blob, char); +op +=(Blob, String); diff --git a/examples/definitions/.rhai/definitions/__builtin__.d.rhai b/examples/definitions/.rhai/definitions/__builtin__.d.rhai new file mode 100644 index 00000000..2e08fa44 --- /dev/null +++ b/examples/definitions/.rhai/definitions/__builtin__.d.rhai @@ -0,0 +1,170 @@ +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: i64) -> 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) -> ?; + +fn contains(string: String, find: String) -> bool; +fn contains(range: Range, value: i64) -> bool; +fn contains(range: RangeInclusive, value: i64) -> bool; +fn contains(map: Map, string: String) -> bool; +fn contains(blob: Blob, value: i64) -> bool; +fn contains(string: String, ch: char) -> bool; diff --git a/examples/definitions/.rhai/definitions/__static__.d.rhai b/examples/definitions/.rhai/definitions/__static__.d.rhai index 10d7b8c4..c422f26a 100644 --- a/examples/definitions/.rhai/definitions/__static__.d.rhai +++ b/examples/definitions/.rhai/definitions/__static__.d.rhai @@ -4,6 +4,17 @@ op minus(i64, i64) -> i64; op !(bool) -> bool; +/// Return `true` if two timestamps are not equal. +op !=(Instant, Instant) -> bool; + +op !=(f32, int) -> bool; + +op !=(f32, f32) -> bool; + +op !=(f64, int) -> bool; + +op !=(u16, u16) -> 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, @@ -22,13 +33,7 @@ op !(bool) -> bool; /// ``` op !=(Array, Array) -> bool; -op !=(u16, u16) -> bool; - -op !=(f32, f32) -> bool; - -op !=(int, f32) -> bool; - -op !=(i32, i32) -> bool; +op !=(int, f64) -> bool; /// Return `true` if two object maps are not equal (i.e. at least one property value is not equal). /// @@ -48,189 +53,111 @@ op !=(i32, i32) -> bool; /// ``` op !=(Map, Map) -> bool; -op !=(u64, u64) -> bool; - op !=(u32, u32) -> bool; -op !=(i8, i8) -> bool; - -op !=(f32, int) -> bool; - -op !=(i16, i16) -> bool; - -/// Return `true` if two timestamps are not equal. -op !=(Instant, Instant) -> bool; - op !=(u128, u128) -> bool; -op !=(u8, u8) -> bool; +op !=(i8, i8) -> bool; -op !=(f64, int) -> bool; - -op !=(int, f64) -> bool; +op !=(u64, u64) -> bool; op !=(i128, i128) -> bool; -op %(u8, u8) -> u8; +op !=(u8, u8) -> bool; -op %(i128, i128) -> i128; +op !=(i16, i16) -> bool; -op %(i32, i32) -> i32; +op !=(i32, i32) -> bool; + +op !=(int, f32) -> bool; op %(int, f32) -> f32; -op %(f32, f32) -> f32; - -op %(u32, u32) -> u32; +op %(i128, i128) -> i128; op %(u64, u64) -> u64; -op %(u16, u16) -> u16; +op %(u8, u8) -> u8; op %(i16, i16) -> i16; -op %(u128, u128) -> u128; - -op %(i8, i8) -> i8; +op %(i32, i32) -> i32; op %(f32, int) -> f32; -op &(i128, i128) -> i128; +op %(u16, u16) -> u16; -op &(u8, u8) -> u8; +op %(f32, f32) -> f32; + +op %(u128, u128) -> u128; + +op %(u32, u32) -> u32; + +op %(i8, i8) -> i8; op &(i8, i8) -> i8; op &(u128, u128) -> u128; -op &(i16, i16) -> i16; +op &(u32, u32) -> u32; op &(u16, u16) -> u16; -op &(u32, u32) -> u32; - -op &(u64, u64) -> u64; +op &(i16, i16) -> i16; op &(i32, i32) -> i32; -op *(i8, i8) -> i8; +op &(u64, u64) -> u64; -op *(f32, int) -> f32; +op &(i128, i128) -> i128; -op *(i16, i16) -> i16; - -op *(u128, u128) -> u128; +op &(u8, u8) -> u8; op *(u16, u16) -> u16; op *(f32, f32) -> f32; -op *(int, f32) -> f32; +op *(f32, int) -> f32; -op *(i32, i32) -> i32; +op *(i8, i8) -> i8; -op *(u64, u64) -> u64; +op *(u128, u128) -> u128; op *(u32, u32) -> u32; -op *(i128, i128) -> i128; - op *(u8, u8) -> u8; -op **(f32, int) -> f32; +op *(i128, i128) -> i128; -op **(u32, int) -> u32; +op *(u64, u64) -> u64; -op **(i128, int) -> i128; +op *(i32, i32) -> i32; -op **(f32, f32) -> f32; +op *(i16, i16) -> i16; + +op *(int, f32) -> f32; op **(u8, int) -> u8; -op **(i8, int) -> i8; +op **(i16, int) -> i16; -op **(u64, int) -> u64; +op **(i128, int) -> i128; -op **(u128, int) -> u128; +op **(f32, int) -> f32; + +op **(f32, f32) -> f32; op **(u16, int) -> u16; -op **(i16, int) -> i16; +op **(i8, int) -> i8; op **(i32, int) -> i32; -op +(i128, i128) -> i128; +op **(u32, int) -> u32; -op +(String, ()) -> String; +op **(u128, int) -> u128; -/// Add the specified number of `seconds` to the timestamp and return it as a new timestamp. -op +(Instant, int) -> Instant; - -op +(char, String) -> String; - -op +(i32) -> i32; - -op +(f32) -> f32; - -op +(String, String) -> String; - -op +(u8, u8) -> u8; - -/// Add the specified number of `seconds` to the timestamp and return it as a new timestamp. -op +(Instant, float) -> Instant; - -op +(String, ?) -> String; - -op +(f64) -> f64; - -op +(int) -> int; - -op +(u128, u128) -> u128; - -op +(Blob, String) -> String; - -op +(i16, i16) -> i16; - -op +((), String) -> String; - -op +(i16) -> i16; - -op +(i8) -> i8; - -op +(f32, int) -> f32; - -op +(i8, i8) -> i8; - -op +(?, String) -> String; - -op +(u32, u32) -> u32; - -/// 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 +(u64, u64) -> u64; - -op +(i32, i32) -> i32; - -op +(String, Blob) -> String; - -op +(int, f32) -> f32; - -op +(f32, f32) -> f32; - -op +(u16, u16) -> u16; +op **(u64, int) -> u64; op +(i128) -> i128; @@ -248,16 +175,84 @@ op +(i128) -> i128; /// ``` op +(Array, Array) -> Array; +op +(i8) -> i8; + +op +(String, ()) -> String; + +op +(u16, u16) -> u16; + +op +(f32, f32) -> f32; + +op +(f32, int) -> f32; + +op +(i8, i8) -> i8; + +op +(int) -> i64; + +op +(u128, u128) -> u128; + +op +(u32, u32) -> u32; + +/// Add the specified number of `seconds` to the timestamp and return it as a new timestamp. +op +(Instant, int) -> Instant; + +op +(i32) -> i32; + +/// 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, char) -> String; +op +(u8, u8) -> u8; + +/// Add the specified number of `seconds` to the timestamp and return it as a new timestamp. +op +(Instant, float) -> Instant; + +op +(String, ?) -> String; + +op +(Blob, String) -> String; + +op +(i128, i128) -> i128; + +op +(u64, u64) -> u64; + +op +(f32) -> f32; + +op +(String, Blob) -> String; + +op +(i32, i32) -> i32; + +op +((), String) -> String; + +op +(f64) -> f64; + +op +(i16) -> i16; + +op +(?, String) -> String; + +op +(i16, i16) -> i16; + +op +(int, f32) -> f32; + +op +(String, String) -> String; + +op +(char, String) -> String; + /// Add the specified number of `seconds` to the timestamp. op +=(Instant, int) -> (); -/// Add the specified number of `seconds` to the timestamp. -op +=(Instant, float) -> (); - -op +=(String, ?) -> (); - /// Add all property values of another object map into the object map. /// Existing property values of the same names are replaced. /// @@ -273,89 +268,93 @@ op +=(String, ?) -> (); /// ``` op +=(Map, Map) -> (); +/// Add the specified number of `seconds` to the timestamp. +op +=(Instant, float) -> (); + +op +=(String, ?) -> (); + op +=(String, Blob) -> (); -op -(i128, i128) -> i128; +op -(f32, f32) -> f32; -op -(f32) -> f32; +op -(u16, u16) -> u16; + +op -(f32, int) -> f32; + +op -(i8, i8) -> i8; /// Subtract the specified number of `seconds` from the timestamp and return it as a new timestamp. op -(Instant, int) -> Instant; +op -(u32, u32) -> u32; + +op -(u128, u128) -> u128; + +op -(i128) -> i128; + op -(i32) -> i32; +op -(int) -> int; + +op -(i8) -> i8; + +/// Return the number of seconds between two timestamps. +op -(Instant, Instant) -> RhaiResult; + +op -(int, f32) -> f32; + +op -(i16) -> i16; + +op -(f64) -> f64; + +op -(f32) -> f32; + /// Subtract the specified number of `seconds` from the timestamp and return it as a new timestamp. op -(Instant, float) -> Instant; op -(u8, u8) -> u8; -op -(f64) -> f64; +op -(u64, u64) -> u64; -op -(int) -> int; - -op -(i16, i16) -> i16; - -op -(i16) -> i16; - -/// Return the number of seconds between two timestamps. -op -(Instant, Instant) -> RhaiResult; - -op -(u128, u128) -> u128; - -op -(i8, i8) -> i8; - -op -(i8) -> i8; - -op -(f32, int) -> f32; - -op -(f32, f32) -> f32; +op -(i128, i128) -> i128; op -(i32, i32) -> i32; -op -(int, f32) -> f32; - -op -(u64, u64) -> u64; - -op -(u32, u32) -> u32; - -op -(i128) -> i128; - -op -(u16, u16) -> u16; - -/// Subtract the specified number of `seconds` from the timestamp. -op -=(Instant, float) -> (); +op -(i16, i16) -> i16; /// Subtract the specified number of `seconds` from the timestamp. op -=(Instant, int) -> (); -op /(u8, u8) -> u8; - -op /(i128, i128) -> i128; - -op /(u32, u32) -> u32; - -op /(u64, u64) -> u64; - -op /(int, f32) -> f32; - -op /(i32, i32) -> i32; - -op /(f32, f32) -> f32; - -op /(u16, u16) -> u16; - -op /(u128, u128) -> u128; - -op /(i16, i16) -> i16; +/// Subtract the specified number of `seconds` from the timestamp. +op -=(Instant, float) -> (); op /(f32, int) -> f32; +op /(u16, u16) -> u16; + +op /(f32, f32) -> f32; + +op /(u32, u32) -> u32; + +op /(u128, u128) -> u128; + op /(i8, i8) -> i8; -op <(i16, i16) -> bool; +op /(int, f32) -> f32; -/// Return `true` if the first timestamp is earlier than the second. -op <(Instant, Instant) -> bool; +op /(i128, i128) -> i128; + +op /(u64, u64) -> u64; + +op /(u8, u8) -> u8; + +op /(i16, i16) -> i16; + +op /(i32, i32) -> i32; + +op <(int, f64) -> bool; + +op <(u32, u32) -> bool; op <(u128, u128) -> bool; @@ -365,89 +364,118 @@ op <(f32, int) -> bool; op <(f32, f32) -> bool; +op <(f64, int) -> bool; + +op <(u16, u16) -> bool; + +/// Return `true` if the first timestamp is earlier than the second. +op <(Instant, Instant) -> bool; + op <(int, f32) -> bool; +op <(i16, i16) -> bool; + op <(i32, i32) -> bool; op <(u64, u64) -> bool; -op <(u32, u32) -> bool; - -op <(u16, u16) -> bool; - -op <(int, f64) -> bool; - op <(i128, i128) -> bool; -op <(f64, int) -> bool; - op <(u8, u8) -> bool; -op <<(u32, int) -> u32; - -op <<(i128, int) -> i128; - -op <<(u8, int) -> u8; +op <<(u16, int) -> u16; op <<(i8, int) -> i8; -op <<(u64, int) -> u64; - -op <<(u128, int) -> u128; - -op <<(u16, int) -> u16; +op <<(u8, int) -> u8; op <<(i16, int) -> i16; +op <<(i128, int) -> i128; + +op <<(u128, int) -> u128; + +op <<(u64, int) -> u64; + op <<(i32, int) -> i32; -op <=(int, f64) -> bool; +op <<(u32, int) -> u32; + +op <=(int, f32) -> bool; op <=(i128, i128) -> bool; -op <=(f64, int) -> bool; +op <=(u64, u64) -> bool; op <=(u8, u8) -> bool; op <=(i16, i16) -> bool; -/// Return `true` if the first timestamp is earlier than or equals to the second. -op <=(Instant, Instant) -> bool; - -op <=(u128, u128) -> bool; - -op <=(i8, i8) -> bool; +op <=(i32, i32) -> bool; op <=(f32, int) -> bool; +op <=(u16, u16) -> bool; + +op <=(f64, int) -> bool; + op <=(f32, f32) -> bool; -op <=(i32, i32) -> bool; +op <=(int, f64) -> bool; -op <=(int, f32) -> bool; +op <=(i8, i8) -> bool; -op <=(u64, u64) -> bool; +op <=(u128, u128) -> bool; op <=(u32, u32) -> bool; -op <=(u16, u16) -> bool; +/// Return `true` if the first timestamp is earlier than or equals to the second. +op <=(Instant, Instant) -> bool; + +op ==(u8, u8) -> bool; + +op ==(u64, u64) -> bool; + +op ==(i128, i128) -> bool; + +op ==(i32, i32) -> bool; + +op ==(i16, i16) -> bool; + +op ==(int, f32) -> bool; /// Return `true` if two timestamps are equal. op ==(Instant, Instant) -> bool; -op ==(i16, i16) -> 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; -op ==(u128, u128) -> bool; +op ==(f32, f32) -> bool; -op ==(i8, i8) -> bool; +op ==(u16, u16) -> bool; + +op ==(f64, int) -> bool; op ==(f32, int) -> bool; -op ==(int, f32) -> bool; +op ==(i8, i8) -> bool; -op ==(i32, i32) -> bool; - -op ==(f32, f32) -> bool; +op ==(u128, u128) -> bool; op ==(u32, u32) -> bool; @@ -469,166 +497,158 @@ op ==(u32, u32) -> bool; /// ``` op ==(Map, Map) -> bool; -op ==(u64, u64) -> 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; - -op ==(u16, u16) -> bool; - -op ==(i128, i128) -> bool; - op ==(int, f64) -> bool; -op ==(f64, int) -> bool; +/// Return `true` if the first timestamp is later than the second. +op >(Instant, Instant) -> bool; -op ==(u8, u8) -> bool; +op >(f32, int) -> bool; + +op >(f32, f32) -> bool; + +op >(u16, u16) -> bool; op >(f64, int) -> bool; -op >(i128, i128) -> bool; - op >(int, f64) -> bool; -op >(u8, u8) -> bool; - -op >(f32, int) -> bool; - op >(i8, i8) -> bool; op >(u128, u128) -> bool; -/// Return `true` if the first timestamp is later than the second. -op >(Instant, Instant) -> bool; - -op >(i16, i16) -> bool; - -op >(u16, u16) -> bool; - op >(u32, u32) -> bool; op >(u64, u64) -> bool; +op >(i128, i128) -> bool; + +op >(u8, u8) -> bool; + +op >(i16, i16) -> bool; + op >(i32, i32) -> bool; op >(int, f32) -> bool; -op >(f32, f32) -> bool; - -op >=(u16, u16) -> bool; - -op >=(u32, u32) -> bool; - -op >=(u64, u64) -> bool; - op >=(int, f32) -> bool; +op >=(i16, i16) -> bool; + op >=(i32, i32) -> bool; -op >=(f32, f32) -> bool; +op >=(u64, u64) -> bool; -op >=(f32, int) -> bool; +op >=(i128, i128) -> bool; + +op >=(u8, u8) -> bool; + +op >=(int, f64) -> bool; op >=(i8, i8) -> bool; op >=(u128, u128) -> bool; -/// Return `true` if the first timestamp is later than or equals to the second. -op >=(Instant, Instant) -> bool; +op >=(u32, u32) -> bool; -op >=(i16, i16) -> bool; +op >=(f32, int) -> bool; -op >=(u8, u8) -> bool; +op >=(f32, f32) -> bool; + +op >=(u16, u16) -> bool; op >=(f64, int) -> bool; -op >=(i128, i128) -> bool; +/// Return `true` if the first timestamp is later than or equals to the second. +op >=(Instant, Instant) -> bool; -op >=(int, f64) -> bool; +op >>(u8, int) -> u8; + +op >>(i16, int) -> i16; + +op >>(i128, int) -> i128; + +op >>(u16, int) -> u16; + +op >>(i8, int) -> i8; + +op >>(i32, int) -> i32; + +op >>(u32, int) -> u32; op >>(u128, int) -> u128; op >>(u64, int) -> u64; -op >>(i8, int) -> i8; - -op >>(u8, int) -> u8; - -op >>(i32, int) -> i32; - -op >>(i16, int) -> i16; - -op >>(u16, int) -> u16; - -op >>(i128, int) -> i128; - -op >>(u32, int) -> u32; - /// Return the natural number _e_. -fn E() -> float; +fn E() -> f64; /// Return the number π. -fn PI() -> float; - -op ^(u8, u8) -> u8; - -op ^(i128, i128) -> i128; - -op ^(u16, u16) -> u16; - -op ^(u64, u64) -> u64; - -op ^(u32, u32) -> u32; - -op ^(i32, i32) -> i32; +fn PI() -> f64; op ^(i8, i8) -> i8; +op ^(u32, u32) -> u32; + op ^(u128, u128) -> u128; +op ^(u16, u16) -> u16; + +op ^(i32, i32) -> i32; + op ^(i16, i16) -> i16; -/// Return the absolute value of the number. -fn abs(x: int) -> int; +op ^(u8, u8) -> u8; -/// Return the absolute value of the floating-point number. -fn abs(x: f64) -> f64; +op ^(u64, u64) -> u64; + +op ^(i128, i128) -> i128; /// Return the absolute value of the floating-point number. fn abs(x: f32) -> f32; /// Return the absolute value of the number. -fn abs(x: i32) -> i32; +fn abs(x: i16) -> i16; + +/// Return the absolute value of the floating-point number. +fn abs(x: f64) -> f64; /// 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: i8) -> i8; +/// Return the absolute value of the number. +fn abs(x: i32) -> i32; + +/// Return the absolute value of the number. +fn abs(x: int) -> int; + /// Return the arc-cosine of the floating-point number, in radians. -fn acos(x: float) -> float; +fn acos(x: float) -> f64; /// Return the arc-hyperbolic-cosine of the floating-point number, in radians. -fn acosh(x: float) -> float; +fn acosh(x: float) -> f64; + +/// 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; /// Return `true` if all elements in the array return `true` when applied a function named by `filter`. /// @@ -652,25 +672,18 @@ fn acosh(x: float) -> float; /// ``` 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 +/// Add a character (as UTF-8 encoded byte-stream) to the end of the BLOB /// /// # Example /// /// ```rhai -/// let x = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 5]; +/// let b = blob(5, 0x42); /// -/// print(x.all(|v| v > 3)); // prints false +/// b.append('!'); /// -/// print(x.all(|v| v > 1)); // prints true -/// -/// print(x.all(|v, i| i > v)); // prints false +/// print(b); // prints "[424242424221]" /// ``` -fn all(array: Array, filter: FnPtr) -> bool; +fn append(blob: Blob, character: char) -> (); /// Add another BLOB to the end of the BLOB. /// @@ -686,34 +699,6 @@ fn all(array: Array, filter: FnPtr) -> bool; /// ``` fn append(blob1: Blob, blob2: Blob) -> (); -/// 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 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) -> (); - -fn append(string: String, utf8: Blob) -> (); - /// Add all the elements of another array to the end of the array. /// /// # Example @@ -743,6 +728,21 @@ fn append(array: Array, new_array: Array) -> (); /// ``` fn append(blob: Blob, value: int) -> (); +fn append(string: String, utf8: Blob) -> (); + +/// 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) -> (); + fn append(string: String, item: ?) -> (); /// Convert the BLOB into a string. @@ -761,34 +761,19 @@ fn append(string: String, item: ?) -> (); fn as_string(blob: Blob) -> String; /// Return the arc-sine of the floating-point number, in radians. -fn asin(x: float) -> float; +fn asin(x: float) -> f64; /// Return the arc-hyperbolic-sine of the floating-point number, in radians. -fn asinh(x: float) -> float; +fn asinh(x: float) -> f64; /// Return the arc-tangent of the floating-point numbers `x` and `y`, in radians. -fn atan(x: float, y: float) -> float; +fn atan(x: float, y: float) -> f64; /// Return the arc-tangent of the floating-point number, in radians. -fn atan(x: float) -> float; +fn atan(x: float) -> f64; /// Return the arc-hyperbolic-tangent of the floating-point number, in radians. -fn atanh(x: float) -> float; - -/// 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; +fn atanh(x: float) -> f64; /// Return an iterator over an inclusive range of bits in the number. /// @@ -846,8 +831,20 @@ fn bits(value: int, range: Range) -> Iterator; /// ``` fn bits(value: int, from: int, len: int) -> Iterator; -/// Return a new, empty BLOB. -fn blob() -> Blob; +/// 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 a new BLOB of the specified length, filled with copies of the initial `value`. /// @@ -877,6 +874,9 @@ fn blob(len: int, value: int) -> Blob; /// ``` fn blob(len: int) -> Blob; +/// Return a new, empty BLOB. +fn blob() -> Blob; + /// Return the length of the string, in number of bytes used to store it in UTF-8 encoding. /// /// # Example @@ -886,10 +886,25 @@ fn blob(len: int) -> Blob; /// /// print(text.bytes); // prints 51 /// ``` -fn bytes(string: String) -> int; +fn bytes(string: String) -> i64; /// Return the smallest whole number larger than or equals to the floating-point number. -fn ceiling(x: float) -> float; +fn ceiling(x: float) -> f64; + +/// 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 the characters in the string. /// @@ -913,32 +928,6 @@ fn chars(string: String) -> Iterator; /// ``` 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 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 a portion of characters in the string. /// /// * If `start` < 0, position counts from the end of the string (`-1` is the last character). @@ -956,6 +945,37 @@ fn chars(string: String, from: int) -> Iterator; /// ``` fn chars(string: String, start: int, len: int) -> 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; + +/// 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. @@ -978,32 +998,12 @@ fn chars(string: String, start: int, len: int) -> Iterator; /// ``` fn chop(blob: Blob, len: int) -> (); -/// 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) -> (); +/// Clear the string, making it empty. +fn clear(string: String) -> (); /// Clear the object map. fn clear(map: Map) -> (); -/// Clear the string, making it empty. -fn clear(string: String) -> (); - /// Clear the BLOB. fn clear(blob: Blob) -> (); @@ -1030,31 +1030,10 @@ fn clear(array: Array) -> (); fn contains(array: Array, value: ?) -> bool; /// Return the cosine of the floating-point number in radians. -fn cos(x: float) -> float; +fn cos(x: float) -> f64; /// Return the hyperbolic cosine of the floating-point number in radians. -fn cosh(x: float) -> float; - -/// 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) -> (); +fn cosh(x: float) -> f64; /// Remove all characters from the string except those within a range. /// @@ -1079,6 +1058,27 @@ fn crop(string: String, start: int) -> (); /// ``` fn crop(string: String, start: int, len: int) -> (); +/// 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 an exclusive `range`. /// /// # Example @@ -1090,7 +1090,7 @@ fn crop(string: String, start: int, len: int) -> (); /// /// print(text); // prints "llo, w" /// ``` -fn crop(string: String, range: ExclusiveRange) -> (); +fn crop(string: String, range: Range) -> (); /// Remove all characters from the string except those within an inclusive `range`. /// @@ -1103,28 +1103,19 @@ fn crop(string: String, range: ExclusiveRange) -> (); /// /// print(text); // prints "llo, wo" /// ``` -fn crop(string: String, range: InclusiveRange) -> (); - -/// Convert the boolean value into a string in debug format. -fn debug(value: bool) -> String; +fn crop(string: String, range: RangeInclusive) -> (); /// Convert the array into a string. fn debug(array: Array) -> String; -/// Convert the string into debug format. -fn debug(character: char) -> String; +/// Return the empty string. +fn debug() -> String; /// Convert the unit into a string in debug format. fn debug(unit: ()) -> String; -/// Return the empty string. -fn debug() -> String; - -/// Convert the value of the `item` into a string in debug format. -fn debug(item: ?) -> String; - -/// Convert the function pointer into a string in debug format. -fn debug(f: FnPtr) -> String; +/// Convert the value of `number` into a string. +fn debug(number: f64) -> String; /// Convert the object map into a string. fn debug(map: Map) -> String; @@ -1132,11 +1123,61 @@ fn debug(map: Map) -> String; /// Convert the value of `number` into a string. fn debug(number: f32) -> String; +/// Convert the string into debug format. +fn debug(character: char) -> String; + +/// Convert the function pointer into a string in debug format. +fn debug(f: FnPtr) -> String; + /// Convert the string into debug format. fn debug(string: String) -> String; -/// Convert the value of `number` into a string. -fn debug(number: f64) -> String; +/// Convert the boolean value into a string in debug format. +fn debug(value: bool) -> String; + +/// Convert the value of the `item` into a string in debug format. +fn debug(item: ?) -> 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 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`. @@ -1165,46 +1206,32 @@ fn debug(number: f64) -> String; /// ``` fn dedup(array: Array, comparer: String) -> (); -/// Remove duplicated _consecutive_ elements from the array. +/// Remove all elements within a portion of the array and return them as a new array. /// -/// The operator `==` is used to compare elements and must be defined, -/// otherwise `false` is assumed. +/// * 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, 2, 2, 3, 4, 3, 3, 2, 1]; +/// let x = [1, 2, 3, 4, 5]; /// -/// x.dedup(); +/// let y = x.drain(1, 2); /// -/// print(x); // prints "[1, 2, 3, 4, 3, 2, 1]" +/// 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 dedup(array: Array) -> (); - -/// 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) -> (); +fn drain(array: Array, start: int, len: int) -> Array; /// Remove all bytes in the BLOB within an exclusive `range` and return them as a new BLOB. /// @@ -1227,7 +1254,49 @@ fn dedup(array: Array, comparer: FnPtr) -> (); /// /// print(b3); // prints "[05]" /// ``` -fn drain(blob: Blob, range: ExclusiveRange) -> Blob; +fn drain(blob: Blob, range: Range) -> Blob; + +/// 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 within a portion of the BLOB and return them as a new BLOB. /// @@ -1291,77 +1360,6 @@ fn drain(blob: Blob, start: int, len: int) -> Blob; /// ``` fn drain(array: Array, filter: String) -> 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: InclusiveRange) -> Array; - -/// 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: InclusiveRange) -> 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 elements in the array that returns `true` when applied the `filter` function and /// return them as a new array. /// @@ -1389,26 +1387,28 @@ fn drain(array: Array, start: int, len: int) -> Array; /// ``` fn drain(array: Array, filter: FnPtr) -> Array; -/// Remove all elements in the array within an exclusive `range` and return them as a new array. +/// Remove all bytes in the BLOB within an inclusive `range` and return them as a new BLOB. /// /// # Example /// /// ```rhai -/// let x = [1, 2, 3, 4, 5]; +/// let b1 = blob(); /// -/// let y = x.drain(1..3); +/// b1 += 1; b1 += 2; b1 += 3; b1 += 4; b1 += 5; /// -/// print(x); // prints "[1, 4, 5]" +/// let b2 = b1.drain(1..=2); /// -/// print(y); // prints "[2, 3]" +/// print(b1); // prints "[010405]" /// -/// let z = x.drain(2..3); +/// print(b2); // prints "[0203]" /// -/// print(x); // prints "[1, 4]" +/// let b3 = b1.drain(2..=2); /// -/// print(z); // prints "[5]" +/// print(b1); // prints "[0104]" +/// +/// print(b3); // prints "[05]" /// ``` -fn drain(array: Array, range: ExclusiveRange) -> Array; +fn drain(blob: Blob, range: RangeInclusive) -> Blob; /// Return the number of seconds between the current system time and the timestamp. /// @@ -1423,11 +1423,11 @@ fn drain(array: Array, range: ExclusiveRange) -> Array; /// ``` 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; +fn end(range: InclusiveRange) -> i64; + +/// Return the end of the exclusive range. +fn end(range: ExclusiveRange) -> i64; /// Return `true` if the string ends with a specified string. /// @@ -1443,126 +1443,7 @@ fn end(range: InclusiveRange) -> int; fn ends_with(string: String, match_string: String) -> bool; /// Return the exponential of the floating-point number. -fn exp(x: float) -> float; - -/// 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: InclusiveRange) -> Blob; - -/// 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: InclusiveRange) -> Array; - -/// 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 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 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 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: ExclusiveRange) -> Blob; - -/// 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: ExclusiveRange) -> Array; +fn exp(x: float) -> f64; /// Copy a portion of the BLOB and return it as a new BLOB. /// @@ -1587,6 +1468,125 @@ fn extract(array: Array, range: ExclusiveRange) -> Array; /// ``` fn extract(blob: Blob, start: int, len: int) -> 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 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 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 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 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; + /// 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. /// @@ -1602,29 +1602,6 @@ fn extract(blob: Blob, start: int, len: int) -> Blob; /// ``` 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. /// @@ -1652,30 +1629,34 @@ fn filter(array: Array, filter: FnPtr) -> Array; /// ``` 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 the character at the `index` position in the string. +/// 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. /// -/// * 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. +/// # Function Parameters +/// +/// * `element`: copy of array element +/// * `index` _(optional)_: current index in the array /// /// # Example /// /// ```rhai -/// let text = "hello, world!"; +/// let x = [1, 2, 3, 4, 5]; /// -/// print(text.get(0)); // prints 'h' +/// let y = x.filter(|v| v >= 3); /// -/// print(text.get(-1)); // prints '!' +/// print(y); // prints "[3, 4, 5]" /// -/// print(text.get(99)); // prints empty (for '()')' +/// let y = x.filter(|v, i| v * i >= 10); +/// +/// print(y); // prints "[12, 20]" /// ``` -fn get(string: String, index: int) -> ?; +fn filter(array: Array, filter: FnPtr) -> Array; + +/// Return the largest whole number less than or equals to the floating-point number. +fn floor(x: float) -> f64; + +/// Return the fractional part of the floating-point number. +fn fraction(x: float) -> f64; /// Get the byte value at the `index` position in the BLOB. /// @@ -1696,7 +1677,26 @@ fn get(string: String, index: int) -> ?; /// /// print(b.get(99)); // prints 0 /// ``` -fn get(blob: Blob, index: int) -> int; +fn get(blob: Blob, index: int) -> i64; + +/// 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) -> ?; /// Get the value of the `property` in the object map and return a copy. /// @@ -1754,10 +1754,10 @@ fn get bits(value: int) -> Iterator; /// /// print(text.bytes); // prints 51 /// ``` -fn get bytes(string: String) -> int; +fn get bytes(string: String) -> i64; /// Return the smallest whole number larger than or equals to the floating-point number. -fn get ceiling(x: float) -> float; +fn get ceiling(x: float) -> f64; /// Return an iterator over all the characters in the string. /// @@ -1784,19 +1784,19 @@ fn get chars(string: String) -> Iterator; fn get elapsed(timestamp: Instant) -> RhaiResult; /// Return the end of the inclusive range. -fn get end(range: InclusiveRange) -> int; +fn get end(range: InclusiveRange) -> i64; /// Return the end of the exclusive range. -fn get end(range: ExclusiveRange) -> int; +fn get end(range: ExclusiveRange) -> i64; /// Return the largest whole number less than or equals to the floating-point number. -fn get floor(x: float) -> float; +fn get floor(x: float) -> f64; /// Return the fractional part of the floating-point number. -fn get fraction(x: float) -> float; +fn get fraction(x: float) -> f64; /// Return the integral part of the floating-point number. -fn get int(x: float) -> float; +fn get int(x: float) -> f64; /// Return `true` if the function is an anonymous function. /// @@ -1809,36 +1809,36 @@ fn get int(x: float) -> float; /// ``` fn get is_anonymous(fn_ptr: FnPtr) -> 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: u32) -> 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: u16) -> 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: i16) -> 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: u8) -> 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: i32) -> 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 number is even. +fn get is_even(x: i8) -> 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: i128) -> bool; + /// Return `true` if the range is exclusive. fn get is_exclusive(range: ExclusiveRange) -> bool; @@ -1849,10 +1849,10 @@ fn get is_exclusive(range: InclusiveRange) -> bool; fn get is_finite(x: float) -> bool; /// Return `true` if the range is inclusive. -fn get is_inclusive(range: ExclusiveRange) -> bool; +fn get is_inclusive(range: InclusiveRange) -> bool; /// Return `true` if the range is inclusive. -fn get is_inclusive(range: InclusiveRange) -> bool; +fn get is_inclusive(range: ExclusiveRange) -> bool; /// Return `true` if the floating-point number is infinite. fn get is_infinite(x: float) -> bool; @@ -1860,26 +1860,14 @@ 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: u32) -> 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: u16) -> 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: u8) -> bool; +fn get is_odd(x: i16) -> bool; /// Return true if the number is odd. fn get is_odd(x: int) -> bool; @@ -1890,14 +1878,32 @@ fn get is_odd(x: u64) -> 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: u8) -> 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: u32) -> bool; + +/// Return true if the number is odd. +fn get is_odd(x: i128) -> bool; + +/// Return true if the floating-point number is zero. +fn get is_zero(x: f32) -> bool; + /// Return true if the number is zero. -fn get is_zero(x: i8) -> bool; +fn get is_zero(x: i16) -> bool; + +/// Return true if the floating-point number is zero. +fn get is_zero(x: f64) -> 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: i16) -> bool; +fn get is_zero(x: u128) -> bool; /// Return true if the number is zero. fn get is_zero(x: i128) -> bool; @@ -1906,36 +1912,19 @@ fn get is_zero(x: i128) -> bool; fn get is_zero(x: u32) -> bool; /// Return true if the number is zero. -fn get is_zero(x: i32) -> bool; - -/// Return true if the floating-point number is zero. -fn get is_zero(x: f32) -> 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: int) -> bool; - -/// Return true if the floating-point number is zero. -fn get is_zero(x: f64) -> bool; +fn get is_zero(x: i8) -> bool; /// Return true if the number is zero. fn get is_zero(x: u8) -> bool; /// Return true if the number is zero. -fn get is_zero(x: u128) -> bool; +fn get is_zero(x: u64) -> bool; -/// 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 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: int) -> bool; /// Return the length of the BLOB. /// @@ -1948,10 +1937,21 @@ fn get len(string: String) -> int; /// /// print(b.len()); // prints 10 /// ``` -fn get len(blob: Blob) -> int; +fn get len(blob: Blob) -> i64; + +/// Return the length of the string, in number of characters. +/// +/// # Example +/// +/// ```rhai +/// let text = "朝には紅顔ありて夕べには白骨となる"; +/// +/// print(text.len); // prints 17 +/// ``` +fn get len(string: String) -> i64; /// Number of elements in the array. -fn get len(array: Array) -> int; +fn get len(array: Array) -> i64; /// Return the name of the function. /// @@ -1968,13 +1968,13 @@ 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 inclusive range. -fn get start(range: InclusiveRange) -> int; +fn get round(x: float) -> f64; /// Return the start of the exclusive range. -fn get start(range: ExclusiveRange) -> int; +fn get start(range: ExclusiveRange) -> i64; + +/// Return the start of the inclusive range. +fn get start(range: InclusiveRange) -> i64; /// Return the _tag_ of a `Dynamic` value. /// @@ -1987,7 +1987,7 @@ fn get start(range: ExclusiveRange) -> int; /// /// print(x.tag); // prints 42 /// ``` -fn get tag(value: ?) -> int; +fn get tag(value: ?) -> i64; /// Return `true` if the specified `bit` in the number is set. /// @@ -2006,6 +2006,17 @@ fn get tag(value: ?) -> int; /// ``` 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 a portion of bits in the number as a new number. /// /// * If `start` < 0, position counts from the MSB (Most Significant Bit). @@ -2030,82 +2041,37 @@ fn get_bits(value: int, start: int, bits: int) -> int; /// /// print(x.get_bits(5..=9)); // print 18 /// ``` -fn get_bits(value: int, range: InclusiveRange) -> int; - -/// 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: ExclusiveRange) -> int; +fn get_bits(value: int, range: RangeInclusive) -> int; fn get_fn_metadata_list(name: String) -> Array; -fn get_fn_metadata_list(name: String, params: int) -> Array; - fn get_fn_metadata_list() -> 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; +fn hypot(x: float, y: float) -> f64; -/// Find the first element in the array that equals a particular `value` and return its index. -/// If no element equals `value`, `-1` is returned. +/// 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. /// -/// The operator `==` is used to compare elements with `value` and must be defined, -/// otherwise `false` is assumed. +/// * 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 x = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 5]; +/// let text = "hello, world! hello, foobar!"; /// -/// print(x.index_of(4)); // prints 3 (first index) +/// print(text.index_of("ll", 5)); // prints 16 (first index after 5) /// -/// print(x.index_of(9)); // prints -1 +/// print(text.index_of("ll", -15)); // prints 16 /// -/// print(x.index_of("foo")); // prints -1: strings do not equal numbers +/// print(text.index_of("xx", 0)); // prints -1 /// ``` -fn index_of(array: Array, value: ?) -> 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 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; +fn index_of(string: String, find_string: String, start: int) -> i64; /// 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`. @@ -2133,27 +2099,6 @@ fn index_of(string: String, character: char) -> int; /// ``` fn index_of(array: Array, filter: String) -> 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 `character` in the string and return the first index where it is found. /// If the `character` is not found, `-1` is returned. /// @@ -2166,7 +2111,29 @@ fn index_of(string: String, character: char, start: int) -> int; /// /// print(text.index_of("xx:)); // prints -1 /// ``` -fn index_of(string: String, find_string: String) -> int; +fn index_of(string: String, find_string: String) -> i64; + +/// 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; /// 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 @@ -2200,56 +2167,6 @@ fn index_of(string: String, find_string: String) -> int; /// ``` fn index_of(array: Array, filter: FnPtr, 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; - -/// 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; - /// 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. @@ -2290,6 +2207,89 @@ fn index_of(array: Array, value: ?, start: int) -> int; /// ``` fn index_of(array: Array, filter: String, start: int) -> 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, 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) -> i64; + +/// 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 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) -> i64; + /// 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). @@ -2331,7 +2331,7 @@ fn insert(array: Array, index: int, item: ?) -> (); fn insert(blob: Blob, index: int, value: int) -> (); /// Return the integral part of the floating-point number. -fn int(x: float) -> float; +fn int(x: float) -> f64; /// Return `true` if the function is an anonymous function. /// @@ -2345,28 +2345,19 @@ fn int(x: float) -> float; fn is_anonymous(fn_ptr: FnPtr) -> 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: u32) -> bool; +fn is_even(x: i16) -> 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: i8) -> 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: int) -> 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: u8) -> bool; +fn is_even(x: i128) -> 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: u64) -> bool; @@ -2374,12 +2365,21 @@ fn is_even(x: u64) -> bool; /// Return true if the number is even. fn is_even(x: i32) -> bool; -/// Return `true` if the range is exclusive. -fn is_exclusive(range: InclusiveRange) -> bool; +/// Return true if the number is even. +fn is_even(x: u8) -> 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: u32) -> 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; @@ -2398,9 +2398,6 @@ fn is_nan(x: float) -> bool; /// Return true if the number is odd. fn is_odd(x: u8) -> 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: int) -> bool; @@ -2413,32 +2410,26 @@ fn is_odd(x: u64) -> 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: i8) -> 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: i8) -> bool; +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 zero. -fn is_zero(x: u8) -> bool; +/// Return true if the number is odd. +fn is_odd(x: i16) -> bool; /// Return true if the number is zero. -fn is_zero(x: u128) -> bool; +fn is_zero(x: i8) -> 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: f64) -> bool; - -/// Return true if the floating-point number is zero. -fn is_zero(x: f32) -> bool; +fn is_zero(x: u32) -> bool; /// Return true if the number is zero. fn is_zero(x: i32) -> bool; @@ -2447,19 +2438,28 @@ fn is_zero(x: i32) -> bool; fn is_zero(x: u64) -> bool; /// Return true if the number is zero. -fn is_zero(x: u32) -> bool; +fn is_zero(x: int) -> bool; + +/// Return true if the number is zero. +fn is_zero(x: u8) -> 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: u16) -> bool; + +/// Return true if the number is zero. +fn is_zero(x: u128) -> bool; + +/// Return true if the floating-point number is zero. +fn is_zero(x: f32) -> 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: i8) -> bool; - -/// Return true if the number is zero. -fn is_zero(x: u16) -> bool; +/// Return true if the floating-point number is zero. +fn is_zero(x: f64) -> bool; /// Return an array with all the property names in the object map. /// @@ -2473,7 +2473,7 @@ fn is_zero(x: u16) -> bool; fn keys(map: Map) -> Array; /// Return the number of properties in the object map. -fn len(map: Map) -> int; +fn len(map: Map) -> i64; /// Return the length of the string, in number of characters. /// @@ -2484,7 +2484,7 @@ fn len(map: Map) -> int; /// /// print(text.len); // prints 17 /// ``` -fn len(string: String) -> int; +fn len(string: String) -> i64; /// Return the length of the BLOB. /// @@ -2497,32 +2497,19 @@ fn len(string: String) -> int; /// /// print(b.len()); // prints 10 /// ``` -fn len(blob: Blob) -> int; +fn len(blob: Blob) -> i64; /// Number of elements in the array. -fn len(array: Array) -> int; +fn len(array: Array) -> i64; /// Return the natural log of the floating-point number. -fn ln(x: float) -> float; - -/// Return the log of the floating-point number with `base`. -fn log(x: float, base: float) -> float; +fn ln(x: float) -> f64; /// Return the log of the floating-point number with base 10. -fn log(x: float) -> float; +fn log(x: float) -> f64; -/// 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) -> (); +/// Return the log of the floating-point number with `base`. +fn log(x: float, base: float) -> f64; /// Convert the character to lower-case. /// @@ -2537,18 +2524,18 @@ fn make_lower(string: String) -> (); /// ``` fn make_lower(character: char) -> (); -/// Convert the character to upper-case. +/// Convert the string to all lower-case. /// /// # Example /// /// ```rhai -/// let ch = 'a'; +/// let text = "HELLO, WORLD!" /// -/// ch.make_upper(); +/// text.make_lower(); /// -/// print(ch); // prints 'A' +/// print(text); // prints "hello, world!"; /// ``` -fn make_upper(character: char) -> (); +fn make_lower(string: String) -> (); /// Convert the string to all upper-case. /// @@ -2563,6 +2550,19 @@ fn make_upper(character: char) -> (); /// ``` fn make_upper(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) -> (); + /// 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. /// @@ -2643,6 +2643,25 @@ fn mixin(map: Map, map2: Map) -> (); /// ``` 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 string to at least the specified number of characters with the specified string. /// /// If `len` ≤ length of string, no padding is done. @@ -2683,25 +2702,6 @@ fn pad(string: String, len: int, padding: String) -> (); /// ``` fn pad(blob: Blob, len: int, value: int) -> (); -/// 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 string to at least the specified number of characters with the specified `character`. /// /// If `len` ≤ length of string, no padding is done. @@ -2721,19 +2721,12 @@ fn pad(array: Array, len: int, item: ?) -> (); /// ``` fn pad(string: String, len: int, character: char) -> (); -/// 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: InclusiveRange) -> float; - /// 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: ExclusiveRange) -> float; +fn parse_be_float(blob: Blob, range: Range) -> f64; /// Parse the bytes beginning at the `start` position in the BLOB as a `FLOAT` /// in big-endian byte order. @@ -2746,7 +2739,31 @@ fn parse_be_float(blob: Blob, range: ExclusiveRange) -> float; /// /// * 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; +fn parse_be_float(blob: Blob, start: int, len: int) -> f64; + +/// 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) -> f64; + +/// 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) -> i64; /// Parse the bytes beginning at the `start` position in the BLOB as an `INT` /// in big-endian byte order. @@ -2769,24 +2786,7 @@ fn parse_be_float(blob: Blob, start: int, len: int) -> float; /// /// print(x.to_hex()); // prints "02030000...00" /// ``` -fn parse_be_int(blob: Blob, start: int, len: int) -> int; - -/// 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: ExclusiveRange) -> int; +fn parse_be_int(blob: Blob, start: int, len: int) -> i64; /// Parse the bytes within an inclusive `range` in the BLOB as an `INT` /// in big-endian byte order. @@ -2803,7 +2803,7 @@ fn parse_be_int(blob: Blob, range: ExclusiveRange) -> int; /// /// print(x.to_hex()); // prints "0203040000...00" /// ``` -fn parse_be_int(blob: Blob, range: InclusiveRange) -> int; +fn parse_be_int(blob: Blob, range: RangeInclusive) -> i64; /// Parse a string into a floating-point number. /// @@ -2816,17 +2816,6 @@ fn parse_be_int(blob: Blob, range: InclusiveRange) -> int; /// ``` 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. @@ -2844,12 +2833,16 @@ fn parse_int(string: String) -> int; /// ``` fn parse_int(string: String, radix: int) -> int; -/// Parse the bytes within an inclusive `range` in the BLOB as a `FLOAT` -/// in little-endian byte order. +/// Parse a string into an integer number. /// -/// * 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: InclusiveRange) -> float; +/// # Example +/// +/// ```rhai +/// let x = parse_int("123"); +/// +/// print(x); // prints 123 +/// ``` +fn parse_int(string: String) -> int; /// Parse the bytes beginning at the `start` position in the BLOB as a `FLOAT` /// in little-endian byte order. @@ -2862,14 +2855,21 @@ fn parse_le_float(blob: Blob, range: InclusiveRange) -> float; /// /// * 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; +fn parse_le_float(blob: Blob, start: int, len: int) -> f64; /// 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: ExclusiveRange) -> float; +fn parse_le_float(blob: Blob, range: Range) -> f64; + +/// 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) -> f64; /// Parse the bytes within an exclusive `range` in the BLOB as an `INT` /// in little-endian byte order. @@ -2886,7 +2886,7 @@ fn parse_le_float(blob: Blob, range: ExclusiveRange) -> float; /// /// print(x.to_hex()); // prints "0302" /// ``` -fn parse_le_int(blob: Blob, range: ExclusiveRange) -> int; +fn parse_le_int(blob: Blob, range: Range) -> i64; /// Parse the bytes beginning at the `start` position in the BLOB as an `INT` /// in little-endian byte order. @@ -2909,7 +2909,7 @@ fn parse_le_int(blob: Blob, range: ExclusiveRange) -> int; /// /// print(x.to_hex()); // prints "0302" /// ``` -fn parse_le_int(blob: Blob, start: int, len: int) -> int; +fn parse_le_int(blob: Blob, start: int, len: int) -> i64; /// Parse the bytes within an inclusive `range` in the BLOB as an `INT` /// in little-endian byte order. @@ -2926,7 +2926,39 @@ fn parse_le_int(blob: Blob, start: int, len: int) -> int; /// /// print(x.to_hex()); // prints "040302" /// ``` -fn parse_le_int(blob: Blob, range: InclusiveRange) -> int; +fn parse_le_int(blob: Blob, range: RangeInclusive) -> i64; + +/// 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) -> i64; + +/// 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. @@ -2945,38 +2977,6 @@ fn parse_le_int(blob: Blob, range: InclusiveRange) -> int; /// ``` fn pop(string: String, len: int) -> String; -/// 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 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 element from the array and return it. /// /// If the array is empty, `()` is returned. @@ -2992,9 +2992,21 @@ fn pop(blob: Blob) -> int; /// ``` fn pop(array: Array) -> ?; +/// Convert the array into a string. +fn print(array: Array) -> String; + +/// Return the empty string. +fn print(unit: ()) -> String; + +/// Return the character into a string. +fn print(character: char) -> String; + /// Return the `string`. fn print(string: String) -> String; +/// Convert the value of `number` into a string. +fn print(number: f32) -> String; + /// Return the empty string. fn print() -> String; @@ -3004,38 +3016,11 @@ fn print(number: f64) -> String; /// Convert the object map into a string. fn print(map: Map) -> String; -/// Convert the value of `number` into a string. -fn print(number: f32) -> String; - -/// Convert the value of the `item` into a string. -fn print(item: ?) -> String; - /// Return the boolean value into a string. fn print(value: bool) -> String; -/// Convert the array into a string. -fn print(array: Array) -> String; - -/// Return the character into a string. -fn print(character: char) -> String; - -/// Return the empty string. -fn print(unit: ()) -> 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 push(blob: Blob, value: int) -> (); +/// Convert the value of the `item` into a string. +fn print(item: ?) -> String; /// Add a new element, which is not another array, to the end of the array. /// @@ -3052,27 +3037,20 @@ fn push(blob: Blob, value: int) -> (); /// ``` fn push(array: Array, item: ?) -> (); -/// Return an iterator over the exclusive range of `from..to`, each iteration increasing by `step`. -/// The value `to` is never included. +/// Add a new byte `value` to the end of the BLOB. /// -/// 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. +/// Only the lower 8 bits of the `value` are used; all other bits are ignored. /// /// # Example /// /// ```rhai -/// // prints all values from 8 to 17 in steps of 3 -/// for n in range(8, 18, 3) { -/// print(n); -/// } +/// let b = blob(); /// -/// // prints all values down from 18 to 9 in steps of -3 -/// for n in range(18, 8, -3) { -/// print(n); -/// } +/// b.push(0x42); +/// +/// print(b); // prints "[42]" /// ``` -fn range(from: i16, to: i16, step: i16) -> Iterator; +fn push(blob: Blob, value: int) -> (); /// Return an iterator over the exclusive range of `from..to`, each iteration increasing by `step`. /// The value `to` is never included. @@ -3094,20 +3072,7 @@ fn range(from: i16, to: i16, step: i16) -> Iterator; /// print(n); /// } /// ``` -fn range(from: i8, to: i8, step: 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: u16, to: u16) -> Iterator; +fn range(from: u8, to: u8, step: u8) -> Iterator; /// Return an iterator over the exclusive range of `from..to`, each iteration increasing by `step`. /// The value `to` is never included. @@ -3129,7 +3094,7 @@ fn range(from: u16, to: u16) -> Iterator; /// print(n); /// } /// ``` -fn range(from: i32, to: i32, step: i32) -> Iterator; +fn range(from: i128, to: i128, step: i128) -> Iterator; /// Return an iterator over an exclusive range, each iteration increasing by `step`. /// @@ -3150,7 +3115,64 @@ fn range(from: i32, to: i32, step: i32) -> Iterator; /// print(n); /// } /// ``` -fn range(range: Range, step: u32) -> Iterator; +fn range(range: Range, 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: float, to: float, step: float) -> 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`, 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`. /// The value `to` is never included. @@ -3165,6 +3187,19 @@ fn range(range: Range, step: u32) -> Iterator; /// ``` 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: i128, to: i128) -> Iterator; + /// Return an iterator over the exclusive range of `from..to`. /// The value `to` is never included. /// @@ -3210,7 +3245,7 @@ fn range(range: Range, step: i32) -> Iterator; /// print(n); /// } /// ``` -fn range(from: u32, to: u32) -> Iterator; +fn range(from: u8, to: u8) -> Iterator; /// Return an iterator over the exclusive range of `from..to`, each iteration increasing by `step`. /// The value `to` is never included. @@ -3232,7 +3267,7 @@ fn range(from: u32, to: u32) -> Iterator; /// print(n); /// } /// ``` -fn range(from: i128, to: i128, step: i128) -> Iterator; +fn range(from: u16, to: u16, step: u16) -> Iterator; /// Return an iterator over an exclusive range, each iteration increasing by `step`. /// @@ -3253,41 +3288,7 @@ fn range(from: i128, to: i128, step: i128) -> Iterator; /// print(n); /// } /// ``` -fn range(range: Range, step: 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: i8, to: 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: i8) -> Iterator; +fn range(range: Range, step: u64) -> Iterator; /// Return an iterator over an exclusive range, each iteration increasing by `step`. /// @@ -3321,7 +3322,98 @@ fn range(range: Range, step: u8) -> Iterator; /// print(n); /// } /// ``` -fn range(from: i16, to: i16) -> Iterator; +fn range(from: u32, to: 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: i32, to: i32, step: 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: u128, to: 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: 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: i16, to: i16, step: 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: i8, to: i8) -> Iterator; /// Return an iterator over the exclusive range of `from..to`, each iteration increasing by `step`. /// The value `to` is never included. @@ -3345,140 +3437,6 @@ fn range(from: i16, to: i16) -> Iterator; /// ``` fn range(from: u128, to: u128, 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 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`, 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: ?, to: ?, step: ?) -> 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: i64, to: i64, step: i64) -> 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 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; - -/// 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. @@ -3500,26 +3458,40 @@ fn range(from: u8, to: u8) -> Iterator; /// ``` fn range(range: Range, step: i128) -> Iterator; -/// Return an iterator over an exclusive range, each iteration increasing by `step`. +/// Return an iterator over the exclusive range of `from..to`. +/// The value `to` is never included. /// -/// If `range` is reversed and `step` < 0, iteration goes backwards. +/// # Example /// -/// Otherwise, if `range` is empty, an empty iterator is returned. +/// ```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`, 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) { +/// 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) { +/// for n in range(18, 8, -3) { /// print(n); /// } /// ``` -fn range(range: ?, step: ?) -> Iterator; +fn range(from: u32, to: u32, step: u32) -> Iterator; /// Return an iterator over an exclusive range, each iteration increasing by `step`. /// @@ -3542,27 +3514,89 @@ fn range(range: ?, step: ?) -> Iterator; /// ``` fn range(range: Range, step: i64) -> Iterator; -/// Return an iterator over the exclusive range of `from..to`, each iteration increasing by `step`. -/// The value `to` is never included. +/// Return an iterator over an exclusive range, each iteration increasing by `step`. /// -/// If `from` > `to` and `step` < 0, iteration goes backwards. +/// If `range` is reversed and `step` < 0, iteration goes backwards. /// -/// If `from` > `to` and `step` > 0 or `from` < `to` and `step` < 0, an empty iterator is returned. +/// 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) { +/// 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) { +/// for n in range(18..8, -3) { /// print(n); /// } /// ``` -fn range(from: u16, to: u16, step: u16) -> Iterator; +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: 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: 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: u16) -> Iterator; /// Return an iterator over the exclusive range of `from..to`. /// The value `to` is never included. @@ -3597,41 +3631,7 @@ fn range(from: i64, to: i64) -> Iterator; /// print(n); /// } /// ``` -fn range(from: u64, to: u64, step: 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: i128, to: 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; +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. @@ -3653,7 +3653,59 @@ fn range(range: Range, step: i16) -> Iterator; /// print(n); /// } /// ``` -fn range(from: u32, to: u32, step: u32) -> Iterator; +fn range(from: i64, to: i64, step: i64) -> Iterator; + +/// 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 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 a function named by `reducer`. /// @@ -3687,58 +3739,6 @@ fn range(from: u32, to: u32, step: u32) -> Iterator; /// ``` fn reduce(array: Array, reducer: String) -> 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 while applying the `reducer` function. /// /// # Function Parameters @@ -3762,39 +3762,6 @@ fn reduce(array: Array, reducer: FnPtr, initial: ?) -> RhaiResult; /// ``` fn reduce(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, 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. /// @@ -3873,6 +3840,62 @@ fn reduce_rev(array: Array, reducer: String, initial: ?) -> RhaiResult; /// ``` 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, 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; + +/// 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) -> i64; + /// Remove any property of the specified `name` from the object map, returning its value. /// /// If the property does not exist, `()` is returned. @@ -3924,29 +3947,6 @@ fn remove(string: String, sub_string: String) -> (); /// ``` 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 all occurrences of a character from the string. /// /// # Example @@ -3960,18 +3960,18 @@ fn remove(blob: Blob, index: int) -> int; /// ``` fn remove(string: String, character: char) -> (); -/// Replace all occurrences of the specified character in the string with another character. +/// 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("l", '*'); +/// text.replace("hello", '*'); /// -/// print(text); // prints "he**o, wor*d! he**o, foobar!" +/// print(text); // prints "*, world! *, foobar!" /// ``` -fn replace(string: String, find_character: char, substitute_character: char) -> (); +fn replace(string: String, find_string: String, substitute_character: char) -> (); /// Replace all occurrences of the specified sub-string in the string with another string. /// @@ -3986,18 +3986,18 @@ fn replace(string: String, find_character: char, substitute_character: char) -> /// ``` fn replace(string: String, find_string: String, substitute_string: String) -> (); -/// Replace all occurrences of the specified sub-string in the string with the specified character. +/// Replace all occurrences of the specified character in the string with another character. /// /// # Example /// /// ```rhai /// let text = "hello, world! hello, foobar!"; /// -/// text.replace("hello", '*'); +/// text.replace("l", '*'); /// -/// print(text); // prints "*, world! *, foobar!" +/// print(text); // prints "he**o, wor*d! he**o, foobar!" /// ``` -fn replace(string: String, find_string: String, substitute_character: char) -> (); +fn replace(string: String, find_character: char, substitute_character: char) -> (); /// Replace all occurrences of the specified character in the string with another string. /// @@ -4062,28 +4062,34 @@ fn retain(blob: Blob, start: int, len: int) -> Blob; /// /// print(b2); // prints "[01]" /// ``` -fn retain(blob: Blob, range: InclusiveRange) -> Blob; +fn retain(blob: Blob, range: RangeInclusive) -> Blob; -/// Remove all elements in the array not within an inclusive `range` and return them as a new 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(1..=3); +/// let y = x.retain(|v| v >= 3); /// -/// print(x); // prints "[2, 3, 4]" +/// print(x); // prints "[3, 4, 5]" /// -/// print(y); // prints "[1, 5]" +/// print(y); // prints "[1, 2]" /// -/// let z = x.retain(1..=2); +/// let z = x.retain(|v, i| v + i <= 5); /// /// print(x); // prints "[3, 4]" /// -/// print(z); // prints "[1]" +/// print(z); // prints "[5]" /// ``` -fn retain(array: Array, range: InclusiveRange) -> Array; +fn retain(array: Array, filter: FnPtr) -> Array; /// 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. @@ -4118,50 +4124,6 @@ fn retain(array: Array, range: InclusiveRange) -> Array; /// ``` fn retain(array: Array, filter: String) -> 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: ExclusiveRange) -> Blob; - -/// 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: ExclusiveRange) -> Array; - /// 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). @@ -4189,32 +4151,83 @@ fn retain(array: Array, range: ExclusiveRange) -> Array; /// ``` fn retain(array: Array, start: int, len: int) -> 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 +/// 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(|v| v >= 3); +/// let y = x.retain(1..4); /// -/// print(x); // prints "[3, 4, 5]" +/// print(x); // prints "[2, 3, 4]" /// -/// print(y); // prints "[1, 2]" +/// print(y); // prints "[1, 5]" /// -/// let z = x.retain(|v, i| v + i <= 5); +/// let z = x.retain(1..3); /// /// print(x); // prints "[3, 4]" /// -/// print(z); // prints "[5]" +/// print(z); // prints "[1]" /// ``` -fn retain(array: Array, filter: FnPtr) -> Array; +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; + +/// 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. /// @@ -4233,68 +4246,9 @@ fn retain(array: Array, filter: FnPtr) -> Array; /// ``` fn reverse(blob: 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) -> (); - /// Return the nearest whole number closest to the floating-point number. /// Rounds away from zero. -fn round(x: float) -> float; - -/// 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: ?) -> (); +fn round(x: float) -> f64; /// Set the `index` position in the string to a new `character`. /// @@ -4346,6 +4300,52 @@ fn set(string: String, index: int, character: char) -> (); /// ``` 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 _tag_ of a `Dynamic` value. /// /// # Example @@ -4383,19 +4383,6 @@ fn set tag(value: ?, tag: int) -> (); /// ``` 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: ExclusiveRange, new_value: int) -> (); - /// Replace an inclusive range of bits in the number with a new value. /// /// # Example @@ -4407,7 +4394,20 @@ fn set_bits(value: int, range: ExclusiveRange, new_value: int) -> (); /// /// print(x); // print 123200 /// ``` -fn set_bits(value: int, range: InclusiveRange, new_value: int) -> (); +fn set_bits(value: int, range: RangeInclusive, new_value: int) -> (); + +/// 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 a portion of bits in the number with a new value. /// @@ -4443,23 +4443,6 @@ fn set_bits(value: int, bit: int, bits: int, new_value: int) -> (); /// ``` fn set_tag(value: ?, tag: int) -> (); -/// 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; - /// Remove the first element from the array and return it. /// /// If the array is empty, `()` is returned. @@ -4475,33 +4458,50 @@ fn shift(blob: Blob) -> int; /// ``` fn shift(array: Array) -> ?; -/// Return the sign (as an integer) of the number according to the following: +/// Remove the first byte from the BLOB and return it. /// -/// * `0` if the number is zero -/// * `1` if the number is positive -/// * `-1` if the number is negative -fn sign(x: i8) -> int; +/// 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) -> i64; /// 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; +fn sign(x: i128) -> i64; /// 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; +fn sign(x: i8) -> i64; /// 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; +fn sign(x: int) -> i64; + +/// 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) -> i64; /// Return the sign (as an integer) of the floating-point number according to the following: /// @@ -4510,13 +4510,6 @@ fn sign(x: i32) -> int; /// * `-1` if the number is negative fn sign(x: f32) -> 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 @@ -4524,18 +4517,45 @@ fn sign(x: int) -> int; /// * `-1` if the number is negative fn sign(x: f64) -> 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) -> i64; + /// Return the sine of the floating-point number in radians. -fn sin(x: float) -> float; +fn sin(x: float) -> f64; /// 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: ?) -> (); +fn sinh(x: float) -> f64; /// 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 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; + /// Return `true` if any element in the array that returns `true` when applied a function named /// by `filter`. /// @@ -4565,25 +4585,30 @@ fn sleep(seconds: int) -> (); /// ``` fn some(array: Array, filter: String) -> bool; -/// Return `true` if any element in the array that returns `true` when applied the `filter` function. +/// Sort the array based on applying the `comparer` function. /// /// # Function Parameters /// -/// * `element`: copy of array element -/// * `index` _(optional)_: current index in the array +/// * `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, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 5]; +/// let x = [1, 3, 5, 7, 9, 2, 4, 6, 8, 10]; /// -/// print(x.some(|v| v > 3)); // prints true +/// // Do comparisons in reverse +/// x.sort(|a, b| if a > b { -1 } else if a < b { 1 } else { 0 }); /// -/// print(x.some(|v| v > 10)); // prints false -/// -/// print(x.some(|v, i| i > v)); // prints true +/// print(x); // prints "[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]" /// ``` -fn some(array: Array, filter: FnPtr) -> bool; +fn sort(array: Array, comparer: FnPtr) -> (); /// Sort the array based on applying a function named by `comparer`. /// @@ -4620,31 +4645,6 @@ fn some(array: Array, filter: FnPtr) -> bool; /// ``` 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) -> (); - /// Sort the array. /// /// All elements in the array must be of the same data type. @@ -4670,34 +4670,6 @@ fn sort(array: Array, comparer: FnPtr) -> (); /// ``` fn sort(array: 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: ExclusiveRange, 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: InclusiveRange, replace: Blob) -> (); - /// Replace an exclusive range of the array with another array. /// /// # Example @@ -4710,7 +4682,7 @@ fn splice(blob: Blob, range: InclusiveRange, replace: Blob) -> (); /// /// print(x); // prints "[1, 7, 8, 9, 10, 4, 5]" /// ``` -fn splice(array: Array, range: ExclusiveRange, replace: Array) -> (); +fn splice(array: Array, range: Range, replace: Array) -> (); /// Replace a portion of the array with another array. /// @@ -4736,19 +4708,33 @@ fn splice(array: Array, range: ExclusiveRange, replace: Array) -> (); /// ``` fn splice(array: Array, start: int, len: int, replace: Array) -> (); -/// Replace an inclusive range of the array with another array. +/// Replace an exclusive `range` of the BLOB with another BLOB. /// /// # Example /// /// ```rhai -/// let x = [1, 2, 3, 4, 5]; -/// let y = [7, 8, 9, 10]; +/// let b1 = blob(10, 0x42); +/// let b2 = blob(5, 0x18); /// -/// x.splice(1..=3, y); +/// b1.splice(1..4, b2); /// -/// print(x); // prints "[1, 7, 8, 9, 10, 5]" +/// print(b1); // prints "[4218181818184242 42424242]" /// ``` -fn splice(array: Array, range: InclusiveRange, replace: Array) -> (); +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 BLOB with another BLOB. /// @@ -4774,6 +4760,45 @@ fn splice(array: Array, range: InclusiveRange, replace: Array) -> (); /// ``` fn splice(blob: Blob, start: int, len: int, replace: Blob) -> (); +/// 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) -> (); + +/// 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 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; + /// 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). @@ -4796,16 +4821,40 @@ fn splice(blob: Blob, start: int, len: int, replace: Blob) -> (); /// ``` fn split(blob: Blob, index: int) -> Blob; -/// Split the string into segments based on a `delimiter` string, returning an array of the segments. +/// 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` character, 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!"] +/// print(text.split('l')); // prints ["he", "", "o, wor", "d! he", "", "o, foo!"] /// ``` -fn split(string: String, delimiter: String) -> Array; +fn split(string: String, delimiter: char) -> Array; /// Cut off the array at `index` and return it as a new array. /// @@ -4838,44 +4887,6 @@ fn split(array: Array, index: int) -> Array; /// ``` fn split(string: String) -> Array; -/// 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 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. /// @@ -4890,28 +4901,17 @@ fn split(string: String, delimiter: String, segments: int) -> Array; /// ``` fn split(string: String, delimiter: char, segments: int) -> Array; -/// Split the string into segments based on a `delimiter` character, returning an array of the segments. +/// 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('l')); // prints ["he", "", "o, wor", "d! he", "", "o, foo!"] +/// print(text.split_rev("ll")); // prints ["o, foo!", "o, world! he", "he"] /// ``` -fn split(string: String, delimiter: char) -> 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; +fn split_rev(string: String, delimiter: String) -> 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. @@ -4927,6 +4927,18 @@ fn split_rev(string: String, delimiter: char) -> Array; /// ``` fn split_rev(string: String, delimiter: String, segments: int) -> 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 the specified number of `segments` based on a `delimiter` character, /// returning an array of the segments. /// @@ -4941,26 +4953,14 @@ fn split_rev(string: String, delimiter: String, segments: int) -> Array; /// ``` fn split_rev(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; - /// 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; +fn sqrt(x: float) -> f64; /// Return the start of the inclusive range. -fn start(range: InclusiveRange) -> int; +fn start(range: InclusiveRange) -> i64; + +/// Return the start of the exclusive range. +fn start(range: ExclusiveRange) -> i64; /// Return `true` if the string starts with a specified string. /// @@ -4975,24 +4975,6 @@ fn start(range: InclusiveRange) -> int; /// ``` fn starts_with(string: String, match_string: String) -> bool; -/// 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 an exclusive range of characters from the string and return it as a new string. /// /// # Example @@ -5002,7 +4984,7 @@ fn sub_string(string: String, start: int) -> String; /// /// print(text.sub_string(3..7)); // prints "lo, " /// ``` -fn sub_string(string: String, range: ExclusiveRange) -> String; +fn sub_string(string: String, range: Range) -> String; /// Copy a portion of the string and return it as a new string. /// @@ -5023,6 +5005,24 @@ fn sub_string(string: String, range: ExclusiveRange) -> String; /// ``` fn sub_string(string: String, start: int, len: int) -> 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 an inclusive range of characters from the string and return it as a new string. /// /// # Example @@ -5032,7 +5032,7 @@ fn sub_string(string: String, start: int, len: int) -> String; /// /// print(text.sub_string(3..=7)); // prints "lo, w" /// ``` -fn sub_string(string: String, range: InclusiveRange) -> String; +fn sub_string(string: String, range: RangeInclusive) -> String; /// Return the _tag_ of a `Dynamic` value. /// @@ -5045,13 +5045,13 @@ fn sub_string(string: String, range: InclusiveRange) -> String; /// /// print(x.tag); // prints 42 /// ``` -fn tag(value: ?) -> int; +fn tag(value: ?) -> i64; /// Return the tangent of the floating-point number in radians. -fn tan(x: float) -> float; +fn tan(x: float) -> f64; /// Return the hyperbolic tangent of the floating-point number in radians. -fn tanh(x: float) -> float; +fn tanh(x: float) -> f64; /// Create a timestamp containing the current system time. fn timestamp() -> Instant; @@ -5070,34 +5070,34 @@ fn timestamp() -> Instant; fn to_array(blob: Blob) -> Array; /// Convert the `value` into a string in binary format. -fn to_binary(value: u8) -> String; +fn to_binary(value: i16) -> 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: u128) -> String; /// Convert the `value` into a string in binary format. -fn to_binary(value: i64) -> String; +fn to_binary(value: i128) -> String; /// Convert the `value` into a string in binary format. -fn to_binary(value: i32) -> String; +fn to_binary(value: i64) -> 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: u32) -> String; +fn to_binary(value: i32) -> String; /// 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; +fn to_binary(value: u8) -> 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: u16) -> String; +fn to_binary(value: u32) -> String; /// Convert the string into an UTF-8 encoded byte-stream as a BLOB. /// @@ -5124,13 +5124,16 @@ fn to_blob(string: String) -> Blob; fn to_chars(string: String) -> Array; /// Convert the value of `number` into a string. -fn to_debug(number: f32) -> String; +fn to_debug(number: f64) -> 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: f64) -> String; +fn to_debug(number: f32) -> String; + +/// Convert the function pointer into a string in debug format. +fn to_debug(f: FnPtr) -> String; /// Convert the string into debug format. fn to_debug(string: String) -> String; @@ -5138,102 +5141,99 @@ fn to_debug(string: String) -> String; /// Convert the string into debug format. fn to_debug(character: char) -> 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 the array into a string. -fn to_debug(array: Array) -> 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 array into a string. +fn to_debug(array: Array) -> String; + +/// Convert the unit into a string in debug format. +fn to_debug(unit: ()) -> String; + /// Convert radians to degrees. -fn to_degrees(x: float) -> float; +fn to_degrees(x: float) -> f64; -fn to_float(x: u8) -> float; - -fn to_float(x: u128) -> float; - -fn to_float(x: i64) -> float; +fn to_float(x: i16) -> f64; /// Convert the 32-bit floating-point number to 64-bit. fn to_float(x: f32) -> f64; -fn to_float(x: i32) -> float; +fn to_float(x: u128) -> f64; -fn to_float(x: u32) -> float; +fn to_float(x: u16) -> f64; -fn to_float(x: i128) -> float; +fn to_float(x: i128) -> f64; -fn to_float(x: i16) -> float; +fn to_float(x: i32) -> f64; -fn to_float(x: i8) -> float; +fn to_float(x: i64) -> f64; -fn to_float(x: u16) -> float; +fn to_float(x: u8) -> f64; -/// Convert the `value` into a string in hex format. -fn to_hex(value: i32) -> String; +fn to_float(x: i8) -> f64; -/// 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: i64) -> String; - -/// Convert the `value` into a string in hex format. -fn to_hex(value: u8) -> 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: i8) -> String; - -/// Convert the `value` into a string in hex format. -fn to_hex(value: u16) -> String; +fn to_float(x: u32) -> f64; /// 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: u16) -> 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: i128) -> String; +/// Convert the `value` into a string in hex format. +fn to_hex(value: i64) -> 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: i32) -> String; + +/// Convert the `value` into a string in hex format. +fn to_hex(value: u8) -> 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: u32) -> String; -fn to_int(x: i128) -> int; - -fn to_int(x: u32) -> int; - -fn to_int(x: i8) -> int; - -fn to_int(x: char) -> int; - -fn to_int(x: u16) -> int; - -fn to_int(x: i16) -> int; - -/// Convert the floating-point number into an integer. -fn to_int(x: f64) -> int; - -fn to_int(x: i64) -> int; - -fn to_int(x: u8) -> int; - -fn to_int(x: u128) -> int; - -fn to_int(x: i32) -> int; +fn to_int(x: char) -> i64; /// Convert the floating-point number into an integer. fn to_int(x: f32) -> int; -fn to_int(x: u64) -> int; +fn to_int(x: i16) -> i64; + +/// Convert the floating-point number into an integer. +fn to_int(x: f64) -> int; + +fn to_int(x: u128) -> i64; + +fn to_int(x: u16) -> i64; + +fn to_int(x: i128) -> i64; + +fn to_int(x: i8) -> i64; + +fn to_int(x: u32) -> i64; + +fn to_int(x: i32) -> i64; + +fn to_int(x: u64) -> i64; + +fn to_int(x: i64) -> i64; + +fn to_int(x: u8) -> i64; /// Return the JSON representation of the object map. /// @@ -5256,19 +5256,6 @@ fn to_int(x: u64) -> int; /// ``` 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 @@ -5282,8 +5269,18 @@ fn to_lower(character: char) -> char; /// ``` fn to_lower(string: String) -> String; -/// Convert the `value` into a string in octal format. -fn to_octal(value: i128) -> 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 `value` into a string in octal format. fn to_octal(value: u32) -> String; @@ -5291,47 +5288,32 @@ fn to_octal(value: u32) -> 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: u16) -> 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: i64) -> String; - /// Convert the `value` into a string in octal format. fn to_octal(value: u8) -> String; /// Convert the `value` into a string in octal format. -fn to_octal(value: u128) -> String; +fn to_octal(value: u64) -> 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: u64) -> String; +fn to_octal(value: i64) -> 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: 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: i16) -> String; /// Convert degrees to radians. -fn to_radians(x: float) -> float; - -/// Return the `string`. -fn to_string(string: String) -> String; - -/// Convert the value of `number` into a string. -fn to_string(number: f64) -> 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 the `item` into a string. -fn to_string(item: ?) -> String; - -/// Return the boolean value into a string. -fn to_string(value: bool) -> String; +fn to_radians(x: float) -> f64; /// Convert the array into a string. fn to_string(array: Array) -> String; @@ -5342,18 +5324,23 @@ fn to_string(unit: ()) -> String; /// Return the character into a string. fn to_string(character: char) -> String; -/// 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; +/// Return the `string`. +fn to_string(string: String) -> String; + +/// Convert the value of `number` into a string. +fn to_string(number: f32) -> 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: f64) -> String; + +/// Return the boolean value into a string. +fn to_string(value: bool) -> String; + +/// Convert the value of the `item` into a string. +fn to_string(item: ?) -> String; /// Convert the character to upper-case and return it as a new character. /// @@ -5368,6 +5355,19 @@ fn to_upper(string: String) -> String; /// ``` 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 @@ -5401,26 +5401,6 @@ fn trim(string: String) -> (); /// ``` fn truncate(string: String, len: int) -> (); -/// 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. @@ -5443,6 +5423,26 @@ fn truncate(array: Array, len: int) -> (); /// ``` fn truncate(blob: Blob, len: int) -> (); +/// 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) -> (); + /// Return an array with all the property values in the object map. /// /// # Example @@ -5469,24 +5469,7 @@ fn values(map: Map) -> Array; /// /// print(b); // prints "[0068656c6c6f0000]" /// ``` -fn write_ascii(blob: Blob, range: InclusiveRange, string: String) -> (); - -/// 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: ExclusiveRange, string: String) -> (); +fn write_ascii(blob: Blob, range: RangeInclusive, string: String) -> (); /// Write an ASCII string to the bytes within an exclusive `range` in the BLOB. /// @@ -5508,34 +5491,22 @@ fn write_ascii(blob: Blob, range: ExclusiveRange, string: String) -> (); /// ``` fn write_ascii(blob: Blob, start: int, len: int, string: String) -> (); -/// Write an `INT` value to the bytes within an inclusive `range` in the BLOB -/// in big-endian byte order. +/// Write an ASCII string to the bytes within an exclusive `range` in the BLOB. /// -/// * 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. +/// 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, 0x42); +/// let b = blob(8); /// -/// b.write_be_int(1..=3, 0x99); +/// b.write_ascii(1..5, "hello, world!"); /// -/// print(b); // prints "[4200000042424242]" +/// print(b); // prints "[0068656c6c000000]" /// ``` -fn write_be(blob: Blob, range: InclusiveRange, value: int) -> (); - -/// 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: ExclusiveRange, value: float) -> (); - -/// 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: InclusiveRange, value: float) -> (); +fn write_ascii(blob: Blob, range: Range, string: String) -> (); /// Write an `INT` value to the bytes within an exclusive `range` in the BLOB /// in big-endian byte order. @@ -5550,7 +5521,29 @@ fn write_be(blob: Blob, range: InclusiveRange, value: float) -> (); /// /// print(b); // prints "[4200004242424242]" /// ``` -fn write_be(blob: Blob, range: ExclusiveRange, value: int) -> (); +fn write_be(blob: Blob, range: Range, value: int) -> (); + +/// 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 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 beginning at the `start` position in the BLOB /// in big-endian byte order. @@ -5573,6 +5566,13 @@ fn write_be(blob: Blob, range: ExclusiveRange, value: int) -> (); /// ``` 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 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 a `FLOAT` value to the bytes beginning at the `start` position in the BLOB /// in big-endian byte order. /// @@ -5586,6 +5586,26 @@ fn write_be(blob: Blob, start: int, len: int, value: int) -> (); /// * 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 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 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 beginning at the `start` position in the BLOB /// in little-endian byte order. /// @@ -5607,12 +5627,27 @@ fn write_be(blob: Blob, start: int, len: int, value: float) -> (); /// ``` fn write_le(blob: Blob, start: int, len: int, value: int) -> (); +/// 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: InclusiveRange, value: float) -> (); +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. @@ -5627,42 +5662,7 @@ fn write_le(blob: Blob, range: InclusiveRange, value: float) -> (); /// /// print(b); // prints "[0078563400000000]" /// ``` -fn write_le(blob: Blob, range: InclusiveRange, 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 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: ExclusiveRange, 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: ExclusiveRange, value: int) -> (); +fn write_le(blob: Blob, range: RangeInclusive, value: int) -> (); /// Write a string to the bytes within an inclusive `range` in the BLOB in UTF-8 encoding. /// @@ -5676,21 +5676,7 @@ fn write_le(blob: Blob, range: ExclusiveRange, value: int) -> (); /// /// print(b); // prints "[00e69c9de3810000]" /// ``` -fn write_utf8(blob: Blob, range: InclusiveRange, string: String) -> (); - -/// 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: ExclusiveRange, string: String) -> (); +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. /// @@ -5712,20 +5698,34 @@ fn write_utf8(blob: Blob, range: ExclusiveRange, string: String) -> (); /// ``` fn write_utf8(blob: Blob, start: int, len: int, string: String) -> (); -op |(i32, i32) -> i32; - -op |(u64, u64) -> u64; - -op |(u32, u32) -> u32; +/// 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) -> (); op |(u16, u16) -> u16; -op |(i16, i16) -> i16; +op |(u32, u32) -> u32; op |(u128, u128) -> u128; op |(i8, i8) -> i8; +op |(i128, i128) -> i128; + +op |(u64, u64) -> u64; + op |(u8, u8) -> u8; -op |(i128, i128) -> i128; \ No newline at end of file +op |(i16, i16) -> i16; + +op |(i32, i32) -> i32; \ No newline at end of file diff --git a/src/definitions/builtin-operators.d.rhai b/src/definitions/builtin-operators.d.rhai new file mode 100644 index 00000000..d907afcf --- /dev/null +++ b/src/definitions/builtin-operators.d.rhai @@ -0,0 +1,251 @@ +module static; + +op ==(i64, i64) -> bool; +op !=(i64, i64) -> bool; +op >(i64, i64) -> bool; +op >=(i64, i64) -> bool; +op <(i64, i64) -> bool; +op <=(i64, i64) -> bool; +op &(i64, i64) -> i64; +op |(i64, i64) -> i64; +op ^(i64, i64) -> i64; +op ..(i64, i64) -> Range; +op ..=(i64, i64) -> 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 +(i64, i64) -> i64; +op -(i64, i64) -> i64; +op *(i64, i64) -> i64; +op /(i64, i64) -> i64; +op %(i64, i64) -> i64; +op **(i64, i64) -> i64; +op >>(i64, i64) -> i64; +op <<(i64, i64) -> i64; + +op +(f64, f64) -> f64; +op -(f64, f64) -> f64; +op *(f64, f64) -> f64; +op /(f64, f64) -> f64; +op %(f64, f64) -> f64; +op **(f64, f64) -> f64; +op ==(f64, f64) -> bool; +op !=(f64, f64) -> bool; +op >(f64, f64) -> bool; +op >=(f64, f64) -> bool; +op <(f64, f64) -> bool; +op <=(f64, f64) -> bool; + +op +(f64, i64) -> f64; +op -(f64, i64) -> f64; +op *(f64, i64) -> f64; +op /(f64, i64) -> f64; +op %(f64, i64) -> f64; +op **(f64, i64) -> f64; +op ==(f64, i64) -> bool; +op !=(f64, i64) -> bool; +op >(f64, i64) -> bool; +op >=(f64, i64) -> bool; +op <(f64, i64) -> bool; +op <=(f64, i64) -> bool; + +op +(i64, f64) -> f64; +op -(i64, f64) -> f64; +op *(i64, f64) -> f64; +op /(i64, f64) -> f64; +op %(i64, f64) -> f64; +op **(i64, f64) -> f64; +op ==(i64, f64) -> bool; +op !=(i64, f64) -> bool; +op >(i64, f64) -> bool; +op >=(i64, f64) -> bool; +op <(i64, f64) -> bool; +op <=(i64, f64) -> 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, i64) -> Decimal; +op -(Decimal, i64) -> Decimal; +op *(Decimal, i64) -> Decimal; +op /(Decimal, i64) -> Decimal; +op %(Decimal, i64) -> Decimal; +op **(Decimal, i64) -> Decimal; +op ==(Decimal, i64) -> bool; +op !=(Decimal, i64) -> bool; +op >(Decimal, i64) -> bool; +op >=(Decimal, i64) -> bool; +op <(Decimal, i64) -> bool; +op <=(Decimal, i64) -> bool; + +op +(i64, Decimal) -> Decimal; +op -(i64, Decimal) -> Decimal; +op *(i64, Decimal) -> Decimal; +op /(i64, Decimal) -> Decimal; +op %(i64, Decimal) -> Decimal; +op **(i64, Decimal) -> Decimal; +op ==(i64, Decimal) -> bool; +op !=(i64, Decimal) -> bool; +op >(i64, Decimal) -> bool; +op >=(i64, Decimal) -> bool; +op <(i64, Decimal) -> bool; +op <=(i64, 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 +=(i64, i64); +op -=(i64, i64); +op *=(i64, i64); +op /=(i64, i64); +op %=(i64, i64); +op **=(i64, i64); +op >>=(i64, i64); +op <<=(i64, i64); +op &=(i64, i64); +op |=(i64, i64); +op ^=(i64, i64); + +op +=(f64, f64); +op -=(f64, f64); +op *=(f64, f64); +op /=(f64, f64); +op %=(f64, f64); +op **=(f64, f64); + +op +=(f64, i64); +op -=(f64, i64); +op *=(f64, i64); +op /=(f64, i64); +op %=(f64, i64); +op **=(f64, i64); + +op +=(Decimal, Decimal); +op -=(Decimal, Decimal); +op *=(Decimal, Decimal); +op /=(Decimal, Decimal); +op %=(Decimal, Decimal); +op **=(Decimal, Decimal); + +op +=(Decimal, i64); +op -=(Decimal, i64); +op *=(Decimal, i64); +op /=(Decimal, i64); +op %=(Decimal, i64); +op **=(Decimal, i64); + +op +=(String, String); +op -=(String, String); +op +=(String, char); +op -=(String, char); +op +=(char, String); +op +=(char, char); + +op +=(arraArray, item: Array); +op +=(arraArray, item: ?); + +op +=(Blob, Blob); +op +=(Blob, value: i64); +op +=(Blob, char); +op +=(Blob, String); diff --git a/src/definitions/builtin.d.rhai b/src/definitions/builtin.d.rhai new file mode 100644 index 00000000..2e08fa44 --- /dev/null +++ b/src/definitions/builtin.d.rhai @@ -0,0 +1,170 @@ +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: i64) -> 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) -> ?; + +fn contains(string: String, find: String) -> bool; +fn contains(range: Range, value: i64) -> bool; +fn contains(range: RangeInclusive, value: i64) -> bool; +fn contains(map: Map, string: String) -> bool; +fn contains(blob: Blob, value: i64) -> bool; +fn contains(string: String, ch: char) -> bool; diff --git a/src/definitions.rs b/src/definitions/mod.rs similarity index 97% rename from src/definitions.rs rename to src/definitions/mod.rs index ef58a146..1b1842ce 100644 --- a/src/definitions.rs +++ b/src/definitions/mod.rs @@ -86,6 +86,9 @@ impl<'e> Definitions<'e> { fs::create_dir_all(path)?; + fs::write(path.join("__builtin__.d.rhai"), include_bytes!("builtin.d.rhai"))?; + fs::write(path.join("__builtin-operators__.d.rhai"), include_bytes!("builtin-operators.d.rhai"))?; + fs::write(path.join("__static__.d.rhai"), self.static_module())?; if self.scope.is_some() { From b00bf8535d58cc8bad4729f82785024a921e6d33 Mon Sep 17 00:00:00 2001 From: tamasfe Date: Tue, 26 Jul 2022 13:55:10 +0200 Subject: [PATCH 04/11] fix(defs): conditional compilation and refactors --- .../definitions/builtin-operators.d.rhai | 0 src/{ => api}/definitions/builtin.d.rhai | 0 src/{ => api}/definitions/mod.rs | 31 ++++++++++++------- src/api/mod.rs | 3 ++ src/lib.rs | 9 +++--- 5 files changed, 27 insertions(+), 16 deletions(-) rename src/{ => api}/definitions/builtin-operators.d.rhai (100%) rename src/{ => api}/definitions/builtin.d.rhai (100%) rename src/{ => api}/definitions/mod.rs (91%) diff --git a/src/definitions/builtin-operators.d.rhai b/src/api/definitions/builtin-operators.d.rhai similarity index 100% rename from src/definitions/builtin-operators.d.rhai rename to src/api/definitions/builtin-operators.d.rhai diff --git a/src/definitions/builtin.d.rhai b/src/api/definitions/builtin.d.rhai similarity index 100% rename from src/definitions/builtin.d.rhai rename to src/api/definitions/builtin.d.rhai diff --git a/src/definitions/mod.rs b/src/api/definitions/mod.rs similarity index 91% rename from src/definitions/mod.rs rename to src/api/definitions/mod.rs index 1b1842ce..ee8a5cc2 100644 --- a/src/definitions/mod.rs +++ b/src/api/definitions/mod.rs @@ -4,10 +4,10 @@ use crate::{ use core::fmt; #[cfg(feature = "no_std")] -use alloc::borrow::Cow; +use std::prelude::v1::*; #[cfg(feature = "no_std")] -use alloc::string::String; +use alloc::borrow::Cow; #[cfg(not(feature = "no_std"))] use std::borrow::Cow; @@ -86,8 +86,14 @@ impl<'e> Definitions<'e> { fs::create_dir_all(path)?; - fs::write(path.join("__builtin__.d.rhai"), include_bytes!("builtin.d.rhai"))?; - fs::write(path.join("__builtin-operators__.d.rhai"), include_bytes!("builtin-operators.d.rhai"))?; + fs::write( + path.join("__builtin__.d.rhai"), + include_bytes!("builtin.d.rhai"), + )?; + fs::write( + path.join("__builtin-operators__.d.rhai"), + include_bytes!("builtin-operators.d.rhai"), + )?; fs::write(path.join("__static__.d.rhai"), self.static_module())?; @@ -95,6 +101,7 @@ impl<'e> Definitions<'e> { fs::write(path.join("__scope__.d.rhai"), self.scope())?; } + #[cfg(not(feature = "no_module"))] for (name, decl) in self.modules() { fs::write(path.join(format!("{name}.d.rhai")), decl)?; } @@ -196,13 +203,15 @@ impl Module { continue; } - f.write_definition( - writer, - def, - def.engine.custom_keywords.contains_key(&f.metadata.name) - || (!f.metadata.name.contains('$') - && !is_valid_function_name(&f.metadata.name)), - )?; + #[cfg(not(feature = "no_custom_syntax"))] + let operator = def.engine.custom_keywords.contains_key(&f.metadata.name) + || (!f.metadata.name.contains('$') && !is_valid_function_name(&f.metadata.name)); + + #[cfg(feature = "no_custom_syntax")] + let operator = + !f.metadata.name.contains('$') && !is_valid_function_name(&f.metadata.name); + + f.write_definition(writer, def, operator)?; } Ok(()) diff --git a/src/api/mod.rs b/src/api/mod.rs index 4f5e96e1..f24777c6 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -28,6 +28,9 @@ pub mod custom_syntax; pub mod deprecated; +#[cfg(feature = "metadata")] +pub mod definitions; + use crate::{Dynamic, Engine, Identifier}; #[cfg(not(feature = "no_custom_syntax"))] diff --git a/src/lib.rs b/src/lib.rs index cc3b6d7d..dcf1aa88 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -82,8 +82,6 @@ mod reify; mod tests; mod tokenizer; mod types; -#[cfg(feature = "metadata")] -mod definitions; /// Error encountered when parsing a script. type PERR = ParseErrorType; @@ -183,6 +181,10 @@ pub use types::{ #[cfg(not(feature = "no_custom_syntax"))] pub use api::custom_syntax::Expression; + +#[cfg(feature = "metadata")] +pub use api::definitions::Definitions; + /// _(debugging)_ Module containing types for debugging. /// Exported under the `debugging` feature only. #[cfg(feature = "debugging")] @@ -260,9 +262,6 @@ pub mod serde; #[cfg(not(feature = "no_optimize"))] pub use optimizer::OptimizationLevel; -#[cfg(feature = "metadata")] -pub use definitions::Definitions; - /// Placeholder for the optimization level. #[cfg(feature = "no_optimize")] pub type OptimizationLevel = (); From fdbe837a5d52a38ea73863f3de0816f072aab24a Mon Sep 17 00:00:00 2001 From: tamasfe Date: Tue, 26 Jul 2022 14:16:54 +0200 Subject: [PATCH 05/11] feat(defs): iter_files and small fixes --- src/api/definitions/builtin-operators.d.rhai | 6 +-- src/api/definitions/mod.rs | 47 ++++++++++++++++---- 2 files changed, 41 insertions(+), 12 deletions(-) diff --git a/src/api/definitions/builtin-operators.d.rhai b/src/api/definitions/builtin-operators.d.rhai index d907afcf..51bdb0e2 100644 --- a/src/api/definitions/builtin-operators.d.rhai +++ b/src/api/definitions/builtin-operators.d.rhai @@ -242,10 +242,10 @@ op -=(String, char); op +=(char, String); op +=(char, char); -op +=(arraArray, item: Array); -op +=(arraArray, item: ?); +op +=(arraArray, Array); +op +=(arraArray, ?); op +=(Blob, Blob); -op +=(Blob, value: i64); +op +=(Blob, i64); op +=(Blob, char); op +=(Blob, String); diff --git a/src/api/definitions/mod.rs b/src/api/definitions/mod.rs index ee8a5cc2..c983dc18 100644 --- a/src/api/definitions/mod.rs +++ b/src/api/definitions/mod.rs @@ -1,7 +1,7 @@ use crate::{ module::FuncInfo, plugin::*, tokenizer::is_valid_function_name, Engine, Module, Scope, }; -use core::fmt; +use core::{fmt, iter}; #[cfg(feature = "no_std")] use std::prelude::v1::*; @@ -71,13 +71,10 @@ pub struct Definitions<'e> { } impl<'e> Definitions<'e> { - /// Write all the definition files to a directory. + /// Write all the definition files returned from [`iter_files`] to a directory. /// - /// The following separate definition files are generated: - /// - /// - `__static__.d.rhai`: globally available items of the engine - /// - `__scope__.d.rhai`: items in the given scope, if any - /// - a separate file for each registered module + /// This function will create the directory path if it does not yet exist, + /// it will also override any existing files as needed. #[cfg(not(feature = "no_std"))] pub fn write_to_dir(&self, path: impl AsRef) -> std::io::Result<()> { use std::fs; @@ -101,7 +98,6 @@ impl<'e> Definitions<'e> { fs::write(path.join("__scope__.d.rhai"), self.scope())?; } - #[cfg(not(feature = "no_module"))] for (name, decl) in self.modules() { fs::write(path.join(format!("{name}.d.rhai")), decl)?; } @@ -109,6 +105,34 @@ impl<'e> Definitions<'e> { Ok(()) } + /// Iterate over the generated definition files. + /// + /// The returned iterator yields all the definition files as (filename, content) pairs. + pub fn iter_files(&self) -> impl Iterator + '_ { + IntoIterator::into_iter([ + ( + "__builtin__.d.rhai".to_string(), + include_str!("builtin.d.rhai").to_string(), + ), + ( + "__builtin-operators__.d.rhai".to_string(), + include_str!("builtin-operators.d.rhai").to_string(), + ), + ("__static__.d.rhai".to_string(), self.static_module()), + ]) + .chain(iter::from_fn(move || { + if self.scope.is_some() { + Some(("__scope__.d.rhai".to_string(), self.scope())) + } else { + None + } + })) + .chain( + self.modules() + .map(|(name, def)| (format!("{name}.d.rhai"), def)), + ) + } + /// Return the definitions for the globally available /// items of the engine. /// @@ -148,8 +172,10 @@ impl<'e> Definitions<'e> { /// Return name and definition pairs for each registered module. /// /// The definitions will always start with `module ;`. - #[cfg(not(feature = "no_module"))] + /// + /// If the feature `no_module` is enabled, this will yield no elements. pub fn modules(&self) -> impl Iterator + '_ { + #[cfg(not(feature = "no_module"))] let mut m = self .engine .global_sub_modules @@ -162,6 +188,9 @@ impl<'e> Definitions<'e> { }) .collect::>(); + #[cfg(feature = "no_module")] + let mut m = Vec::new(); + m.sort_by(|(name1, _), (name2, _)| name1.cmp(name2)); m.into_iter() From d350462cf838118875b063182c5f322ab7231032 Mon Sep 17 00:00:00 2001 From: tamasfe Date: Tue, 26 Jul 2022 14:18:43 +0200 Subject: [PATCH 06/11] chore: formatting --- src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index dcf1aa88..51e260f0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -181,7 +181,6 @@ pub use types::{ #[cfg(not(feature = "no_custom_syntax"))] pub use api::custom_syntax::Expression; - #[cfg(feature = "metadata")] pub use api::definitions::Definitions; From ade818b043f4e3cfcaebe521fd8d5d22e134803b Mon Sep 17 00:00:00 2001 From: tamasfe Date: Tue, 26 Jul 2022 14:28:54 +0200 Subject: [PATCH 07/11] fix(defs): compile errors --- examples/definitions/main.rs | 8 ++++++-- src/api/definitions/mod.rs | 33 ++++++++++++++++++--------------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/examples/definitions/main.rs b/examples/definitions/main.rs index 0638f8e8..f83ac4fd 100644 --- a/examples/definitions/main.rs +++ b/examples/definitions/main.rs @@ -18,11 +18,15 @@ fn main() { // since it will be part of the scope. scope.push("hello_there", "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. - engine.register_custom_operator("minus", 100).unwrap(); - engine.register_fn("minus", |a: i64, b: i64| a - b); + #[cfg(not(feature = "no_custom_syntax"))] + { + engine.register_custom_operator("minus", 100).unwrap(); + engine.register_fn("minus", |a: i64, b: i64| a - b); + } engine .eval_with_scope::<()>( diff --git a/src/api/definitions/mod.rs b/src/api/definitions/mod.rs index c983dc18..94e600a5 100644 --- a/src/api/definitions/mod.rs +++ b/src/api/definitions/mod.rs @@ -169,29 +169,32 @@ impl<'e> Definitions<'e> { s } - /// Return name and definition pairs for each registered module. + /// Return module name and definition pairs for each registered module. /// /// The definitions will always start with `module ;`. /// /// If the feature `no_module` is enabled, this will yield no elements. pub fn modules(&self) -> impl Iterator + '_ { #[cfg(not(feature = "no_module"))] - let mut m = self - .engine - .global_sub_modules - .iter() - .map(move |(name, module)| { - ( - name.to_string(), - format!("module {name};\n\n{}", module.definition(self)), - ) - }) - .collect::>(); + let m = { + let mut m = self + .engine + .global_sub_modules + .iter() + .map(move |(name, module)| { + ( + name.to_string(), + format!("module {name};\n\n{}", module.definition(self)), + ) + }) + .collect::>(); + + m.sort_by(|(name1, _), (name2, _)| name1.cmp(name2)); + m + }; #[cfg(feature = "no_module")] - let mut m = Vec::new(); - - m.sort_by(|(name1, _), (name2, _)| name1.cmp(name2)); + let m = Vec::new(); m.into_iter() } From 6d4b5095d2a551a6d1bd47e2c0e2390b7190e55f Mon Sep 17 00:00:00 2001 From: tamasfe Date: Tue, 26 Jul 2022 14:42:30 +0200 Subject: [PATCH 08/11] feat(defs): deterministic function ordering --- .../definitions/__builtin-operators__.d.rhai | 6 +- .../.rhai/definitions/__static__.d.rhai | 3810 ++++++++--------- src/api/definitions/mod.rs | 12 +- 3 files changed, 1918 insertions(+), 1910 deletions(-) diff --git a/examples/definitions/.rhai/definitions/__builtin-operators__.d.rhai b/examples/definitions/.rhai/definitions/__builtin-operators__.d.rhai index d907afcf..51bdb0e2 100644 --- a/examples/definitions/.rhai/definitions/__builtin-operators__.d.rhai +++ b/examples/definitions/.rhai/definitions/__builtin-operators__.d.rhai @@ -242,10 +242,10 @@ op -=(String, char); op +=(char, String); op +=(char, char); -op +=(arraArray, item: Array); -op +=(arraArray, item: ?); +op +=(arraArray, Array); +op +=(arraArray, ?); op +=(Blob, Blob); -op +=(Blob, value: i64); +op +=(Blob, i64); op +=(Blob, char); op +=(Blob, String); diff --git a/examples/definitions/.rhai/definitions/__static__.d.rhai b/examples/definitions/.rhai/definitions/__static__.d.rhai index c422f26a..6dbd4594 100644 --- a/examples/definitions/.rhai/definitions/__static__.d.rhai +++ b/examples/definitions/.rhai/definitions/__static__.d.rhai @@ -4,36 +4,7 @@ op minus(i64, i64) -> i64; op !(bool) -> bool; -/// Return `true` if two timestamps are not equal. -op !=(Instant, Instant) -> bool; - -op !=(f32, int) -> bool; - -op !=(f32, f32) -> bool; - -op !=(f64, int) -> bool; - -op !=(u16, u16) -> 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; - -op !=(int, f64) -> bool; +op !=(i16, i16) -> bool; /// Return `true` if two object maps are not equal (i.e. at least one property value is not equal). /// @@ -53,150 +24,171 @@ op !=(int, f64) -> bool; /// ``` op !=(Map, Map) -> bool; -op !=(u32, u32) -> bool; - -op !=(u128, u128) -> bool; - -op !=(i8, i8) -> bool; - -op !=(u64, u64) -> bool; - -op !=(i128, i128) -> bool; +/// Return `true` if two timestamps are not equal. +op !=(Instant, Instant) -> bool; op !=(u8, u8) -> bool; -op !=(i16, i16) -> bool; +op !=(u32, u32) -> 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; + +op !=(f32, f32) -> bool; + +op !=(f64, int) -> bool; + +op !=(u16, u16) -> bool; + +op !=(int, f64) -> bool; op !=(i32, i32) -> bool; +op !=(u64, u64) -> bool; + +op !=(f32, int) -> bool; + +op !=(i128, i128) -> bool; + +op !=(i8, i8) -> bool; + op !=(int, f32) -> bool; -op %(int, f32) -> f32; - -op %(i128, i128) -> i128; - -op %(u64, u64) -> u64; - -op %(u8, u8) -> u8; - -op %(i16, i16) -> i16; - -op %(i32, i32) -> i32; - -op %(f32, int) -> f32; - -op %(u16, u16) -> u16; +op !=(u128, u128) -> bool; op %(f32, f32) -> f32; -op %(u128, u128) -> u128; +op %(u16, u16) -> u16; -op %(u32, u32) -> u32; +op %(i32, i32) -> i32; + +op %(u64, u64) -> u64; + +op %(f32, int) -> f32; + +op %(i128, i128) -> i128; op %(i8, i8) -> i8; -op &(i8, i8) -> i8; +op %(int, f32) -> f32; -op &(u128, u128) -> u128; +op %(u128, u128) -> u128; -op &(u32, u32) -> u32; +op %(i16, i16) -> i16; + +op %(u8, u8) -> u8; + +op %(u32, u32) -> u32; op &(u16, u16) -> u16; -op &(i16, i16) -> i16; - op &(i32, i32) -> i32; op &(u64, u64) -> u64; op &(i128, i128) -> i128; +op &(i8, i8) -> i8; + +op &(u128, u128) -> u128; + +op &(i16, i16) -> i16; + op &(u8, u8) -> u8; -op *(u16, u16) -> u16; - -op *(f32, f32) -> f32; - -op *(f32, int) -> f32; +op &(u32, u32) -> u32; op *(i8, i8) -> i8; -op *(u128, u128) -> u128; - -op *(u32, u32) -> u32; - -op *(u8, u8) -> u8; - op *(i128, i128) -> i128; -op *(u64, u64) -> u64; - -op *(i32, i32) -> i32; - -op *(i16, i16) -> i16; - op *(int, f32) -> f32; -op **(u8, int) -> u8; +op *(u128, u128) -> u128; -op **(i16, int) -> i16; +op *(f32, f32) -> f32; -op **(i128, int) -> i128; +op *(u64, u64) -> u64; -op **(f32, int) -> f32; +op *(f32, int) -> f32; + +op *(i32, i32) -> i32; + +op *(u16, u16) -> u16; + +op *(u32, u32) -> u32; + +op *(i16, i16) -> i16; + +op *(u8, u8) -> u8; + +op **(i8, int) -> i8; op **(f32, f32) -> f32; +op **(f32, int) -> f32; + op **(u16, int) -> u16; -op **(i8, int) -> i8; +op **(i16, int) -> i16; + +op **(u8, int) -> u8; + +op **(u64, int) -> u64; + +op **(u128, int) -> u128; op **(i32, int) -> i32; op **(u32, int) -> u32; -op **(u128, int) -> u128; - -op **(u64, int) -> u64; - -op +(i128) -> i128; - -/// 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 +(i8) -> i8; - -op +(String, ()) -> String; - -op +(u16, u16) -> u16; - -op +(f32, f32) -> f32; - -op +(f32, int) -> f32; - -op +(i8, i8) -> i8; +op **(i128, int) -> i128; op +(int) -> i64; -op +(u128, u128) -> u128; +op +(i128) -> i128; + +op +(i16) -> i16; + +op +(i8) -> i8; + +op +(f32) -> f32; + +op +(f64) -> f64; + +op +(i32) -> i32; op +(u32, u32) -> u32; -/// Add the specified number of `seconds` to the timestamp and return it as a new timestamp. -op +(Instant, int) -> Instant; +op +(char, String) -> String; -op +(i32) -> i32; +op +((), String) -> String; + +/// Add the specified number of `seconds` to the timestamp and return it as a new timestamp. +op +(Instant, float) -> Instant; + +op +(u8, u8) -> u8; + +op +(?, String) -> String; + +op +(String, ?) -> String; + +op +(i16, i16) -> i16; /// 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. @@ -215,43 +207,53 @@ op +(Map, Map) -> Map; op +(String, char) -> String; -op +(u8, u8) -> u8; +op +(int, f32) -> f32; /// Add the specified number of `seconds` to the timestamp and return it as a new timestamp. -op +(Instant, float) -> Instant; +op +(Instant, int) -> Instant; -op +(String, ?) -> String; +op +(u128, u128) -> u128; -op +(Blob, String) -> String; +op +(String, ()) -> String; op +(i128, i128) -> i128; -op +(u64, u64) -> u64; +op +(String, String) -> String; -op +(f32) -> f32; +op +(i8, i8) -> i8; + +op +(Blob, String) -> String; op +(String, Blob) -> String; +op +(u16, u16) -> u16; + op +(i32, i32) -> i32; -op +((), String) -> String; +op +(f32, int) -> f32; -op +(f64) -> f64; +op +(u64, u64) -> u64; -op +(i16) -> i16; +/// 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 +(?, String) -> String; - -op +(i16, i16) -> i16; - -op +(int, f32) -> f32; - -op +(String, String) -> String; - -op +(char, String) -> String; +op +(f32, f32) -> f32; /// Add the specified number of `seconds` to the timestamp. -op +=(Instant, int) -> (); +op +=(Instant, float) -> (); + +op +=(String, ?) -> (); /// Add all property values of another object map into the object map. /// Existing property values of the same names are replaced. @@ -269,183 +271,176 @@ op +=(Instant, int) -> (); op +=(Map, Map) -> (); /// Add the specified number of `seconds` to the timestamp. -op +=(Instant, float) -> (); - -op +=(String, ?) -> (); +op +=(Instant, int) -> (); op +=(String, Blob) -> (); -op -(f32, f32) -> f32; - -op -(u16, u16) -> u16; - -op -(f32, int) -> f32; - -op -(i8, i8) -> i8; - -/// Subtract the specified number of `seconds` from the timestamp and return it as a new timestamp. -op -(Instant, int) -> Instant; - -op -(u32, u32) -> u32; - -op -(u128, u128) -> u128; +op -(int) -> int; op -(i128) -> i128; -op -(i32) -> i32; +op -(i16) -> i16; -op -(int) -> int; +op -(f32) -> f32; op -(i8) -> i8; -/// Return the number of seconds between two timestamps. -op -(Instant, Instant) -> RhaiResult; - -op -(int, f32) -> f32; - -op -(i16) -> i16; +op -(i32) -> i32; op -(f64) -> f64; -op -(f32) -> f32; +op -(u32, u32) -> u32; /// Subtract the specified number of `seconds` from the timestamp and return it as a new timestamp. op -(Instant, float) -> Instant; +op -(i16, i16) -> i16; + +/// Return the number of seconds between two timestamps. +op -(Instant, Instant) -> RhaiResult; + op -(u8, u8) -> u8; -op -(u64, u64) -> u64; +op -(i8, i8) -> i8; op -(i128, i128) -> i128; +op -(int, f32) -> f32; + +op -(u128, u128) -> u128; + +/// Subtract the specified number of `seconds` from the timestamp and return it as a new timestamp. +op -(Instant, int) -> Instant; + +op -(f32, f32) -> f32; + +op -(u64, u64) -> u64; + +op -(f32, int) -> f32; + op -(i32, i32) -> i32; -op -(i16, i16) -> i16; - -/// Subtract the specified number of `seconds` from the timestamp. -op -=(Instant, int) -> (); +op -(u16, u16) -> u16; /// Subtract the specified number of `seconds` from the timestamp. op -=(Instant, float) -> (); -op /(f32, int) -> f32; - -op /(u16, u16) -> u16; - -op /(f32, f32) -> f32; - -op /(u32, u32) -> u32; - -op /(u128, u128) -> u128; - -op /(i8, i8) -> i8; - -op /(int, f32) -> f32; - -op /(i128, i128) -> i128; - -op /(u64, u64) -> u64; +/// Subtract the specified number of `seconds` from the timestamp. +op -=(Instant, int) -> (); op /(u8, u8) -> u8; op /(i16, i16) -> i16; +op /(u32, u32) -> u32; + op /(i32, i32) -> i32; -op <(int, f64) -> bool; +op /(u16, u16) -> u16; -op <(u32, u32) -> bool; +op /(f32, int) -> f32; -op <(u128, u128) -> bool; +op /(u64, u64) -> u64; -op <(i8, i8) -> bool; +op /(f32, f32) -> f32; -op <(f32, int) -> bool; +op /(u128, u128) -> u128; + +op /(int, f32) -> f32; + +op /(i128, i128) -> i128; + +op /(i8, i8) -> i8; op <(f32, f32) -> bool; -op <(f64, int) -> bool; - op <(u16, u16) -> bool; -/// Return `true` if the first timestamp is earlier than the second. -op <(Instant, Instant) -> bool; - -op <(int, f32) -> bool; - -op <(i16, i16) -> bool; +op <(int, f64) -> bool; op <(i32, i32) -> bool; op <(u64, u64) -> bool; +op <(f32, int) -> bool; + +op <(f64, int) -> bool; + op <(i128, i128) -> bool; +op <(i8, i8) -> bool; + +op <(u128, u128) -> bool; + +op <(int, f32) -> bool; + +/// Return `true` if the first timestamp is earlier than the second. +op <(Instant, Instant) -> bool; + +op <(i16, i16) -> bool; + op <(u8, u8) -> bool; -op <<(u16, int) -> u16; - -op <<(i8, int) -> i8; - -op <<(u8, int) -> u8; - -op <<(i16, int) -> i16; +op <(u32, u32) -> bool; op <<(i128, int) -> i128; +op <<(u32, int) -> u32; + +op <<(i32, int) -> i32; + op <<(u128, int) -> u128; op <<(u64, int) -> u64; -op <<(i32, int) -> i32; +op <<(i16, int) -> i16; -op <<(u32, int) -> u32; +op <<(u16, int) -> u16; + +op <<(u8, int) -> u8; + +op <<(i8, int) -> i8; + +op <=(u128, u128) -> bool; op <=(int, f32) -> bool; +op <=(i8, i8) -> bool; + op <=(i128, i128) -> bool; op <=(u64, u64) -> bool; -op <=(u8, u8) -> bool; - -op <=(i16, i16) -> bool; - -op <=(i32, i32) -> bool; - op <=(f32, int) -> bool; op <=(u16, u16) -> bool; +op <=(int, f64) -> bool; + +op <=(i32, i32) -> bool; + op <=(f64, int) -> bool; op <=(f32, f32) -> bool; -op <=(int, f64) -> bool; - -op <=(i8, i8) -> bool; - -op <=(u128, u128) -> bool; - op <=(u32, u32) -> bool; +op <=(u8, u8) -> bool; + /// Return `true` if the first timestamp is earlier than or equals to the second. op <=(Instant, Instant) -> bool; -op ==(u8, u8) -> bool; - -op ==(u64, u64) -> bool; +op <=(i16, i16) -> bool; op ==(i128, i128) -> bool; -op ==(i32, i32) -> bool; +op ==(i8, i8) -> bool; -op ==(i16, i16) -> bool; +op ==(u128, u128) -> bool; op ==(int, f32) -> bool; -/// Return `true` if two timestamps are equal. -op ==(Instant, Instant) -> bool; +op ==(f32, f32) -> bool; /// Return `true` if two arrays are equal (i.e. all elements are equal and in the same order). /// @@ -465,20 +460,23 @@ op ==(Instant, Instant) -> bool; /// ``` op ==(Array, Array) -> bool; -op ==(f32, f32) -> bool; +op ==(i32, i32) -> bool; op ==(u16, u16) -> bool; -op ==(f64, int) -> bool; +op ==(int, f64) -> bool; + +op ==(u64, u64) -> bool; op ==(f32, int) -> bool; -op ==(i8, i8) -> bool; - -op ==(u128, u128) -> bool; +op ==(f64, int) -> bool; op ==(u32, u32) -> bool; +/// Return `true` if two timestamps are equal. +op ==(Instant, Instant) -> 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, @@ -497,85 +495,87 @@ op ==(u32, u32) -> bool; /// ``` op ==(Map, Map) -> bool; -op ==(int, f64) -> bool; +op ==(i16, i16) -> bool; -/// Return `true` if the first timestamp is later than the second. -op >(Instant, Instant) -> bool; +op ==(u8, u8) -> bool; -op >(f32, int) -> bool; - -op >(f32, f32) -> bool; - -op >(u16, u16) -> bool; - -op >(f64, int) -> bool; - -op >(int, f64) -> bool; - -op >(i8, i8) -> bool; +op >(int, f32) -> bool; op >(u128, u128) -> bool; -op >(u32, u32) -> bool; +op >(i128, i128) -> bool; + +op >(i8, i8) -> bool; + +op >(f64, int) -> bool; + +op >(i32, i32) -> bool; + +op >(int, f64) -> bool; + +op >(u16, u16) -> bool; + +op >(f32, int) -> bool; op >(u64, u64) -> bool; -op >(i128, i128) -> bool; +op >(f32, f32) -> bool; + +op >(u32, u32) -> bool; op >(u8, u8) -> bool; op >(i16, i16) -> bool; -op >(i32, i32) -> bool; - -op >(int, f32) -> bool; - -op >=(int, f32) -> bool; - -op >=(i16, i16) -> bool; - -op >=(i32, i32) -> bool; - -op >=(u64, u64) -> bool; - -op >=(i128, i128) -> bool; +/// Return `true` if the first timestamp is later than the second. +op >(Instant, Instant) -> bool; op >=(u8, u8) -> bool; -op >=(int, f64) -> bool; - -op >=(i8, i8) -> bool; - -op >=(u128, u128) -> bool; - -op >=(u32, u32) -> bool; - -op >=(f32, int) -> bool; - -op >=(f32, f32) -> bool; - -op >=(u16, u16) -> bool; - -op >=(f64, int) -> bool; +op >=(i16, i16) -> bool; /// Return `true` if the first timestamp is later than or equals to the second. op >=(Instant, Instant) -> bool; -op >>(u8, int) -> u8; +op >=(u32, u32) -> bool; -op >>(i16, int) -> i16; +op >=(f64, int) -> bool; -op >>(i128, int) -> i128; +op >=(f32, int) -> bool; -op >>(u16, int) -> u16; +op >=(u64, u64) -> bool; -op >>(i8, int) -> i8; +op >=(int, f64) -> bool; + +op >=(u16, u16) -> bool; + +op >=(i32, i32) -> bool; + +op >=(f32, f32) -> bool; + +op >=(int, f32) -> bool; + +op >=(u128, u128) -> bool; + +op >=(i8, i8) -> bool; + +op >=(i128, i128) -> bool; + +op >>(u128, int) -> u128; op >>(i32, int) -> i32; op >>(u32, int) -> u32; -op >>(u128, int) -> u128; +op >>(i128, int) -> i128; + +op >>(i8, int) -> i8; + +op >>(i16, int) -> i16; + +op >>(u16, int) -> u16; + +op >>(u8, int) -> u8; op >>(u64, int) -> u64; @@ -585,71 +585,51 @@ fn E() -> f64; /// Return the number π. fn PI() -> f64; -op ^(i8, i8) -> i8; - -op ^(u32, u32) -> u32; - op ^(u128, u128) -> u128; -op ^(u16, u16) -> u16; - -op ^(i32, i32) -> i32; - -op ^(i16, i16) -> i16; - -op ^(u8, u8) -> u8; - -op ^(u64, u64) -> u64; - op ^(i128, i128) -> i128; -/// Return the absolute value of the floating-point number. -fn abs(x: f32) -> f32; +op ^(i8, i8) -> i8; + +op ^(i32, i32) -> i32; + +op ^(u16, u16) -> u16; + +op ^(u64, u64) -> u64; + +op ^(u32, u32) -> u32; + +op ^(u8, u8) -> u8; + +op ^(i16, i16) -> i16; /// Return the absolute value of the number. -fn abs(x: i16) -> i16; - -/// Return the absolute value of the floating-point number. -fn abs(x: f64) -> f64; +fn abs(x: int) -> int; /// 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 floating-point number. +fn abs(x: f32) -> f32; + /// Return the absolute value of the number. fn abs(x: i8) -> i8; +/// Return the absolute value of the floating-point number. +fn abs(x: f64) -> f64; + /// Return the absolute value of the number. fn abs(x: i32) -> i32; -/// Return the absolute value of the number. -fn abs(x: int) -> int; - /// Return the arc-cosine of the floating-point number, in radians. fn acos(x: float) -> f64; /// Return the arc-hyperbolic-cosine of the floating-point number, in radians. fn acosh(x: float) -> f64; -/// 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; - /// Return `true` if all elements in the array return `true` when applied a function named by `filter`. /// /// # Function Parameters @@ -672,18 +652,25 @@ fn all(array: Array, filter: FnPtr) -> bool; /// ``` fn all(array: Array, filter: String) -> bool; -/// Add a character (as UTF-8 encoded byte-stream) to the end of the BLOB +/// 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 b = blob(5, 0x42); +/// let x = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 5]; /// -/// b.append('!'); +/// print(x.all(|v| v > 3)); // prints false /// -/// print(b); // prints "[424242424221]" +/// print(x.all(|v| v > 1)); // prints true +/// +/// print(x.all(|v, i| i > v)); // prints false /// ``` -fn append(blob: Blob, character: char) -> (); +fn all(array: Array, filter: FnPtr) -> bool; /// Add another BLOB to the end of the BLOB. /// @@ -699,19 +686,7 @@ fn append(blob: Blob, character: char) -> (); /// ``` fn append(blob1: Blob, blob2: Blob) -> (); -/// 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.push(y); -/// -/// print(x); // prints "[1, 2, 3, true, 'x']" -/// ``` -fn append(array: Array, new_array: Array) -> (); +fn append(string: String, item: ?) -> (); /// Add a new byte `value` to the end of the BLOB. /// @@ -728,7 +703,32 @@ fn append(array: Array, new_array: Array) -> (); /// ``` fn append(blob: Blob, value: int) -> (); -fn append(string: String, utf8: Blob) -> (); +/// 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.push(y); +/// +/// print(x); // prints "[1, 2, 3, true, 'x']" +/// ``` +fn append(array: Array, new_array: Array) -> (); + +/// 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 /// @@ -743,7 +743,7 @@ fn append(string: String, utf8: Blob) -> (); /// ``` fn append(blob: Blob, string: String) -> (); -fn append(string: String, item: ?) -> (); +fn append(string: String, utf8: Blob) -> (); /// Convert the BLOB into a string. /// @@ -766,28 +766,15 @@ fn asin(x: float) -> f64; /// Return the arc-hyperbolic-sine of the floating-point number, in radians. fn asinh(x: float) -> f64; -/// Return the arc-tangent of the floating-point numbers `x` and `y`, in radians. -fn atan(x: float, y: float) -> f64; - /// Return the arc-tangent of the floating-point number, in radians. fn atan(x: float) -> f64; +/// Return the arc-tangent of the floating-point numbers `x` and `y`, in radians. +fn atan(x: float, y: float) -> f64; + /// Return the arc-hyperbolic-tangent of the floating-point number, in radians. fn atanh(x: float) -> f64; -/// 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 all the bits in the number. /// /// # Example @@ -801,6 +788,19 @@ fn bits(value: int, range: RangeInclusive) -> Iterator; /// ``` fn bits(value: int) -> 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 an exclusive range of bits in the number. /// /// # Example @@ -814,6 +814,21 @@ fn bits(value: int) -> Iterator; /// ``` fn bits(value: int, range: Range) -> 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 a portion of bits in the number. /// /// * If `start` < 0, position counts from the MSB (Most Significant Bit)>. @@ -831,20 +846,21 @@ fn bits(value: int, range: Range) -> Iterator; /// ``` fn bits(value: int, from: int, len: int) -> Iterator; -/// Return an iterator over the bits in the number starting from the specified `start` position. +/// Return a new, empty BLOB. +fn blob() -> Blob; + +/// Return a new BLOB of the specified length, filled with zeros. /// -/// If `start` < 0, position counts from the MSB (Most Significant Bit)>. +/// If `len` ≤ 0, an empty BLOB is returned. /// /// # Example /// /// ```rhai -/// let x = 123456; +/// let b = blob(10); /// -/// for bit in x.bits(10) { -/// print(bit); -/// } +/// print(b); // prints "[0000000000000000 0000]" /// ``` -fn bits(value: int, from: int) -> Iterator; +fn blob(len: int) -> Blob; /// Return a new BLOB of the specified length, filled with copies of the initial `value`. /// @@ -861,22 +877,6 @@ fn bits(value: int, from: int) -> Iterator; /// ``` fn blob(len: int, value: int) -> 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, empty BLOB. -fn blob() -> Blob; - /// Return the length of the string, in number of bytes used to store it in UTF-8 encoding. /// /// # Example @@ -891,6 +891,17 @@ fn bytes(string: String) -> i64; /// Return the smallest whole number larger than or equals to the floating-point number. fn ceiling(x: float) -> f64; +/// 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). @@ -906,16 +917,16 @@ fn ceiling(x: float) -> f64; /// ``` fn chars(string: String, from: int) -> Iterator; -/// Return an iterator over the characters in the string. +/// Return an iterator over an inclusive range of characters in the string. /// /// # Example /// /// ```rhai -/// for ch in "hello, world!".chars() { +/// for ch in "hello, world!".chars(2..=6) { /// print(ch); /// } /// ``` -fn chars(string: String) -> Iterator; +fn chars(string: String, range: RangeInclusive) -> Iterator; /// Return an iterator over an exclusive range of characters in the string. /// @@ -945,17 +956,6 @@ fn chars(string: String, range: Range) -> Iterator; /// ``` fn chars(string: String, start: int, len: int) -> 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; - /// Cut off the head of the array, leaving a tail of the specified length. /// /// * If `len` ≤ 0, the array is cleared. @@ -1001,15 +1001,15 @@ fn chop(blob: Blob, len: int) -> (); /// Clear the string, making it empty. fn clear(string: String) -> (); -/// Clear the object map. -fn clear(map: Map) -> (); - /// Clear the BLOB. fn clear(blob: Blob) -> (); /// Clear the array. fn clear(array: Array) -> (); +/// Clear the object map. +fn clear(map: Map) -> (); + /// Return `true` if the array contains an element that equals `value`. /// /// The operator `==` is used to compare elements with `value` and must be defined, @@ -1035,6 +1035,53 @@ fn cos(x: float) -> f64; /// Return the hyperbolic cosine of the floating-point number in radians. fn cosh(x: float) -> f64; +/// 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 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 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 a range. /// /// * If `start` < 0, position counts from the end of the string (`-1` is the last character). @@ -1058,111 +1105,39 @@ fn cosh(x: float) -> f64; /// ``` fn crop(string: String, start: int, len: int) -> (); -/// 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 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) -> (); - -/// Convert the array into a string. -fn debug(array: Array) -> String; - /// Return the empty string. fn debug() -> String; -/// Convert the unit into a string in debug format. -fn debug(unit: ()) -> String; - -/// Convert the value of `number` into a string. -fn debug(number: f64) -> String; - /// Convert the object map into a string. fn debug(map: Map) -> String; -/// Convert the value of `number` into a string. -fn debug(number: f32) -> String; - -/// Convert the string into debug format. -fn debug(character: char) -> String; +/// Convert the unit into a string in debug format. +fn debug(unit: ()) -> String; /// Convert the function pointer into a string in debug format. fn debug(f: FnPtr) -> String; -/// Convert the string into debug format. -fn debug(string: String) -> String; +/// Convert the array into a string. +fn debug(array: Array) -> String; /// Convert the boolean value into a string in debug format. fn debug(value: bool) -> String; +/// Convert the string into debug format. +fn debug(character: char) -> String; + +/// Convert the value of `number` into a string. +fn debug(number: f32) -> String; + +/// Convert the value of `number` into a string. +fn debug(number: f64) -> String; + +/// Convert the string into debug format. +fn debug(string: String) -> String; + /// Convert the value of the `item` into a string in debug format. fn debug(item: ?) -> 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 duplicated _consecutive_ elements from the array. /// /// The operator `==` is used to compare elements and must be defined, @@ -1206,32 +1181,101 @@ fn dedup(array: Array) -> (); /// ``` fn dedup(array: Array, comparer: String) -> (); -/// Remove all elements within a portion of the array and return them as a new array. +/// Remove duplicated _consecutive_ elements from the array that return `true` when applied the +/// `comparer` function. /// -/// * 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. +/// 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 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 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(1, 2); +/// 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(-1, 1); +/// let z = x.drain(2..3); /// /// print(x); // prints "[1, 4]" /// /// print(z); // prints "[5]" /// ``` -fn drain(array: Array, start: int, len: int) -> Array; +fn drain(array: Array, range: Range) -> Array; /// Remove all bytes in the BLOB within an exclusive `range` and return them as a new BLOB. /// @@ -1256,26 +1300,38 @@ fn drain(array: Array, start: int, len: int) -> Array; /// ``` fn drain(blob: Blob, range: Range) -> Blob; -/// Remove all elements in the array within an exclusive `range` and return them as a new array. +/// 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(1..3); +/// let y = x.drain("small"); /// -/// print(x); // prints "[1, 4, 5]" +/// print(x); // prints "[3, 4, 5]" /// -/// print(y); // prints "[2, 3]" +/// print(y); // prints "[1, 2]" /// -/// let z = x.drain(2..3); +/// let z = x.drain("screen"); /// -/// print(x); // prints "[1, 4]" +/// print(x); // prints "[3, 4]" /// /// print(z); // prints "[5]" /// ``` -fn drain(array: Array, range: Range) -> Array; +fn drain(array: Array, filter: String) -> Array; /// Remove all elements in the array within an inclusive `range` and return them as a new array. /// @@ -1327,88 +1383,32 @@ fn drain(array: Array, range: RangeInclusive) -> Array; /// ``` fn drain(blob: Blob, start: int, len: int) -> Blob; -/// Remove all elements in the array that returns `true` when applied a function named by `filter` -/// and return them as a new array. +/// Remove all elements within a portion of the array 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 +/// * 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(|v| v < 3); +/// let y = x.drain(1, 2); /// -/// print(x); // prints "[3, 4, 5]" +/// print(x); // prints "[1, 4, 5]" /// -/// print(y); // prints "[1, 2]" +/// print(y); // prints "[2, 3]" /// -/// let z = x.drain(|v, i| v + i > 5); +/// let z = x.drain(-1, 1); /// -/// print(x); // prints "[3, 4]" +/// print(x); // prints "[1, 4]" /// /// print(z); // prints "[5]" /// ``` -fn drain(array: Array, filter: FnPtr) -> Array; - -/// 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; +fn drain(array: Array, start: int, len: int) -> Array; /// Return the number of seconds between the current system time and the timestamp. /// @@ -1445,28 +1445,25 @@ fn ends_with(string: String, match_string: String) -> bool; /// Return the exponential of the floating-point number. fn exp(x: float) -> f64; -/// Copy a portion of the BLOB and return it as a new BLOB. +/// 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 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. +/// * 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 b = blob(); +/// let x = [1, 2, 3, 4, 5]; /// -/// b += 1; b += 2; b += 3; b += 4; b += 5; +/// print(x.extract(2)); // prints "[3, 4, 5]" /// -/// print(b.extract(1, 3)); // prints "[020303]" +/// print(x.extract(-3)); // prints "[3, 4, 5]" /// -/// print(b.extract(-3, 2)); // prints "[0304]" -/// -/// print(b); // prints "[0102030405]" +/// print(x); // prints "[1, 2, 3, 4, 5]" /// ``` -fn extract(blob: Blob, start: int, len: int) -> Blob; +fn extract(array: Array, start: int) -> Array; /// Copy a portion of the BLOB beginning at the `start` position till the end and return it as /// a new BLOB. @@ -1490,6 +1487,19 @@ fn extract(blob: Blob, start: int, len: int) -> Blob; /// ``` fn extract(blob: Blob, start: int) -> Blob; +/// 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 an inclusive `range` of the BLOB and return it as a new BLOB. /// /// # Example @@ -1505,27 +1515,6 @@ fn extract(blob: Blob, start: int) -> Blob; /// ``` fn extract(blob: Blob, range: RangeInclusive) -> 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 an exclusive `range` of the BLOB and return it as a new BLOB. /// /// # Example @@ -1554,38 +1543,49 @@ fn extract(blob: Blob, range: Range) -> Blob; /// ``` 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. +/// 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, the entire array is copied and returned. +/// * 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(2)); // prints "[3, 4, 5]" +/// print(x.extract(1, 3)); // prints "[2, 3, 4]" /// -/// print(x.extract(-3)); // prints "[3, 4, 5]" +/// print(x.extract(-3, 2)); // prints "[3, 4]" /// /// print(x); // prints "[1, 2, 3, 4, 5]" /// ``` -fn extract(array: Array, start: int) -> Array; +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. @@ -1783,12 +1783,12 @@ fn get chars(string: String) -> Iterator; /// ``` fn get elapsed(timestamp: Instant) -> RhaiResult; -/// Return the end of the inclusive range. -fn get end(range: InclusiveRange) -> i64; - /// Return the end of the exclusive range. fn get end(range: ExclusiveRange) -> i64; +/// Return the end of the inclusive range. +fn get end(range: InclusiveRange) -> i64; + /// Return the largest whole number less than or equals to the floating-point number. fn get floor(x: float) -> f64; @@ -1809,50 +1809,50 @@ fn get int(x: float) -> f64; /// ``` fn get is_anonymous(fn_ptr: FnPtr) -> 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: u32) -> 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: u16) -> 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: u64) -> 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: u8) -> 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: int) -> 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: u64) -> bool; - -/// Return true if the number is even. -fn get is_even(x: u8) -> 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: u32) -> bool; - -/// Return true if the number is even. -fn get is_even(x: i128) -> bool; +/// Return `true` if the range is exclusive. +fn get is_exclusive(range: InclusiveRange) -> 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: InclusiveRange) -> bool; +fn get is_inclusive(range: ExclusiveRange) -> bool; /// Return `true` if the range is inclusive. -fn get is_inclusive(range: ExclusiveRange) -> bool; +fn get is_inclusive(range: InclusiveRange) -> bool; /// Return `true` if the floating-point number is infinite. fn get is_infinite(x: float) -> bool; @@ -1860,85 +1860,72 @@ 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: u16) -> 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: i16) -> 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: u64) -> 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: u8) -> 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: u16) -> 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: u32) -> 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: u8) -> 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: i128) -> bool; +/// Return true if the floating-point number is zero. +fn get is_zero(x: f64) -> 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: 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: 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: i8) -> bool; + /// Return true if the floating-point number is zero. fn get is_zero(x: f32) -> bool; /// Return true if the number is zero. fn get is_zero(x: i16) -> bool; -/// Return true if the floating-point number is zero. -fn get is_zero(x: f64) -> 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: u128) -> bool; +fn get is_zero(x: u8) -> 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: u32) -> 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: u8) -> 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: i32) -> bool; - /// Return true if the number is zero. fn get is_zero(x: int) -> bool; -/// 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) -> i64; - /// Return the length of the string, in number of characters. /// /// # Example @@ -1953,6 +1940,19 @@ fn get len(string: String) -> i64; /// Number of elements in the array. fn get len(array: Array) -> i64; +/// 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) -> i64; + /// Return the name of the function. /// /// # Example @@ -2017,6 +2017,17 @@ fn get_bit(value: int, bit: int) -> bool; /// ``` 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). @@ -2032,47 +2043,15 @@ fn get_bits(value: int, range: Range) -> int; /// ``` fn get_bits(value: int, start: int, bits: int) -> 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; +fn get_fn_metadata_list() -> Array; fn get_fn_metadata_list(name: String) -> Array; -fn get_fn_metadata_list() -> 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) -> f64; -/// 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) -> i64; - /// 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. @@ -2105,13 +2084,13 @@ fn index_of(array: Array, filter: String) -> int; /// # Example /// /// ```rhai -/// let text = "hello, world! hello, foobar!"; +/// let text = "hello, world!"; /// -/// print(text.index_of("ll")); // prints 2 (first index) +/// print(text.index_of('l')); // prints 2 (first index) /// -/// print(text.index_of("xx:)); // prints -1 +/// print(text.index_of('x')); // prints -1 /// ``` -fn index_of(string: String, find_string: String) -> i64; +fn index_of(string: String, character: char) -> i64; /// 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`. @@ -2135,6 +2114,39 @@ fn index_of(string: String, find_string: String) -> i64; /// ``` fn index_of(array: Array, filter: FnPtr) -> 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) -> i64; + +/// 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; + /// 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. @@ -2207,28 +2219,9 @@ fn index_of(array: Array, filter: FnPtr, start: int) -> int; /// ``` fn index_of(array: Array, filter: String, start: int) -> 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, starting from the specified `start` position, +/// 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 `character` is not found, `-1` is returned. +/// 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. @@ -2237,15 +2230,15 @@ fn index_of(array: Array, value: ?) -> int; /// # Example /// /// ```rhai -/// let text = "hello, world!"; +/// let text = "hello, world! hello, foobar!"; /// -/// print(text.index_of('l', 5)); // prints 10 (first index after 5) +/// print(text.index_of("ll", 5)); // prints 16 (first index after 5) /// -/// print(text.index_of('o', -7)); // prints 8 +/// print(text.index_of("ll", -15)); // prints 16 /// -/// print(text.index_of('x', 0)); // prints -1 +/// print(text.index_of("xx", 0)); // prints -1 /// ``` -fn index_of(string: String, character: char, start: int) -> i64; +fn index_of(string: String, find_string: String, start: int) -> i64; /// 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. @@ -2276,19 +2269,45 @@ fn index_of(string: String, character: char, start: int) -> i64; /// ``` fn index_of(array: Array, value: ?, start: int) -> int; -/// Find the specified `character` in the string and return the first index where it is found. +/// 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')); // prints 2 (first index) +/// print(text.index_of('l', 5)); // prints 10 (first index after 5) /// -/// print(text.index_of('x')); // prints -1 +/// print(text.index_of('o', -7)); // prints 8 +/// +/// print(text.index_of('x', 0)); // prints -1 /// ``` -fn index_of(string: String, character: char) -> i64; +fn index_of(string: String, character: char, start: int) -> i64; + +/// 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) -> (); /// Add a new element into the array at a particular `index` position. /// @@ -2311,25 +2330,6 @@ fn index_of(string: String, character: char) -> i64; /// ``` 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) -> f64; @@ -2345,35 +2345,35 @@ fn int(x: float) -> f64; fn is_anonymous(fn_ptr: FnPtr) -> 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: u16) -> bool; +fn is_even(x: u64) -> 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: i128) -> 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: u64) -> 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: u8) -> bool; +fn is_even(x: u16) -> 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: i32) -> 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: int) -> 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: u8) -> bool; + +/// Return true if the number is even. +fn is_even(x: i128) -> bool; + /// Return `true` if the range is exclusive. fn is_exclusive(range: ExclusiveRange) -> bool; @@ -2395,38 +2395,35 @@ 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: i16) -> bool; + /// Return true if the number is odd. fn is_odd(x: u8) -> 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: int) -> 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: u64) -> 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: i8) -> bool; - -/// Return true if the number is odd. -fn is_odd(x: i128) -> bool; +fn is_odd(x: u64) -> 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; +fn is_odd(x: i8) -> bool; /// Return true if the number is odd. -fn is_odd(x: i16) -> bool; - -/// Return true if the number is zero. -fn is_zero(x: i8) -> bool; +fn is_odd(x: u16) -> bool; /// Return true if the number is zero. fn is_zero(x: u32) -> bool; @@ -2434,32 +2431,35 @@ fn is_zero(x: u32) -> 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: u64) -> bool; +/// Return true if the floating-point number is zero. +fn is_zero(x: f64) -> bool; /// Return true if the number is zero. -fn is_zero(x: int) -> bool; - -/// Return true if the number is zero. -fn is_zero(x: u8) -> bool; - -/// Return true if the number is zero. -fn is_zero(x: i128) -> bool; +fn is_zero(x: i8) -> 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: u128) -> bool; - /// Return true if the floating-point number is zero. fn is_zero(x: f32) -> 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: u128) -> 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 floating-point number is zero. -fn is_zero(x: f64) -> bool; +/// Return true if the number is zero. +fn is_zero(x: u8) -> bool; + +/// Return true if the number is zero. +fn is_zero(x: int) -> bool; /// Return an array with all the property names in the object map. /// @@ -2475,16 +2475,8 @@ fn keys(map: Map) -> Array; /// Return the number of properties in the object map. fn len(map: Map) -> i64; -/// Return the length of the string, in number of characters. -/// -/// # Example -/// -/// ```rhai -/// let text = "朝には紅顔ありて夕べには白骨となる"; -/// -/// print(text.len); // prints 17 -/// ``` -fn len(string: String) -> i64; +/// Number of elements in the array. +fn len(array: Array) -> i64; /// Return the length of the BLOB. /// @@ -2499,8 +2491,16 @@ fn len(string: String) -> i64; /// ``` fn len(blob: Blob) -> i64; -/// Number of elements in the array. -fn len(array: Array) -> i64; +/// Return the length of the string, in number of characters. +/// +/// # Example +/// +/// ```rhai +/// let text = "朝には紅顔ありて夕べには白骨となる"; +/// +/// print(text.len); // prints 17 +/// ``` +fn len(string: String) -> i64; /// Return the natural log of the floating-point number. fn ln(x: float) -> f64; @@ -2511,19 +2511,6 @@ fn log(x: float) -> f64; /// Return the log of the floating-point number with `base`. fn log(x: float, base: float) -> f64; -/// 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 @@ -2537,18 +2524,18 @@ fn make_lower(character: char) -> (); /// ``` fn make_lower(string: String) -> (); -/// Convert the string to all upper-case. +/// Convert the character to lower-case. /// /// # Example /// /// ```rhai -/// let text = "hello, world!" +/// let ch = 'A'; /// -/// text.make_upper(); +/// ch.make_lower(); /// -/// print(text); // prints "HELLO, WORLD!"; +/// print(ch); // prints 'a' /// ``` -fn make_upper(string: String) -> (); +fn make_lower(character: char) -> (); /// Convert the character to upper-case. /// @@ -2563,6 +2550,42 @@ fn make_upper(string: String) -> (); /// ``` 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 `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; + /// 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. /// @@ -2592,29 +2615,6 @@ fn make_upper(character: char) -> (); /// ``` 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. /// @@ -2662,7 +2662,7 @@ fn name(fn_ptr: FnPtr) -> String; /// ``` fn pad(array: Array, len: int, item: ?) -> (); -/// Pad the string to at least the specified number of characters with the specified string. +/// Pad the string to at least the specified number of characters with the specified `character`. /// /// If `len` ≤ length of string, no padding is done. /// @@ -2671,15 +2671,15 @@ fn pad(array: Array, len: int, item: ?) -> (); /// ```rhai /// let text = "hello"; /// -/// text.pad(10, "(!)"); +/// text.pad(8, '!'); /// -/// print(text); // prints "hello(!)(!)" +/// print(text); // prints "hello!!!" /// -/// text.pad(8, '***'); +/// text.pad(5, '*'); /// -/// print(text); // prints "hello(!)(!)" +/// print(text); // prints "hello!!!" /// ``` -fn pad(string: String, len: int, padding: String) -> (); +fn pad(string: String, len: int, character: char) -> (); /// Pad the BLOB to at least the specified length with copies of a specified byte `value`. /// @@ -2702,7 +2702,7 @@ fn pad(string: String, len: int, padding: String) -> (); /// ``` fn pad(blob: Blob, len: int, value: int) -> (); -/// Pad the string to at least the specified number of characters with the specified `character`. +/// Pad the string to at least the specified number of characters with the specified string. /// /// If `len` ≤ length of string, no padding is done. /// @@ -2711,15 +2711,15 @@ fn pad(blob: Blob, len: int, value: int) -> (); /// ```rhai /// let text = "hello"; /// -/// text.pad(8, '!'); +/// text.pad(10, "(!)"); /// -/// print(text); // prints "hello!!!" +/// print(text); // prints "hello(!)(!)" /// -/// text.pad(5, '*'); +/// text.pad(8, '***'); /// -/// print(text); // prints "hello!!!" +/// print(text); // prints "hello(!)(!)" /// ``` -fn pad(string: String, len: int, character: char) -> (); +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. @@ -2728,6 +2728,13 @@ fn pad(string: String, len: int, character: char) -> (); /// * If number of bytes in `range` > number of bytes for `FLOAT`, extra bytes are ignored. fn parse_be_float(blob: Blob, range: Range) -> f64; +/// 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) -> f64; + /// Parse the bytes beginning at the `start` position in the BLOB as a `FLOAT` /// in big-endian byte order. /// @@ -2741,13 +2748,6 @@ fn parse_be_float(blob: Blob, range: Range) -> f64; /// * 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) -> f64; -/// 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) -> f64; - /// Parse the bytes within an exclusive `range` in the BLOB as an `INT` /// in big-endian byte order. /// @@ -2765,6 +2765,23 @@ fn parse_be_float(blob: Blob, range: RangeInclusive) -> f64; /// ``` fn parse_be_int(blob: Blob, range: Range) -> i64; +/// 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) -> i64; + /// Parse the bytes beginning at the `start` position in the BLOB as an `INT` /// in big-endian byte order. /// @@ -2788,23 +2805,6 @@ fn parse_be_int(blob: Blob, range: Range) -> i64; /// ``` fn parse_be_int(blob: Blob, start: int, len: int) -> i64; -/// 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) -> i64; - /// Parse a string into a floating-point number. /// /// # Example @@ -2816,6 +2816,17 @@ fn parse_be_int(blob: Blob, range: RangeInclusive) -> i64; /// ``` 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. @@ -2833,16 +2844,19 @@ fn parse_float(string: String) -> float; /// ``` fn parse_int(string: String, radix: int) -> int; -/// Parse a string into an integer number. +/// Parse the bytes within an exclusive `range` in the BLOB as a `FLOAT` +/// in little-endian byte order. /// -/// # Example +/// * 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) -> f64; + +/// Parse the bytes within an inclusive `range` in the BLOB as a `FLOAT` +/// in little-endian byte order. /// -/// ```rhai -/// let x = parse_int("123"); -/// -/// print(x); // prints 123 -/// ``` -fn parse_int(string: String) -> int; +/// * 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) -> f64; /// Parse the bytes beginning at the `start` position in the BLOB as a `FLOAT` /// in little-endian byte order. @@ -2857,19 +2871,22 @@ fn parse_int(string: String) -> int; /// * 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) -> f64; -/// Parse the bytes within an exclusive `range` in the BLOB as a `FLOAT` +/// 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 `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) -> f64; - -/// 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 `INT`, zeros are padded. +/// * If number of bytes in `range` > number of bytes for `INT`, extra bytes are ignored. /// -/// * 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) -> f64; +/// ```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) -> i64; /// Parse the bytes within an exclusive `range` in the BLOB as an `INT` /// in little-endian byte order. @@ -2911,22 +2928,20 @@ fn parse_le_int(blob: Blob, range: Range) -> i64; /// ``` fn parse_le_int(blob: Blob, start: int, len: int) -> i64; -/// Parse the bytes within an inclusive `range` in the BLOB as an `INT` -/// in little-endian byte order. +/// Remove the last character from the string and return it. /// -/// * 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. +/// If the string is empty, `()` is returned. +/// +/// # Example /// /// ```rhai -/// let b = blob(); +/// let text = "hello, world!"; /// -/// b += 1; b += 2; b += 3; b += 4; b += 5; +/// print(text.pop()); // prints '!' /// -/// let x = b.parse_le_int(1..=3); // parse three bytes -/// -/// print(x.to_hex()); // prints "040302" +/// print(text); // prints "hello, world" /// ``` -fn parse_le_int(blob: Blob, range: RangeInclusive) -> i64; +fn pop(string: String) -> ?; /// Remove the last byte from the BLOB and return it. /// @@ -2945,20 +2960,20 @@ fn parse_le_int(blob: Blob, range: RangeInclusive) -> i64; /// ``` fn pop(blob: Blob) -> i64; -/// Remove the last character from the string and return it. +/// Remove the last element from the array and return it. /// -/// If the string is empty, `()` is returned. +/// If the array is empty, `()` is returned. /// /// # Example /// /// ```rhai -/// let text = "hello, world!"; +/// let x = [1, 2, 3]; /// -/// print(text.pop()); // prints '!' +/// print(x.pop()); // prints 3 /// -/// print(text); // prints "hello, world" +/// print(x); // prints "[1, 2]" /// ``` -fn pop(string: String) -> ?; +fn pop(array: Array) -> ?; /// Remove a specified number of characters from the end of the string and return it as a /// new string. @@ -2977,20 +2992,26 @@ fn pop(string: String) -> ?; /// ``` fn pop(string: String, len: int) -> String; -/// 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) -> ?; +/// Return the empty string. +fn print() -> String; + +/// Convert the value of the `item` into a string. +fn print(item: ?) -> String; + +/// Return the `string`. +fn print(string: String) -> String; + +/// Convert the value of `number` into a string. +fn print(number: f64) -> String; + +/// Convert the value of `number` into a string. +fn print(number: f32) -> String; + +/// Return the boolean value into a string. +fn print(value: bool) -> String; + +/// Return the character into a string. +fn print(character: char) -> String; /// Convert the array into a string. fn print(array: Array) -> String; @@ -2998,30 +3019,9 @@ fn print(array: Array) -> String; /// Return the empty string. fn print(unit: ()) -> String; -/// Return the character into a string. -fn print(character: char) -> String; - -/// Return the `string`. -fn print(string: String) -> String; - -/// Convert the value of `number` into a string. -fn print(number: f32) -> String; - -/// Return the empty string. -fn print() -> String; - -/// Convert the value of `number` into a string. -fn print(number: f64) -> String; - /// Convert the object map into a string. fn print(map: Map) -> String; -/// Return the boolean value into a string. -fn print(value: bool) -> String; - -/// Convert the value of the `item` into a string. -fn print(item: ?) -> 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. @@ -3052,49 +3052,120 @@ fn push(array: Array, item: ?) -> (); /// ``` fn push(blob: Blob, value: int) -> (); -/// Return an iterator over the exclusive range of `from..to`, each iteration increasing by `step`. +/// Return an iterator over the exclusive range of `from..to`. /// 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) { +/// // prints all values from 8 to 17 +/// for n in range(8, 18) { /// print(n); /// } /// ``` -fn range(from: u8, to: u8, step: u8) -> Iterator; +fn range(from: i128, to: i128) -> Iterator; -/// Return an iterator over the exclusive range of `from..to`, each iteration increasing by `step`. -/// The value `to` is never included. +/// Return an iterator over an exclusive range, each iteration increasing by `step`. /// -/// If `from` > `to` and `step` < 0, iteration goes backwards. +/// If `range` is reversed and `step` < 0, iteration goes backwards. /// -/// If `from` > `to` and `step` > 0 or `from` < `to` and `step` < 0, an empty iterator is returned. +/// 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) { +/// 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) { +/// for n in range(18..8, -3) { /// print(n); /// } /// ``` -fn range(from: i128, to: i128, step: i128) -> Iterator; +fn range(range: Range, step: 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: i8, to: 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: 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 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 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: i64, to: i64) -> Iterator; /// Return an iterator over an exclusive range, each iteration increasing by `step`. /// @@ -3117,63 +3188,6 @@ fn range(from: i128, to: i128, step: i128) -> Iterator; /// ``` fn range(range: Range, 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: float, to: float, step: float) -> 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`, 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`. /// The value `to` is never included. /// @@ -3187,31 +3201,26 @@ fn range(from: u64, to: u64, step: u64) -> Iterator; /// ``` fn range(from: i32, to: i32) -> Iterator; -/// Return an iterator over the exclusive range of `from..to`. -/// The value `to` is never included. +/// 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 -/// for n in range(8, 18) { +/// // 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) -> 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; +fn range(range: Range, step: i64) -> Iterator; /// Return an iterator over an exclusive range, each iteration increasing by `step`. /// @@ -3245,29 +3254,7 @@ fn range(range: Range, step: i32) -> Iterator; /// print(n); /// } /// ``` -fn range(from: u8, to: 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: u16, to: u16, step: u16) -> Iterator; +fn range(from: u16, to: u16) -> Iterator; /// Return an iterator over an exclusive range, each iteration increasing by `step`. /// @@ -3288,7 +3275,101 @@ fn range(from: u16, to: u16, step: u16) -> Iterator; /// print(n); /// } /// ``` -fn range(range: Range, step: u64) -> Iterator; +fn range(range: Range, step: 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: u64, to: 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: 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: u32, to: 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: 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: 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: u8, to: u8) -> Iterator; /// Return an iterator over an exclusive range, each iteration increasing by `step`. /// @@ -3311,54 +3392,6 @@ fn range(range: Range, step: u64) -> Iterator; /// ``` fn range(range: Range, step: u8) -> 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`, 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`. -/// 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 an exclusive range, each iteration increasing by `step`. /// /// If `range` is reversed and `step` < 0, iteration goes backwards. @@ -3402,18 +3435,49 @@ fn range(range: Range, step: u128) -> Iterator; /// ``` fn range(from: i16, to: i16, step: i16) -> Iterator; -/// Return an iterator over the exclusive range of `from..to`. +/// 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 -/// for n in range(8, 18) { +/// // 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) -> Iterator; +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: 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. @@ -3437,39 +3501,27 @@ fn range(from: i8, to: i8) -> Iterator; /// ``` fn range(from: u128, to: u128, step: u128) -> Iterator; -/// Return an iterator over an exclusive range, each iteration increasing by `step`. +/// Return an iterator over the exclusive range of `from..to`, each iteration increasing by `step`. +/// The value `to` is never included. /// -/// If `range` is reversed and `step` < 0, iteration goes backwards. +/// If `from` > `to` and `step` < 0, iteration goes backwards. /// -/// Otherwise, if `range` is empty, an empty iterator is returned. +/// 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) { +/// 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) { +/// for n in range(18, 8, -3) { /// print(n); /// } /// ``` -fn range(range: Range, step: 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: u16, to: u16) -> Iterator; +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. @@ -3491,125 +3543,73 @@ fn range(from: u16, to: u16) -> Iterator; /// print(n); /// } /// ``` -fn range(from: u32, to: u32, step: u32) -> Iterator; +fn range(from: i32, to: i32, 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: i64) -> 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: 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: 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: u16) -> Iterator; - -/// Return an iterator over the exclusive range of `from..to`. +/// 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 -/// for n in range(8, 18) { +/// // 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: i64, to: i64) -> Iterator; +fn range(from: i64, to: i64, step: i64) -> 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: u8, to: u8, step: u8) -> Iterator; /// Return an iterator over the exclusive range of `from..to`, each iteration increasing by `step`. /// The value `to` is never included. @@ -3653,7 +3653,62 @@ fn range(from: i8, to: i8, step: i8) -> Iterator; /// print(n); /// } /// ``` -fn range(from: i64, to: i64, step: i64) -> Iterator; +fn range(from: float, to: float, step: float) -> Iterator; + +/// 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, 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. /// @@ -3707,7 +3762,8 @@ fn reduce(array: Array, reducer: FnPtr, initial: ?) -> RhaiResult; /// ``` fn reduce(array: Array, reducer: String, initial: ?) -> RhaiResult; -/// Reduce an array by iterating through all elements while applying a function named by `reducer`. +/// Reduce an array by iterating through all elements, in _reverse_ order, +/// while applying a function named by `reducer`. /// /// # Function Parameters /// @@ -3729,17 +3785,18 @@ fn reduce(array: Array, reducer: String, initial: ?) -> RhaiResult; /// /// let x = [1, 2, 3, 4, 5]; /// -/// let y = x.reduce("process"); +/// let y = x.reduce_rev("process"); /// /// print(y); // prints 15 /// -/// let y = x.reduce("process_extra"); +/// let y = x.reduce_rev("process_extra"); /// /// print(y); // prints 25 /// ``` -fn reduce(array: Array, reducer: String) -> RhaiResult; +fn reduce_rev(array: Array, reducer: String) -> RhaiResult; -/// Reduce an array by iterating through all elements while applying the `reducer` function. +/// Reduce an array by iterating through all elements, in _reverse_ order, +/// while applying the `reducer` function. /// /// # Function Parameters /// @@ -3752,15 +3809,15 @@ fn reduce(array: Array, reducer: String) -> RhaiResult; /// ```rhai /// let x = [1, 2, 3, 4, 5]; /// -/// let y = x.reduce(|r, v| v + (r ?? 0)); +/// let y = x.reduce_rev(|r, v| v + (r ?? 0)); /// /// print(y); // prints 15 /// -/// let y = x.reduce(|r, v, i| v + i + (r ?? 0)); +/// let y = x.reduce_rev(|r, v, i| v + i + (r ?? 0)); /// /// print(y); // prints 25 /// ``` -fn reduce(array: Array, reducer: FnPtr) -> RhaiResult; +fn reduce_rev(array: Array, reducer: FnPtr) -> RhaiResult; /// Reduce an array by iterating through all elements, in _reverse_ order, /// while applying the `reducer` function. @@ -3816,62 +3873,35 @@ fn reduce_rev(array: Array, reducer: FnPtr, initial: ?) -> RhaiResult; /// ``` 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, initially `()` -/// * `element`: copy of array element -/// * `index` _(optional)_: current index in the array +/// Remove all occurrences of a sub-string from the string. /// /// # Example /// /// ```rhai -/// let x = [1, 2, 3, 4, 5]; +/// let text = "hello, world! hello, foobar!"; /// -/// let y = x.reduce_rev(|r, v| v + (r ?? 0)); +/// text.remove("hello"); /// -/// print(y); // prints 15 -/// -/// let y = x.reduce_rev(|r, v, i| v + i + (r ?? 0)); -/// -/// print(y); // prints 25 +/// print(text); // prints ", world! , foobar!" /// ``` -fn reduce_rev(array: Array, reducer: FnPtr) -> RhaiResult; +fn remove(string: String, sub_string: String) -> (); -/// Reduce an array by iterating through all elements, in _reverse_ order, -/// while applying a function named by `reducer`. +/// Remove any property of the specified `name` from the object map, returning its value. /// -/// # 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 +/// If the property does not exist, `()` is returned. /// /// # Example /// /// ```rhai -/// fn process(r, x) { -/// x + (r ?? 0) -/// } -/// fn process_extra(r, x, i) { -/// x + i + (r ?? 0) -/// } +/// let m = #{a:1, b:2, c:3}; /// -/// let x = [1, 2, 3, 4, 5]; +/// let x = m.remove("b"); /// -/// let y = x.reduce_rev("process"); +/// print(x); // prints 2 /// -/// print(y); // prints 15 -/// -/// let y = x.reduce_rev("process_extra"); -/// -/// print(y); // prints 25 +/// print(m); // prints "#{a:1, c:3}" /// ``` -fn reduce_rev(array: Array, reducer: String) -> RhaiResult; +fn remove(map: Map, property: String) -> ?; /// Remove the byte at the specified `index` from the BLOB and return it. /// @@ -3896,36 +3926,6 @@ fn reduce_rev(array: Array, reducer: String) -> RhaiResult; /// ``` fn remove(blob: Blob, index: int) -> i64; -/// 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 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) -> (); - /// 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). @@ -3960,6 +3960,19 @@ fn remove(array: Array, index: int) -> ?; /// ``` fn remove(string: String, character: char) -> (); +/// 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 sub-string in the string with the specified character. /// /// # Example @@ -3986,19 +3999,6 @@ fn replace(string: String, find_string: String, substitute_character: char) -> ( /// ``` fn replace(string: String, find_string: String, substitute_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 @@ -4012,35 +4012,6 @@ fn replace(string: String, find_character: char, substitute_character: char) -> /// ``` fn replace(string: String, find_character: char, substitute_string: String) -> (); -/// 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; - /// Remove all bytes in the BLOB not within an inclusive `range` and return them as a new BLOB. /// /// # Example @@ -4091,6 +4062,50 @@ fn retain(blob: Blob, range: RangeInclusive) -> Blob; /// ``` 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 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 elements in the array that do not return `true` when applied a function named by /// `filter` and return them as a new array. /// @@ -4124,6 +4139,56 @@ fn retain(array: Array, filter: FnPtr) -> Array; /// ``` fn retain(array: Array, filter: String) -> 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 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; + /// 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). @@ -4151,84 +4216,6 @@ fn retain(array: Array, filter: String) -> Array; /// ``` fn retain(array: Array, start: int, len: int) -> 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; - -/// 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 @@ -4246,6 +4233,19 @@ fn reverse(array: Array) -> (); /// ``` fn reverse(blob: 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) -> (); + /// Return the nearest whole number closest to the floating-point number. /// Rounds away from zero. fn round(x: float) -> f64; @@ -4275,30 +4275,24 @@ fn round(x: float) -> f64; /// ``` fn set(string: String, index: int, character: char) -> (); -/// Set the element at the `index` position in the array to a new `value`. +/// Set the value of the `property` in the object map 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. +/// If `property` does not exist in the object map, it is added. /// /// # Example /// /// ```rhai -/// let x = [1, 2, 3]; +/// let m = #{a: 1, b: 2, c: 3}; /// -/// x.set(0, 42); +/// m.set("b", 42)' /// -/// print(x); // prints "[42, 2, 3]" +/// print(m); // prints "#{a: 1, b: 42, c: 3}" /// -/// x.set(-3, 0); +/// x.set("x", 0); /// -/// print(x); // prints "[0, 2, 3]" -/// -/// x.set(99, 123); -/// -/// print(x); // prints "[0, 2, 3]" +/// print(m); // prints "#{a: 1, b: 42, c: 3, x: 0}" /// ``` -fn set(array: Array, index: int, value: ?) -> (); +fn set(map: Map, property: String, value: ?) -> (); /// Set the particular `index` position in the BLOB to a new byte `value`. /// @@ -4327,24 +4321,30 @@ fn set(array: Array, index: int, value: ?) -> (); /// ``` fn set(blob: Blob, index: int, value: int) -> (); -/// Set the value of the `property` in the object map to a new `value`. +/// Set the element at the `index` position in the array to a new `value`. /// -/// If `property` does not exist in the object map, it is added. +/// * 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 m = #{a: 1, b: 2, c: 3}; +/// let x = [1, 2, 3]; /// -/// m.set("b", 42)' +/// x.set(0, 42); /// -/// print(m); // prints "#{a: 1, b: 42, c: 3}" +/// print(x); // prints "[42, 2, 3]" /// -/// x.set("x", 0); +/// x.set(-3, 0); /// -/// print(m); // prints "#{a: 1, b: 42, c: 3, x: 0}" +/// print(x); // prints "[0, 2, 3]" +/// +/// x.set(99, 123); +/// +/// print(x); // prints "[0, 2, 3]" /// ``` -fn set(map: Map, property: String, value: ?) -> (); +fn set(array: Array, index: int, value: ?) -> (); /// Set the _tag_ of a `Dynamic` value. /// @@ -4443,21 +4443,6 @@ fn set_bits(value: int, bit: int, bits: int, new_value: int) -> (); /// ``` 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. @@ -4475,19 +4460,20 @@ fn shift(array: Array) -> ?; /// ``` fn shift(blob: Blob) -> i64; -/// Return the sign (as an integer) of the number according to the following: +/// Remove the first element from the array and return it. /// -/// * `0` if the number is zero -/// * `1` if the number is positive -/// * `-1` if the number is negative -fn sign(x: i128) -> i64; - -/// Return the sign (as an integer) of the number according to the following: +/// If the array is empty, `()` is returned. /// -/// * `0` if the number is zero -/// * `1` if the number is positive -/// * `-1` if the number is negative -fn sign(x: i8) -> i64; +/// # Example +/// +/// ```rhai +/// let x = [1, 2, 3]; +/// +/// print(x.shift()); // prints 1 +/// +/// print(x); // prints "[2, 3]" +/// ``` +fn shift(array: Array) -> ?; /// Return the sign (as an integer) of the number according to the following: /// @@ -4501,7 +4487,14 @@ fn sign(x: int) -> i64; /// * `0` if the number is zero /// * `1` if the number is positive /// * `-1` if the number is negative -fn sign(x: i32) -> i64; +fn sign(x: i128) -> i64; + +/// 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) -> i64; /// Return the sign (as an integer) of the floating-point number according to the following: /// @@ -4510,19 +4503,26 @@ fn sign(x: i32) -> i64; /// * `-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: +/// 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: f64) -> int; +fn sign(x: i8) -> i64; /// 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) -> i64; +fn sign(x: i32) -> i64; + +/// 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: f64) -> int; /// Return the sine of the floating-point number in radians. fn sin(x: float) -> f64; @@ -4536,26 +4536,6 @@ 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 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; - /// Return `true` if any element in the array that returns `true` when applied a function named /// by `filter`. /// @@ -4585,30 +4565,50 @@ fn some(array: Array, filter: FnPtr) -> bool; /// ``` fn some(array: Array, filter: String) -> bool; -/// Sort the array based on applying the `comparer` function. +/// Return `true` if any element in the array that returns `true` when applied the `filter` function. /// /// # Function Parameters /// -/// * `element1`: copy of the current array element to compare -/// * `element2`: copy of the next array element to compare +/// * `element`: copy of array element +/// * `index` _(optional)_: current index in the array /// -/// ## Return Value +/// # Example /// -/// * Any integer > 0 if `element1 > element2` -/// * Zero if `element1 == element2` -/// * Any integer < 0 if `element1 < element2` +/// ```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]; /// -/// // Do comparisons in reverse -/// x.sort(|a, b| if a > b { -1 } else if a < b { 1 } else { 0 }); +/// x.sort(); /// -/// print(x); // prints "[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]" +/// print(x); // prints "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]" /// ``` -fn sort(array: Array, comparer: FnPtr) -> (); +fn sort(array: Array) -> (); /// Sort the array based on applying a function named by `comparer`. /// @@ -4645,68 +4645,44 @@ fn sort(array: Array, comparer: FnPtr) -> (); /// ``` fn sort(array: Array, comparer: String) -> (); -/// Sort the array. +/// Sort the array based on applying the `comparer` function. /// -/// All elements in the array must be of the same data type. +/// # Function Parameters /// -/// # Supported Data Types +/// * `element1`: copy of the current array element to compare +/// * `element2`: copy of the next array element to compare /// -/// * integer numbers -/// * floating-point numbers -/// * decimal numbers -/// * characters -/// * strings -/// * booleans -/// * `()` +/// ## 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]; /// -/// x.sort(); +/// // Do comparisons in reverse +/// x.sort(|a, b| if a > b { -1 } else if a < b { 1 } else { 0 }); /// -/// print(x); // prints "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]" +/// print(x); // prints "[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]" /// ``` -fn sort(array: Array) -> (); +fn sort(array: Array, comparer: FnPtr) -> (); -/// Replace an exclusive range of the array with another array. +/// Replace an inclusive `range` of the BLOB with another BLOB. /// /// # Example /// /// ```rhai -/// let x = [1, 2, 3, 4, 5]; -/// let y = [7, 8, 9, 10]; +/// let b1 = blob(10, 0x42); +/// let b2 = blob(5, 0x18); /// -/// x.splice(1..3, y); +/// b1.splice(1..=4, b2); /// -/// print(x); // prints "[1, 7, 8, 9, 10, 4, 5]" +/// print(b1); // prints "[4218181818184242 424242]" /// ``` -fn splice(array: Array, range: Range, replace: Array) -> (); - -/// 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) -> (); +fn splice(blob: Blob, range: RangeInclusive, replace: Blob) -> (); /// Replace an exclusive `range` of the BLOB with another BLOB. /// @@ -4722,19 +4698,33 @@ fn splice(array: Array, start: int, len: int, replace: Array) -> (); /// ``` fn splice(blob: Blob, range: Range, replace: Blob) -> (); -/// Replace an inclusive `range` of the BLOB with another BLOB. +/// Replace an inclusive range of the array with another array. /// /// # Example /// /// ```rhai -/// let b1 = blob(10, 0x42); -/// let b2 = blob(5, 0x18); +/// let x = [1, 2, 3, 4, 5]; +/// let y = [7, 8, 9, 10]; /// -/// b1.splice(1..=4, b2); +/// x.splice(1..=3, y); /// -/// print(b1); // prints "[4218181818184242 424242]" +/// print(x); // prints "[1, 7, 8, 9, 10, 5]" /// ``` -fn splice(blob: Blob, range: RangeInclusive, replace: Blob) -> (); +fn splice(array: Array, range: RangeInclusive, replace: Array) -> (); + +/// 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 a portion of the BLOB with another BLOB. /// @@ -4760,7 +4750,13 @@ fn splice(blob: Blob, range: RangeInclusive, replace: Blob) -> (); /// ``` fn splice(blob: Blob, start: int, len: int, replace: Blob) -> (); -/// Replace an inclusive range of the array with another array. +/// 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 /// @@ -4768,36 +4764,26 @@ fn splice(blob: Blob, start: int, len: int, replace: Blob) -> (); /// let x = [1, 2, 3, 4, 5]; /// let y = [7, 8, 9, 10]; /// -/// x.splice(1..=3, y); +/// x.splice(1, 2, y); /// -/// print(x); // prints "[1, 7, 8, 9, 10, 5]" +/// 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, range: RangeInclusive, replace: Array) -> (); +fn splice(array: Array, start: int, len: int, replace: 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. +/// 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("ll", 2)); // prints ["he", "o, world! hello, foo!"] +/// print(text.split()); // prints ["hello,", "world!", "hello,", "foo!"] /// ``` -fn split(string: String, delimiter: String, segments: 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; +fn split(string: String) -> Array; /// Cut off the BLOB at `index` and return it as a new BLOB. /// @@ -4876,16 +4862,30 @@ fn split(string: String, delimiter: char) -> Array; /// ``` fn split(array: Array, index: int) -> Array; -/// Split the string into segments based on whitespaces, returning an array of the segments. +/// 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()); // prints ["hello,", "world!", "hello,", "foo!"] +/// print(text.split("ll")); // prints ["he", "o, world! he", "o, foo!"] /// ``` -fn split(string: String) -> Array; +fn split(string: String, delimiter: String) -> 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. @@ -4913,6 +4913,18 @@ fn split(string: String, delimiter: char, segments: int) -> Array; /// ``` 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. /// @@ -4927,18 +4939,6 @@ fn split_rev(string: String, delimiter: String) -> Array; /// ``` fn split_rev(string: String, delimiter: String, segments: int) -> 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 the specified number of `segments` based on a `delimiter` character, /// returning an array of the segments. /// @@ -4986,24 +4986,16 @@ fn starts_with(string: String, match_string: String) -> bool; /// ``` fn sub_string(string: String, range: Range) -> 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. +/// 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, 4)); // prints "lo, " -/// -/// print(text.sub_string(-8, 3)); // prints ", w" +/// print(text.sub_string(3..=7)); // prints "lo, w" /// ``` -fn sub_string(string: String, start: int, len: int) -> String; +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. @@ -5023,16 +5015,24 @@ fn sub_string(string: String, start: int, len: int) -> String; /// ``` fn sub_string(string: String, start: int) -> String; -/// Copy an inclusive range of characters from the string and return it as a new 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..=7)); // prints "lo, w" +/// print(text.sub_string(3, 4)); // prints "lo, " +/// +/// print(text.sub_string(-8, 3)); // prints ", w" /// ``` -fn sub_string(string: String, range: RangeInclusive) -> String; +fn sub_string(string: String, start: int, len: int) -> String; /// Return the _tag_ of a `Dynamic` value. /// @@ -5069,33 +5069,33 @@ fn timestamp() -> Instant; /// ``` fn to_array(blob: Blob) -> Array; -/// 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: u16) -> 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: i128) -> String; - /// Convert the `value` into a string in binary format. fn to_binary(value: i64) -> 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: i32) -> String; +fn to_binary(value: i16) -> String; /// Convert the `value` into a string in binary format. fn to_binary(value: u8) -> String; +/// 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: u64) -> 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: i8) -> 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: i32) -> String; + /// Convert the `value` into a string in binary format. fn to_binary(value: u32) -> String; @@ -5126,17 +5126,17 @@ fn to_chars(string: String) -> Array; /// Convert the value of `number` into a string. fn to_debug(number: f64) -> String; -/// Convert the object map into a string. -fn to_debug(map: Map) -> String; +/// Convert the string into debug format. +fn to_debug(string: String) -> String; + +/// Convert the value of the `item` into a string in debug format. +fn to_debug(item: ?) -> String; /// Convert the value of `number` into a string. fn to_debug(number: f32) -> String; -/// Convert the function pointer into a string in debug format. -fn to_debug(f: FnPtr) -> String; - -/// Convert the string into debug format. -fn to_debug(string: String) -> String; +/// Convert the array into a string. +fn to_debug(array: Array) -> String; /// Convert the string into debug format. fn to_debug(character: char) -> String; @@ -5144,11 +5144,11 @@ fn to_debug(character: char) -> String; /// Convert the boolean value into a string in debug format. fn to_debug(value: bool) -> String; -/// Convert the value of the `item` into a string in debug format. -fn to_debug(item: ?) -> String; +/// Convert the function pointer into a string in debug format. +fn to_debug(f: FnPtr) -> String; -/// Convert the array into a string. -fn to_debug(array: Array) -> String; +/// Convert the object map into a string. +fn to_debug(map: Map) -> String; /// Convert the unit into a string in debug format. fn to_debug(unit: ()) -> String; @@ -5156,29 +5156,35 @@ fn to_debug(unit: ()) -> String; /// Convert radians to degrees. fn to_degrees(x: float) -> f64; -fn to_float(x: i16) -> f64; +fn to_float(x: i32) -> f64; + +fn to_float(x: u32) -> f64; /// Convert the 32-bit floating-point number to 64-bit. fn to_float(x: f32) -> f64; -fn to_float(x: u128) -> f64; +fn to_float(x: i8) -> f64; fn to_float(x: u16) -> f64; +fn to_float(x: u128) -> f64; + fn to_float(x: i128) -> f64; -fn to_float(x: i32) -> f64; - -fn to_float(x: i64) -> f64; - fn to_float(x: u8) -> f64; -fn to_float(x: i8) -> f64; +fn to_float(x: i16) -> f64; -fn to_float(x: u32) -> f64; +fn to_float(x: i64) -> f64; /// Convert the `value` into a string in hex format. -fn to_hex(value: i16) -> String; +fn to_hex(value: i32) -> 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: i8) -> String; /// Convert the `value` into a string in hex format. fn to_hex(value: u16) -> String; @@ -5186,55 +5192,49 @@ fn to_hex(value: u16) -> 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: i128) -> String; - -/// Convert the `value` into a string in hex format. -fn to_hex(value: i64) -> 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: i32) -> String; +fn to_hex(value: i128) -> String; /// Convert the `value` into a string in hex format. fn to_hex(value: u8) -> String; /// Convert the `value` into a string in hex format. -fn to_hex(value: i8) -> String; +fn to_hex(value: i16) -> String; /// Convert the `value` into a string in hex format. -fn to_hex(value: u32) -> String; +fn to_hex(value: i64) -> String; -fn to_int(x: char) -> i64; +fn to_int(x: u32) -> i64; + +/// Convert the floating-point number into an integer. +fn to_int(x: f64) -> int; + +fn to_int(x: i32) -> i64; + +fn to_int(x: u64) -> i64; + +fn to_int(x: u128) -> i64; + +fn to_int(x: u16) -> i64; + +fn to_int(x: i8) -> i64; /// Convert the floating-point number into an integer. fn to_int(x: f32) -> int; fn to_int(x: i16) -> i64; -/// Convert the floating-point number into an integer. -fn to_int(x: f64) -> int; +fn to_int(x: u8) -> i64; -fn to_int(x: u128) -> i64; - -fn to_int(x: u16) -> i64; +fn to_int(x: char) -> i64; fn to_int(x: i128) -> i64; -fn to_int(x: i8) -> i64; - -fn to_int(x: u32) -> i64; - -fn to_int(x: i32) -> i64; - -fn to_int(x: u64) -> i64; - fn to_int(x: i64) -> i64; -fn to_int(x: u8) -> i64; - /// Return the JSON representation of the object map. /// /// # Data types @@ -5256,19 +5256,6 @@ fn to_int(x: u8) -> i64; /// ``` fn to_json(map: Map) -> String; -/// 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 character to lower-case and return it as a new character. /// /// # Example @@ -5282,78 +5269,78 @@ fn to_lower(string: String) -> String; /// ``` fn to_lower(character: char) -> char; -/// 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: i8) -> String; - -/// Convert the `value` into a string in octal format. -fn to_octal(value: u8) -> 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: i32) -> String; - -/// Convert the `value` into a string in octal format. -fn to_octal(value: i64) -> String; +/// 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: u128) -> String; +fn to_octal(value: i16) -> String; + +/// Convert the `value` into a string in octal format. +fn to_octal(value: u8) -> String; + +/// Convert the `value` into a string in octal format. +fn to_octal(value: i64) -> 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: i32) -> 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: i16) -> String; +fn to_octal(value: i8) -> 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: u128) -> String; /// Convert degrees to radians. fn to_radians(x: float) -> f64; -/// Convert the array into a string. -fn to_string(array: Array) -> String; - -/// Return the empty string. -fn to_string(unit: ()) -> String; +/// Return the boolean value into a string. +fn to_string(value: bool) -> String; /// Return the character into a string. fn to_string(character: char) -> String; -/// Return the `string`. -fn to_string(string: String) -> String; - -/// Convert the value of `number` into a string. -fn to_string(number: f32) -> String; +/// Convert the array into a string. +fn to_string(array: Array) -> 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: f64) -> String; +/// Return the empty string. +fn to_string(unit: ()) -> String; -/// Return the boolean value into a string. -fn to_string(value: bool) -> String; +/// Return the `string`. +fn to_string(string: String) -> String; /// Convert the value of the `item` into a string. fn to_string(item: ?) -> 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 value of `number` into a string. +fn to_string(number: f64) -> String; + +/// Convert the value of `number` into a string. +fn to_string(number: f32) -> String; /// Convert the string to all upper-case and return it as a new string. /// @@ -5368,6 +5355,19 @@ fn to_upper(character: char) -> char; /// ``` fn to_upper(string: String) -> 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; + /// Remove whitespace characters from both ends of the string. /// /// # Example @@ -5381,26 +5381,6 @@ fn to_upper(string: String) -> String; /// ``` fn trim(string: String) -> (); -/// 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) -> (); - /// Cut off the BLOB at the specified length. /// /// * If `len` ≤ 0, the BLOB is cleared. @@ -5423,6 +5403,26 @@ fn truncate(string: String, len: int) -> (); /// ``` 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) -> (); + /// Cut off the array at the specified length. /// /// * If `len` ≤ 0, the array is cleared. @@ -5454,6 +5454,23 @@ fn truncate(array: Array, len: int) -> (); /// ``` 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. @@ -5491,37 +5508,19 @@ fn write_ascii(blob: Blob, range: RangeInclusive, string: String) -> (); /// ``` fn write_ascii(blob: Blob, start: int, len: int, string: String) -> (); -/// 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 `INT` value to the bytes within an exclusive `range` in the BLOB +/// 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 `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. +/// * 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 a `FLOAT` value to the bytes within an exclusive `range` in the BLOB +/// in big-endian byte order. /// -/// ```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) -> (); +/// * 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 inclusive `range` in the BLOB /// in big-endian byte order. @@ -5538,12 +5537,20 @@ fn write_be(blob: Blob, range: Range, value: int) -> (); /// ``` fn write_be(blob: Blob, range: RangeInclusive, value: int) -> (); -/// Write a `FLOAT` value to the bytes within an inclusive `range` in the BLOB +/// 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 `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) -> (); +/// * 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 an `INT` value to the bytes beginning at the `start` position in the BLOB /// in big-endian byte order. @@ -5566,13 +5573,6 @@ fn write_be(blob: Blob, range: RangeInclusive, value: float) -> (); /// ``` 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 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 a `FLOAT` value to the bytes beginning at the `start` position in the BLOB /// in big-endian byte order. /// @@ -5586,6 +5586,50 @@ fn write_be(blob: Blob, range: Range, value: float) -> (); /// * 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 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 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 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 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 a `FLOAT` value to the bytes beginning at the `start` position in the BLOB /// in little-endian byte order. /// @@ -5599,13 +5643,6 @@ fn write_be(blob: Blob, start: int, len: int, value: float) -> (); /// * 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 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 beginning at the `start` position in the BLOB /// in little-endian byte order. /// @@ -5627,42 +5664,19 @@ fn write_le(blob: Blob, range: Range, value: float) -> (); /// ``` fn write_le(blob: Blob, start: int, len: int, value: int) -> (); -/// Write an `INT` value to the bytes within an exclusive `range` in the BLOB -/// in little-endian byte order. +/// Write a string to the bytes within an exclusive `range` in the BLOB in UTF-8 encoding. /// -/// * 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. +/// * 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_le_int(1..3, 0x12345678); +/// b.write_utf8(1..5, "朝には紅顔ありて夕べには白骨となる"); /// -/// print(b); // prints "[0078560000000000]" +/// print(b); // prints "[00e69c9de3000000]" /// ``` -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) -> (); +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. /// @@ -5698,34 +5712,20 @@ fn write_utf8(blob: Blob, range: RangeInclusive, string: String) -> (); /// ``` fn write_utf8(blob: Blob, start: int, len: int, string: String) -> (); -/// 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) -> (); +op |(u8, u8) -> u8; -op |(u16, u16) -> u16; +op |(i16, i16) -> i16; op |(u32, u32) -> u32; +op |(u64, u64) -> u64; + +op |(i32, i32) -> i32; + +op |(u16, u16) -> u16; + op |(u128, u128) -> u128; op |(i8, i8) -> i8; -op |(i128, i128) -> i128; - -op |(u64, u64) -> u64; - -op |(u8, u8) -> u8; - -op |(i16, i16) -> i16; - -op |(i32, i32) -> i32; \ No newline at end of file +op |(i128, i128) -> i128; \ No newline at end of file diff --git a/src/api/definitions/mod.rs b/src/api/definitions/mod.rs index 94e600a5..df09cbb1 100644 --- a/src/api/definitions/mod.rs +++ b/src/api/definitions/mod.rs @@ -1,7 +1,7 @@ use crate::{ module::FuncInfo, plugin::*, tokenizer::is_valid_function_name, Engine, Module, Scope, }; -use core::{fmt, iter}; +use core::{cmp::Ordering, fmt, iter}; #[cfg(feature = "no_std")] use std::prelude::v1::*; @@ -223,7 +223,15 @@ impl Module { } let mut func_infos = self.iter_fn().collect::>(); - func_infos.sort_by(|a, b| a.metadata.name.cmp(&b.metadata.name)); + func_infos.sort_by(|a, b| match a.metadata.name.cmp(&b.metadata.name) { + Ordering::Equal => match a.metadata.params.cmp(&b.metadata.params) { + Ordering::Equal => (a.metadata.params_info.join("") + + a.metadata.return_type.as_str()) + .cmp(&(b.metadata.params_info.join("") + b.metadata.return_type.as_str())), + o => o, + }, + o => o, + }); for f in func_infos { if !first { From 7dcf6a5d7a4af8bfe3d072e32ef8fe0dd9d17b4d Mon Sep 17 00:00:00 2001 From: tamasfe Date: Tue, 26 Jul 2022 14:51:22 +0200 Subject: [PATCH 09/11] chore(defs): no stdio on wasm --- src/api/definitions/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/definitions/mod.rs b/src/api/definitions/mod.rs index df09cbb1..53ffe6f3 100644 --- a/src/api/definitions/mod.rs +++ b/src/api/definitions/mod.rs @@ -75,7 +75,7 @@ impl<'e> Definitions<'e> { /// /// This function will create the directory path if it does not yet exist, /// it will also override any existing files as needed. - #[cfg(not(feature = "no_std"))] + #[cfg(all(not(feature = "no_std"), not(target_family = "wasm")))] pub fn write_to_dir(&self, path: impl AsRef) -> std::io::Result<()> { use std::fs; From 3805830bfa858defa28083fc3918136f6a092bd5 Mon Sep 17 00:00:00 2001 From: tamasfe Date: Tue, 26 Jul 2022 15:08:12 +0200 Subject: [PATCH 10/11] chore(defs): regenerate example definitions --- .../.rhai/definitions/__static__.d.rhai | 3294 ++++++++--------- 1 file changed, 1647 insertions(+), 1647 deletions(-) diff --git a/examples/definitions/.rhai/definitions/__static__.d.rhai b/examples/definitions/.rhai/definitions/__static__.d.rhai index 6dbd4594..80992faf 100644 --- a/examples/definitions/.rhai/definitions/__static__.d.rhai +++ b/examples/definitions/.rhai/definitions/__static__.d.rhai @@ -4,7 +4,23 @@ op minus(i64, i64) -> i64; op !(bool) -> bool; -op !=(i16, i16) -> 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). /// @@ -27,169 +43,156 @@ op !=(Map, Map) -> bool; /// Return `true` if two timestamps are not equal. op !=(Instant, Instant) -> bool; -op !=(u8, u8) -> bool; +op !=(int, f32) -> bool; -op !=(u32, u32) -> bool; +op !=(int, f64) -> 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; +op !=(f32, int) -> bool; op !=(f32, f32) -> bool; op !=(f64, int) -> bool; -op !=(u16, u16) -> bool; +op !=(i128, i128) -> bool; -op !=(int, f64) -> bool; +op !=(i16, i16) -> bool; op !=(i32, i32) -> bool; -op !=(u64, u64) -> bool; - -op !=(f32, int) -> bool; - -op !=(i128, i128) -> bool; - op !=(i8, i8) -> bool; -op !=(int, f32) -> bool; - op !=(u128, u128) -> bool; -op %(f32, f32) -> f32; +op !=(u16, u16) -> bool; -op %(u16, u16) -> u16; +op !=(u32, u32) -> bool; -op %(i32, i32) -> i32; +op !=(u64, u64) -> bool; -op %(u64, u64) -> u64; - -op %(f32, int) -> f32; - -op %(i128, i128) -> i128; - -op %(i8, i8) -> i8; +op !=(u8, u8) -> bool; op %(int, f32) -> f32; -op %(u128, u128) -> u128; +op %(f32, int) -> f32; + +op %(f32, f32) -> f32; + +op %(i128, i128) -> i128; op %(i16, i16) -> i16; -op %(u8, u8) -> u8; +op %(i32, i32) -> i32; + +op %(i8, i8) -> i8; + +op %(u128, u128) -> u128; + +op %(u16, u16) -> u16; op %(u32, u32) -> u32; -op &(u16, u16) -> u16; +op %(u64, u64) -> u64; -op &(i32, i32) -> i32; - -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 &(i16, i16) -> i16; - -op &(u8, u8) -> u8; +op &(u16, u16) -> u16; op &(u32, u32) -> u32; -op *(i8, i8) -> i8; +op &(u64, u64) -> u64; -op *(i128, i128) -> i128; +op &(u8, u8) -> u8; op *(int, f32) -> f32; -op *(u128, u128) -> u128; +op *(f32, int) -> f32; op *(f32, f32) -> f32; -op *(u64, u64) -> u64; +op *(i128, i128) -> i128; -op *(f32, int) -> f32; +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 *(i16, i16) -> i16; +op *(u64, u64) -> u64; op *(u8, u8) -> u8; -op **(i8, int) -> i8; +op **(f32, int) -> f32; op **(f32, f32) -> f32; -op **(f32, int) -> f32; - -op **(u16, int) -> u16; +op **(i128, int) -> i128; op **(i16, int) -> i16; -op **(u8, int) -> u8; +op **(i32, int) -> i32; -op **(u64, int) -> u64; +op **(i8, int) -> i8; op **(u128, int) -> u128; -op **(i32, int) -> i32; +op **(u16, int) -> u16; op **(u32, int) -> u32; -op **(i128, int) -> i128; +op **(u64, int) -> u64; + +op **(u8, int) -> u8; op +(int) -> i64; -op +(i128) -> i128; - -op +(i16) -> i16; - -op +(i8) -> i8; - op +(f32) -> f32; op +(f64) -> f64; +op +(i128) -> i128; + +op +(i16) -> i16; + op +(i32) -> i32; -op +(u32, u32) -> u32; - -op +(char, String) -> String; +op +(i8) -> i8; op +((), String) -> String; -/// Add the specified number of `seconds` to the timestamp and return it as a new timestamp. -op +(Instant, float) -> Instant; +/// 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 +(u8, u8) -> u8; +op +(char, String) -> String; op +(?, String) -> String; -op +(String, ?) -> String; - -op +(i16, i16) -> i16; - /// 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. /// @@ -205,55 +208,47 @@ op +(i16, i16) -> i16; /// ``` op +(Map, Map) -> Map; +op +(String, String) -> String; + op +(String, char) -> String; -op +(int, f32) -> f32; +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 +(u128, u128) -> u128; - -op +(String, ()) -> String; - -op +(i128, i128) -> i128; - -op +(String, String) -> String; - -op +(i8, i8) -> i8; - op +(Blob, String) -> String; -op +(String, Blob) -> String; - -op +(u16, u16) -> u16; - -op +(i32, i32) -> i32; +op +(int, f32) -> f32; op +(f32, int) -> f32; -op +(u64, u64) -> u64; - -/// 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 +(f32, f32) -> f32; -/// Add the specified number of `seconds` to the timestamp. -op +=(Instant, float) -> (); +op +(i128, i128) -> i128; -op +=(String, ?) -> (); +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. @@ -270,177 +265,172 @@ op +=(String, ?) -> (); /// ``` op +=(Map, Map) -> (); -/// Add the specified number of `seconds` to the timestamp. -op +=(Instant, int) -> (); +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 -(f64) -> f64; + op -(i128) -> i128; op -(i16) -> i16; -op -(f32) -> f32; - -op -(i8) -> i8; - op -(i32) -> i32; -op -(f64) -> f64; - -op -(u32, u32) -> u32; - -/// Subtract the specified number of `seconds` from the timestamp and return it as a new timestamp. -op -(Instant, float) -> Instant; - -op -(i16, i16) -> i16; +op -(i8) -> i8; /// Return the number of seconds between two timestamps. op -(Instant, Instant) -> RhaiResult; -op -(u8, u8) -> u8; - -op -(i8, i8) -> i8; - -op -(i128, i128) -> i128; - -op -(int, f32) -> f32; - -op -(u128, u128) -> u128; +/// 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 -(f32, f32) -> f32; - -op -(u64, u64) -> u64; +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 /(u8, u8) -> u8; - -op /(i16, i16) -> i16; - -op /(u32, u32) -> u32; - -op /(i32, i32) -> i32; - -op /(u16, u16) -> u16; +op /(int, f32) -> f32; op /(f32, int) -> f32; -op /(u64, u64) -> u64; - op /(f32, f32) -> f32; -op /(u128, u128) -> u128; - -op /(int, f32) -> f32; - op /(i128, i128) -> i128; +op /(i16, i16) -> i16; + +op /(i32, i32) -> i32; + op /(i8, i8) -> i8; -op <(f32, f32) -> bool; +op /(u128, u128) -> u128; -op <(u16, u16) -> bool; +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, f64) -> bool; -op <(i32, i32) -> bool; - -op <(u64, u64) -> bool; - op <(f32, int) -> bool; +op <(f32, f32) -> bool; + op <(f64, int) -> bool; op <(i128, i128) -> bool; +op <(i16, i16) -> bool; + +op <(i32, i32) -> bool; + op <(i8, i8) -> bool; op <(u128, u128) -> bool; -op <(int, f32) -> bool; - -/// Return `true` if the first timestamp is earlier than the second. -op <(Instant, Instant) -> bool; - -op <(i16, i16) -> bool; - -op <(u8, u8) -> bool; +op <(u16, u16) -> bool; op <(u32, u32) -> bool; +op <(u64, u64) -> bool; + +op <(u8, u8) -> bool; + op <<(i128, int) -> i128; -op <<(u32, int) -> u32; - -op <<(i32, int) -> i32; - -op <<(u128, int) -> u128; - -op <<(u64, int) -> u64; - op <<(i16, int) -> i16; -op <<(u16, int) -> u16; - -op <<(u8, int) -> u8; +op <<(i32, int) -> i32; op <<(i8, int) -> i8; -op <=(u128, u128) -> bool; +op <<(u128, int) -> u128; -op <=(int, f32) -> bool; +op <<(u16, int) -> u16; -op <=(i8, i8) -> bool; +op <<(u32, int) -> u32; -op <=(i128, i128) -> bool; +op <<(u64, int) -> u64; -op <=(u64, u64) -> bool; - -op <=(f32, int) -> bool; - -op <=(u16, u16) -> bool; - -op <=(int, f64) -> bool; - -op <=(i32, i32) -> bool; - -op <=(f64, int) -> bool; - -op <=(f32, f32) -> bool; - -op <=(u32, u32) -> bool; - -op <=(u8, u8) -> bool; +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, f64) -> bool; + +op <=(f32, int) -> bool; + +op <=(f32, f32) -> bool; + +op <=(f64, int) -> bool; + +op <=(i128, i128) -> bool; + op <=(i16, i16) -> bool; -op ==(i128, i128) -> bool; +op <=(i32, i32) -> bool; -op ==(i8, i8) -> bool; +op <=(i8, i8) -> bool; -op ==(u128, u128) -> bool; +op <=(u128, u128) -> bool; -op ==(int, f32) -> bool; +op <=(u16, u16) -> bool; -op ==(f32, f32) -> 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). /// @@ -460,23 +450,6 @@ op ==(f32, f32) -> bool; /// ``` op ==(Array, Array) -> bool; -op ==(i32, i32) -> bool; - -op ==(u16, u16) -> bool; - -op ==(int, f64) -> bool; - -op ==(u64, u64) -> bool; - -op ==(f32, int) -> bool; - -op ==(f64, int) -> bool; - -op ==(u32, u32) -> bool; - -/// Return `true` if two timestamps are equal. -op ==(Instant, Instant) -> 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, @@ -495,135 +468,162 @@ op ==(Instant, Instant) -> bool; /// ``` op ==(Map, Map) -> bool; +/// Return `true` if two timestamps are equal. +op ==(Instant, Instant) -> bool; + +op ==(int, f32) -> bool; + +op ==(int, f64) -> bool; + +op ==(f32, int) -> bool; + +op ==(f32, f32) -> bool; + +op ==(f64, 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) -> bool; - -op >(u128, u128) -> bool; - -op >(i128, i128) -> bool; - -op >(i8, i8) -> bool; - -op >(f64, int) -> bool; - -op >(i32, i32) -> bool; - -op >(int, f64) -> bool; - -op >(u16, u16) -> bool; - -op >(f32, int) -> bool; - -op >(u64, u64) -> bool; - -op >(f32, f32) -> bool; - -op >(u32, u32) -> bool; - -op >(u8, u8) -> bool; - -op >(i16, i16) -> bool; - /// Return `true` if the first timestamp is later than the second. op >(Instant, Instant) -> bool; -op >=(u8, u8) -> bool; +op >(int, f32) -> bool; -op >=(i16, i16) -> bool; +op >(int, f64) -> bool; + +op >(f32, int) -> bool; + +op >(f32, f32) -> bool; + +op >(f64, 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 >=(u32, u32) -> bool; - -op >=(f64, int) -> bool; - -op >=(f32, int) -> bool; - -op >=(u64, u64) -> bool; +op >=(int, f32) -> bool; op >=(int, f64) -> bool; -op >=(u16, u16) -> bool; - -op >=(i32, i32) -> bool; +op >=(f32, int) -> bool; op >=(f32, f32) -> bool; -op >=(int, f32) -> bool; - -op >=(u128, u128) -> bool; - -op >=(i8, i8) -> bool; +op >=(f64, int) -> bool; op >=(i128, i128) -> bool; -op >>(u128, int) -> u128; +op >=(i16, i16) -> bool; -op >>(i32, int) -> i32; +op >=(i32, i32) -> bool; -op >>(u32, int) -> u32; +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 >>(i16, int) -> i16; +op >>(u128, int) -> u128; op >>(u16, int) -> u16; -op >>(u8, int) -> u8; +op >>(u32, int) -> u32; op >>(u64, int) -> u64; +op >>(u8, int) -> u8; + /// Return the natural number _e_. fn E() -> f64; /// Return the number π. fn PI() -> f64; -op ^(u128, u128) -> u128; - op ^(i128, i128) -> i128; -op ^(i8, i8) -> i8; - -op ^(i32, i32) -> i32; - -op ^(u16, u16) -> u16; - -op ^(u64, u64) -> u64; - -op ^(u32, u32) -> u32; - -op ^(u8, u8) -> u8; - 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: f64) -> f64; + /// 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 floating-point number. -fn abs(x: f32) -> f32; +/// 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 absolute value of the floating-point number. -fn abs(x: f64) -> f64; - -/// Return the absolute value of the number. -fn abs(x: i32) -> i32; - /// Return the arc-cosine of the floating-point number, in radians. fn acos(x: float) -> f64; @@ -672,37 +672,6 @@ fn all(array: Array, filter: String) -> bool; /// ``` fn all(array: Array, filter: FnPtr) -> bool; -/// 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) -> (); - -fn append(string: String, 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 append(blob: Blob, value: int) -> (); - /// Add all the elements of another array to the end of the array. /// /// # Example @@ -717,6 +686,20 @@ fn append(blob: Blob, value: int) -> (); /// ``` 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 @@ -743,6 +726,23 @@ fn append(blob: Blob, character: char) -> (); /// ``` 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. @@ -788,32 +788,6 @@ fn atanh(x: float) -> f64; /// ``` fn bits(value: int) -> 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 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 the bits in the number starting from the specified `start` position. /// /// If `start` < 0, position counts from the MSB (Most Significant Bit)>. @@ -829,6 +803,32 @@ fn bits(value: int, range: Range) -> Iterator; /// ``` 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)>. @@ -917,17 +917,6 @@ fn chars(string: String) -> Iterator; /// ``` fn chars(string: String, from: int) -> 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 an exclusive range of characters in the string. /// /// # Example @@ -939,6 +928,17 @@ fn chars(string: String, range: RangeInclusive) -> Iterator; /// ``` 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). @@ -998,18 +998,18 @@ fn chop(array: Array, len: int) -> (); /// ``` fn chop(blob: Blob, len: int) -> (); -/// Clear the string, making it empty. -fn clear(string: String) -> (); +/// Clear the array. +fn clear(array: Array) -> (); /// Clear the BLOB. fn clear(blob: Blob) -> (); -/// Clear the array. -fn clear(array: Array) -> (); - /// 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, @@ -1035,6 +1035,32 @@ fn cos(x: float) -> f64; /// Return the hyperbolic cosine of the floating-point number in radians. fn cosh(x: float) -> f64; +/// 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). @@ -1056,32 +1082,6 @@ fn cosh(x: float) -> f64; /// ``` fn crop(string: String, start: int) -> (); -/// 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 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 a range. /// /// * If `start` < 0, position counts from the end of the string (`-1` is the last character). @@ -1108,23 +1108,20 @@ fn crop(string: String, start: int, len: int) -> (); /// Return the empty string. fn debug() -> String; -/// Convert the object map into a string. -fn debug(map: Map) -> String; +/// Convert the array into a string. +fn debug(array: Array) -> String; -/// Convert the unit into a string in debug format. -fn debug(unit: ()) -> String; +/// Convert the string into debug format. +fn debug(character: char) -> String; /// Convert the function pointer into a string in debug format. fn debug(f: FnPtr) -> String; -/// Convert the array into a string. -fn debug(array: Array) -> String; +/// Convert the value of the `item` into a string in debug format. +fn debug(item: ?) -> String; -/// Convert the boolean value into a string in debug format. -fn debug(value: bool) -> String; - -/// Convert the string into debug format. -fn debug(character: char) -> String; +/// Convert the object map into a string. +fn debug(map: Map) -> String; /// Convert the value of `number` into a string. fn debug(number: f32) -> String; @@ -1135,8 +1132,11 @@ fn debug(number: f64) -> String; /// Convert the string into debug format. fn debug(string: String) -> String; -/// Convert the value of the `item` into a string in debug format. -fn debug(item: ?) -> String; +/// Convert the unit into a string in debug format. +fn debug(unit: ()) -> String; + +/// Convert the boolean value into a string in debug format. +fn debug(value: bool) -> String; /// Remove duplicated _consecutive_ elements from the array. /// @@ -1206,28 +1206,38 @@ fn dedup(array: Array, comparer: String) -> (); /// ``` fn dedup(array: Array, comparer: FnPtr) -> (); -/// Remove all bytes in the BLOB within an inclusive `range` and return them as a new BLOB. +/// 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 -/// let b1 = blob(); +/// fn small(x) { x < 3 } /// -/// b1 += 1; b1 += 2; b1 += 3; b1 += 4; b1 += 5; +/// fn screen(x, i) { x + i > 5 } /// -/// let b2 = b1.drain(1..=2); +/// let x = [1, 2, 3, 4, 5]; /// -/// print(b1); // prints "[010405]" +/// let y = x.drain("small"); /// -/// print(b2); // prints "[0203]" +/// print(x); // prints "[3, 4, 5]" /// -/// let b3 = b1.drain(2..=2); +/// print(y); // prints "[1, 2]" /// -/// print(b1); // prints "[0104]" +/// let z = x.drain("screen"); /// -/// print(b3); // prints "[05]" +/// print(x); // prints "[3, 4]" +/// +/// print(z); // prints "[5]" /// ``` -fn drain(blob: Blob, range: RangeInclusive) -> Blob; +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. @@ -1277,6 +1287,27 @@ fn drain(array: Array, filter: FnPtr) -> Array; /// ``` 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 @@ -1300,59 +1331,55 @@ fn drain(array: Array, range: Range) -> Array; /// ``` fn drain(blob: Blob, range: Range) -> Blob; -/// 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 +/// Remove all bytes in the BLOB within an inclusive `range` and return them as a new BLOB. /// /// # Example /// /// ```rhai -/// fn small(x) { x < 3 } +/// let b1 = blob(); /// -/// fn screen(x, i) { x + i > 5 } +/// b1 += 1; b1 += 2; b1 += 3; b1 += 4; b1 += 5; /// -/// let x = [1, 2, 3, 4, 5]; +/// let b2 = b1.drain(1..=2); /// -/// let y = x.drain("small"); +/// print(b1); // prints "[010405]" /// -/// print(x); // prints "[3, 4, 5]" +/// print(b2); // prints "[0203]" /// -/// print(y); // prints "[1, 2]" +/// let b3 = b1.drain(2..=2); /// -/// let z = x.drain("screen"); +/// print(b1); // prints "[0104]" /// -/// print(x); // prints "[3, 4]" -/// -/// print(z); // prints "[5]" +/// print(b3); // prints "[05]" /// ``` -fn drain(array: Array, filter: String) -> Array; +fn drain(blob: Blob, range: RangeInclusive) -> Blob; -/// Remove all elements in the array within an inclusive `range` and return them as a new array. +/// 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); +/// let y = x.drain(1, 2); /// /// print(x); // prints "[1, 4, 5]" /// /// print(y); // prints "[2, 3]" /// -/// let z = x.drain(2..=2); +/// let z = x.drain(-1, 1); /// /// print(x); // prints "[1, 4]" /// /// print(z); // prints "[5]" /// ``` -fn drain(array: Array, range: RangeInclusive) -> Array; +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. /// @@ -1383,33 +1410,6 @@ fn drain(array: Array, range: RangeInclusive) -> Array; /// ``` fn drain(blob: Blob, start: int, len: int) -> 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; - /// Return the number of seconds between the current system time and the timestamp. /// /// # Example @@ -1423,12 +1423,12 @@ fn drain(array: Array, start: int, len: int) -> Array; /// ``` fn elapsed(timestamp: Instant) -> RhaiResult; -/// Return the end of the inclusive range. -fn end(range: InclusiveRange) -> i64; - /// Return the end of the exclusive range. fn end(range: ExclusiveRange) -> i64; +/// Return the end of the inclusive range. +fn end(range: InclusiveRange) -> i64; + /// Return `true` if the string ends with a specified string. /// /// # Example @@ -1445,6 +1445,32 @@ fn ends_with(string: String, match_string: String) -> bool; /// Return the exponential of the floating-point number. fn exp(x: float) -> f64; +/// 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. /// @@ -1465,6 +1491,36 @@ fn exp(x: float) -> f64; /// ``` 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. /// @@ -1487,62 +1543,6 @@ fn extract(array: Array, start: int) -> Array; /// ``` fn extract(blob: Blob, start: int) -> Blob; -/// 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 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 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 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 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). @@ -1602,6 +1602,29 @@ fn extract(blob: Blob, start: int, len: int) -> Blob; /// ``` 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. /// @@ -1629,35 +1652,31 @@ fn fill_with(map: Map, map2: Map) -> (); /// ``` fn filter(array: Array, filter_func: String) -> Array; -/// 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; - /// Return the largest whole number less than or equals to the floating-point number. fn floor(x: float) -> f64; /// Return the fractional part of the floating-point number. fn fraction(x: float) -> f64; +/// 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). @@ -1679,6 +1698,21 @@ fn fraction(x: float) -> f64; /// ``` fn get(blob: Blob, index: int) -> i64; +/// 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). @@ -1698,40 +1732,6 @@ fn get(blob: Blob, index: int) -> i64; /// ``` fn get(string: String, index: 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 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) -> ?; - /// Return an iterator over all the bits in the number. /// /// # Example @@ -1810,41 +1810,41 @@ fn get int(x: float) -> f64; fn get is_anonymous(fn_ptr: FnPtr) -> 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: u32) -> 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: u16) -> 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: u64) -> bool; +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: u8) -> 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: int) -> bool; +fn get is_even(x: i32) -> bool; -/// Return `true` if the range is exclusive. -fn get is_exclusive(range: InclusiveRange) -> 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; @@ -1860,47 +1860,56 @@ 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: u128) -> 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: i8) -> 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: i32) -> 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: int) -> bool; /// Return true if the number is odd. -fn get is_odd(x: u8) -> bool; +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: i128) -> bool; +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: f64) -> 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: u32) -> bool; - -/// Return true if the number is zero. -fn get is_zero(x: u64) -> bool; +fn get is_zero(x: i8) -> bool; /// Return true if the number is zero. fn get is_zero(x: u128) -> bool; @@ -1909,34 +1918,14 @@ fn get is_zero(x: u128) -> bool; fn get is_zero(x: u16) -> bool; /// Return true if the number is zero. -fn get is_zero(x: i8) -> bool; - -/// Return true if the floating-point number is zero. -fn get is_zero(x: f32) -> bool; +fn get is_zero(x: u32) -> bool; /// Return true if the number is zero. -fn get is_zero(x: i16) -> bool; +fn get is_zero(x: u64) -> bool; /// Return true if the number is zero. fn get is_zero(x: u8) -> 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: int) -> bool; - -/// Return the length of the string, in number of characters. -/// -/// # Example -/// -/// ```rhai -/// let text = "朝には紅顔ありて夕べには白骨となる"; -/// -/// print(text.len); // prints 17 -/// ``` -fn get len(string: String) -> i64; - /// Number of elements in the array. fn get len(array: Array) -> i64; @@ -1953,6 +1942,17 @@ fn get len(array: Array) -> i64; /// ``` fn get len(blob: Blob) -> i64; +/// Return the length of the string, in number of characters. +/// +/// # Example +/// +/// ```rhai +/// let text = "朝には紅顔ありて夕べには白骨となる"; +/// +/// print(text.len); // prints 17 +/// ``` +fn get len(string: String) -> i64; + /// Return the name of the function. /// /// # Example @@ -2078,20 +2078,6 @@ fn hypot(x: float, y: float) -> f64; /// ``` fn index_of(array: Array, filter: String) -> 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) -> i64; - /// 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. @@ -2114,20 +2100,6 @@ fn index_of(string: String, character: char) -> i64; /// ``` fn index_of(array: Array, filter: FnPtr) -> 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) -> i64; - /// Find the first element in the array that equals a particular `value` and return its index. /// If no element equals `value`, `-1` is returned. /// @@ -2147,37 +2119,33 @@ fn index_of(string: String, find_string: String) -> i64; /// ``` fn index_of(array: Array, value: ?) -> 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 +/// 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 x = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 5]; +/// let text = "hello, world!"; /// -/// print(x.index_of(|v| v > 1, 3)); // prints 5: 2 > 1 +/// print(text.index_of('l')); // prints 2 (first index) /// -/// 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 +/// print(text.index_of('x')); // prints -1 /// ``` -fn index_of(array: Array, filter: FnPtr, start: int) -> int; +fn index_of(string: String, character: char) -> i64; + +/// 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) -> i64; /// 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 @@ -2219,26 +2187,37 @@ fn index_of(array: Array, filter: FnPtr, start: int) -> int; /// ``` fn index_of(array: Array, filter: String, 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. +/// 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 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. +/// * 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 text = "hello, world! hello, foobar!"; +/// let x = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 5]; /// -/// print(text.index_of("ll", 5)); // prints 16 (first index after 5) +/// print(x.index_of(|v| v > 1, 3)); // prints 5: 2 > 1 /// -/// print(text.index_of("ll", -15)); // prints 16 +/// print(x.index_of(|v| v < 2, 9)); // prints -1: nothing < 2 past index 9 /// -/// print(text.index_of("xx", 0)); // prints -1 +/// 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(string: String, find_string: String, start: int) -> i64; +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. @@ -2290,24 +2269,26 @@ fn index_of(array: Array, value: ?, start: int) -> int; /// ``` fn index_of(string: String, character: char, start: int) -> i64; -/// Add a byte `value` to the BLOB at a particular `index` position. +/// 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 `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. +/// * 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 b = blob(5, 0x42); +/// let text = "hello, world! hello, foobar!"; /// -/// b.insert(2, 0x18); +/// print(text.index_of("ll", 5)); // prints 16 (first index after 5) /// -/// print(b); // prints "[4242184242]" +/// print(text.index_of("ll", -15)); // prints 16 +/// +/// print(text.index_of("xx", 0)); // prints -1 /// ``` -fn insert(blob: Blob, index: int, value: int) -> (); +fn index_of(string: String, find_string: String, start: int) -> i64; /// Add a new element into the array at a particular `index` position. /// @@ -2330,6 +2311,25 @@ fn insert(blob: Blob, index: int, value: int) -> (); /// ``` 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) -> f64; @@ -2345,7 +2345,19 @@ fn int(x: float) -> f64; fn is_anonymous(fn_ptr: FnPtr) -> bool; /// Return true if the number is even. -fn is_even(x: u64) -> bool; +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; @@ -2353,27 +2365,15 @@ 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: i8) -> 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: u32) -> 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: i16) -> bool; +fn is_even(x: u64) -> bool; /// Return true if the number is even. fn is_even(x: u8) -> bool; -/// Return true if the number is even. -fn is_even(x: i128) -> bool; - /// Return `true` if the range is exclusive. fn is_exclusive(range: ExclusiveRange) -> bool; @@ -2396,20 +2396,26 @@ fn is_infinite(x: float) -> bool; fn is_nan(x: float) -> 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: u8) -> bool; +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: int) -> bool; +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; @@ -2417,37 +2423,16 @@ fn is_odd(x: u32) -> bool; fn is_odd(x: u64) -> 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: i8) -> bool; - -/// Return true if the number is odd. -fn is_odd(x: u16) -> bool; +fn is_odd(x: u8) -> 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: i32) -> bool; - -/// Return true if the floating-point number is zero. -fn is_zero(x: f64) -> 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: u16) -> bool; +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 number is zero. -fn is_zero(x: u64) -> bool; - -/// Return true if the number is zero. -fn is_zero(x: u128) -> bool; +/// Return true if the floating-point number is zero. +fn is_zero(x: f64) -> bool; /// Return true if the number is zero. fn is_zero(x: i128) -> bool; @@ -2456,10 +2441,25 @@ fn is_zero(x: i128) -> bool; fn is_zero(x: i16) -> bool; /// Return true if the number is zero. -fn is_zero(x: u8) -> bool; +fn is_zero(x: i32) -> bool; /// Return true if the number is zero. -fn is_zero(x: int) -> bool; +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. /// @@ -2472,9 +2472,6 @@ fn is_zero(x: int) -> bool; /// ``` fn keys(map: Map) -> Array; -/// Return the number of properties in the object map. -fn len(map: Map) -> i64; - /// Number of elements in the array. fn len(array: Array) -> i64; @@ -2491,6 +2488,9 @@ fn len(array: Array) -> i64; /// ``` fn len(blob: Blob) -> i64; +/// Return the number of properties in the object map. +fn len(map: Map) -> i64; + /// Return the length of the string, in number of characters. /// /// # Example @@ -2511,19 +2511,6 @@ fn log(x: float) -> f64; /// Return the log of the floating-point number with `base`. fn log(x: float, base: float) -> f64; -/// 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 lower-case. /// /// # Example @@ -2537,6 +2524,19 @@ fn make_lower(string: String) -> (); /// ``` 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 @@ -2563,29 +2563,6 @@ fn make_upper(character: char) -> (); /// ``` fn make_upper(string: String) -> (); -/// 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; - /// 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. /// @@ -2615,6 +2592,29 @@ fn map(array: Array, mapper: FnPtr) -> Array; /// ``` 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. /// @@ -2662,25 +2662,6 @@ fn name(fn_ptr: FnPtr) -> String; /// ``` fn pad(array: Array, len: int, item: ?) -> (); -/// 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 BLOB to at least the specified length with copies of a specified byte `value`. /// /// If `len` ≤ length of BLOB, no padding is done. @@ -2702,6 +2683,25 @@ fn pad(string: String, len: int, character: char) -> (); /// ``` 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. @@ -2871,23 +2871,6 @@ fn parse_le_float(blob: Blob, range: RangeInclusive) -> f64; /// * 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) -> f64; -/// 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) -> i64; - /// Parse the bytes within an exclusive `range` in the BLOB as an `INT` /// in little-endian byte order. /// @@ -2905,6 +2888,23 @@ fn parse_le_int(blob: Blob, range: RangeInclusive) -> i64; /// ``` fn parse_le_int(blob: Blob, range: Range) -> i64; +/// 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) -> i64; + /// Parse the bytes beginning at the `start` position in the BLOB as an `INT` /// in little-endian byte order. /// @@ -2928,20 +2928,20 @@ fn parse_le_int(blob: Blob, range: Range) -> i64; /// ``` fn parse_le_int(blob: Blob, start: int, len: int) -> i64; -/// Remove the last character from the string and return it. +/// Remove the last element from the array and return it. /// -/// If the string is empty, `()` is returned. +/// If the array is empty, `()` is returned. /// /// # Example /// /// ```rhai -/// let text = "hello, world!"; +/// let x = [1, 2, 3]; /// -/// print(text.pop()); // prints '!' +/// print(x.pop()); // prints 3 /// -/// print(text); // prints "hello, world" +/// print(x); // prints "[1, 2]" /// ``` -fn pop(string: String) -> ?; +fn pop(array: Array) -> ?; /// Remove the last byte from the BLOB and return it. /// @@ -2960,20 +2960,20 @@ fn pop(string: String) -> ?; /// ``` fn pop(blob: Blob) -> i64; -/// Remove the last element from the array and return it. +/// Remove the last character from the string and return it. /// -/// If the array is empty, `()` is returned. +/// If the string is empty, `()` is returned. /// /// # Example /// /// ```rhai -/// let x = [1, 2, 3]; +/// let text = "hello, world!"; /// -/// print(x.pop()); // prints 3 +/// print(text.pop()); // prints '!' /// -/// print(x); // prints "[1, 2]" +/// print(text); // prints "hello, world" /// ``` -fn pop(array: Array) -> ?; +fn pop(string: String) -> ?; /// Remove a specified number of characters from the end of the string and return it as a /// new string. @@ -2995,32 +2995,32 @@ fn pop(string: String, len: int) -> String; /// Return the empty string. fn print() -> String; -/// Convert the value of the `item` into a string. -fn print(item: ?) -> String; - -/// Return the `string`. -fn print(string: String) -> String; - -/// Convert the value of `number` into a string. -fn print(number: f64) -> String; - -/// Convert the value of `number` into a string. -fn print(number: f32) -> String; - -/// Return the boolean value into a string. -fn print(value: bool) -> String; +/// Convert the array into a string. +fn print(array: Array) -> String; /// Return the character into a string. fn print(character: char) -> String; -/// Convert the array into a string. -fn print(array: Array) -> String; +/// Convert the value of the `item` into a string. +fn print(item: ?) -> String; + +/// Convert the object map into a string. +fn print(map: Map) -> String; + +/// Convert the value of `number` into a string. +fn print(number: f32) -> String; + +/// Convert the value of `number` into a string. +fn print(number: f64) -> String; + +/// Return the `string`. +fn print(string: String) -> String; /// Return the empty string. fn print(unit: ()) -> String; -/// Convert the object map into a string. -fn print(map: Map) -> String; +/// Return the boolean value into a string. +fn print(value: bool) -> String; /// Add a new element, which is not another array, to the end of the array. /// @@ -3065,26 +3065,44 @@ fn push(blob: Blob, value: int) -> (); /// ``` fn range(from: i128, to: 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. +/// 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 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) { +/// // prints all values from 8 to 17 +/// for n in range(8, 18) { /// print(n); /// } /// ``` -fn range(range: Range, step: i128) -> Iterator; +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: i64, to: i64) -> Iterator; /// Return an iterator over the exclusive range of `from..to`. /// The value `to` is never included. @@ -3099,27 +3117,6 @@ fn range(range: Range, step: i128) -> Iterator; /// ``` fn range(from: i8, to: 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: i8) -> Iterator; - /// Return an iterator over the exclusive range of `from..to`. /// The value `to` is never included. /// @@ -3133,26 +3130,18 @@ fn range(range: Range, step: i8) -> Iterator; /// ``` fn range(from: u128, to: 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. +/// 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 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) { +/// // prints all values from 8 to 17 +/// for n in range(8, 18) { /// print(n); /// } /// ``` -fn range(range: Range, step: u64) -> Iterator; +fn range(from: u16, to: u16) -> Iterator; /// Return an iterator over the exclusive range of `from..to`. /// The value `to` is never included. @@ -3165,7 +3154,33 @@ fn range(range: Range, step: u64) -> Iterator; /// print(n); /// } /// ``` -fn range(from: i64, to: i64) -> Iterator; +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`. /// @@ -3188,18 +3203,68 @@ fn range(from: i64, to: i64) -> Iterator; /// ``` fn range(range: Range, step: float) -> Iterator; -/// Return an iterator over the exclusive range of `from..to`. -/// The value `to` is never included. +/// 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 -/// for n in range(8, 18) { +/// // 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) -> Iterator; +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`. /// @@ -3241,156 +3306,7 @@ fn range(range: Range, step: i64) -> Iterator; /// print(n); /// } /// ``` -fn range(range: Range, step: 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: u16, to: 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: 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: u64, to: 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: 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: u32, to: 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: 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: 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: 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: u8) -> Iterator; +fn range(range: Range, step: i8) -> Iterator; /// Return an iterator over an exclusive range, each iteration increasing by `step`. /// @@ -3413,27 +3329,89 @@ fn range(range: Range, step: u8) -> Iterator; /// ``` fn range(range: Range, step: u128) -> Iterator; -/// Return an iterator over the exclusive range of `from..to`, each iteration increasing by `step`. -/// The value `to` is never included. +/// Return an iterator over an exclusive range, each iteration increasing by `step`. /// -/// If `from` > `to` and `step` < 0, iteration goes backwards. +/// If `range` is reversed and `step` < 0, iteration goes backwards. /// -/// If `from` > `to` and `step` > 0 or `from` < `to` and `step` < 0, an empty iterator is returned. +/// 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) { +/// 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) { +/// for n in range(18..8, -3) { /// print(n); /// } /// ``` -fn range(from: i16, to: i16, step: i16) -> Iterator; +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. @@ -3455,7 +3433,7 @@ fn range(from: i16, to: i16, step: i16) -> Iterator; /// print(n); /// } /// ``` -fn range(from: u32, to: u32, step: u32) -> Iterator; +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. @@ -3499,29 +3477,7 @@ fn range(from: i128, to: i128, step: i128) -> Iterator; /// 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: u64, to: u64, step: u64) -> Iterator; +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. @@ -3567,50 +3523,6 @@ fn range(from: i32, to: i32, step: i32) -> Iterator; /// ``` fn range(from: i64, to: i64, step: i64) -> 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: u8, to: u8, step: u8) -> Iterator; - /// Return an iterator over the exclusive range of `from..to`, each iteration increasing by `step`. /// The value `to` is never included. /// @@ -3653,30 +3565,95 @@ fn range(from: i8, to: i8, step: i8) -> Iterator; /// print(n); /// } /// ``` -fn range(from: float, to: float, step: float) -> Iterator; +fn range(from: u128, to: u128, step: u128) -> Iterator; -/// Reduce an array by iterating through all elements while applying the `reducer` function. +/// Return an iterator over the exclusive range of `from..to`, each iteration increasing by `step`. +/// The value `to` is never included. /// -/// # Function Parameters +/// If `from` > `to` and `step` < 0, iteration goes backwards. /// -/// * `result`: accumulated result, initially `()` -/// * `element`: copy of array element -/// * `index` _(optional)_: current index in the array +/// If `from` > `to` and `step` > 0 or `from` < `to` and `step` < 0, an empty iterator is returned. /// /// # Example /// /// ```rhai -/// let x = [1, 2, 3, 4, 5]; +/// // prints all values from 8 to 17 in steps of 3 +/// for n in range(8, 18, 3) { +/// print(n); +/// } /// -/// 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 +/// // prints all values down from 18 to 9 in steps of -3 +/// for n in range(18, 8, -3) { +/// print(n); +/// } /// ``` -fn reduce(array: Array, reducer: FnPtr) -> RhaiResult; +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`. /// @@ -3714,7 +3691,7 @@ fn reduce(array: Array, reducer: String) -> RhaiResult; /// /// # Function Parameters /// -/// * `result`: accumulated result, starting with the value of `initial` +/// * `result`: accumulated result, initially `()` /// * `element`: copy of array element /// * `index` _(optional)_: current index in the array /// @@ -3723,15 +3700,15 @@ fn reduce(array: Array, reducer: String) -> RhaiResult; /// ```rhai /// let x = [1, 2, 3, 4, 5]; /// -/// let y = x.reduce(|r, v| v + r, 5); +/// let y = x.reduce(|r, v| v + (r ?? 0)); /// -/// print(y); // prints 20 +/// print(y); // prints 15 /// -/// let y = x.reduce(|r, v, i| v + i + r, 5); +/// let y = x.reduce(|r, v, i| v + i + (r ?? 0)); /// -/// print(y); // prints 30 +/// print(y); // prints 25 /// ``` -fn reduce(array: Array, reducer: FnPtr, initial: ?) -> RhaiResult; +fn reduce(array: Array, reducer: FnPtr) -> RhaiResult; /// Reduce an array by iterating through all elements while applying a function named by `reducer`. /// @@ -3762,6 +3739,29 @@ fn reduce(array: Array, reducer: FnPtr, initial: ?) -> RhaiResult; /// ``` 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`. /// @@ -3819,30 +3819,6 @@ fn reduce_rev(array: Array, reducer: String) -> RhaiResult; /// ``` fn reduce_rev(array: Array, reducer: FnPtr) -> 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; - /// Reduce an array by iterating through all elements, in _reverse_ order, /// while applying a function named by `reducer`. /// @@ -3873,35 +3849,50 @@ fn reduce_rev(array: Array, reducer: FnPtr, initial: ?) -> RhaiResult; /// ``` fn reduce_rev(array: Array, reducer: String, initial: ?) -> RhaiResult; -/// Remove all occurrences of a sub-string from the string. +/// 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 text = "hello, world! hello, foobar!"; +/// let x = [1, 2, 3, 4, 5]; /// -/// text.remove("hello"); +/// let y = x.reduce_rev(|r, v| v + r, 5); /// -/// print(text); // prints ", world! , foobar!" +/// print(y); // prints 20 +/// +/// let y = x.reduce_rev(|r, v, i| v + i + r, 5); +/// +/// print(y); // prints 30 /// ``` -fn remove(string: String, sub_string: String) -> (); +fn reduce_rev(array: Array, reducer: FnPtr, initial: ?) -> RhaiResult; -/// Remove any property of the specified `name` from the object map, returning its value. +/// Remove the element at the specified `index` from the array and return it. /// -/// If the property does not exist, `()` is returned. +/// * 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 m = #{a:1, b:2, c:3}; +/// let x = [1, 2, 3]; /// -/// let x = m.remove("b"); +/// print(x.remove(1)); // prints 2 /// -/// print(x); // prints 2 +/// print(x); // prints "[1, 3]" /// -/// print(m); // prints "#{a:1, c:3}" +/// print(x.remove(-2)); // prints 1 +/// +/// print(x); // prints "[3]" /// ``` -fn remove(map: Map, property: String) -> ?; +fn remove(array: Array, index: int) -> ?; /// Remove the byte at the specified `index` from the BLOB and return it. /// @@ -3926,26 +3917,22 @@ fn remove(map: Map, property: String) -> ?; /// ``` fn remove(blob: Blob, index: int) -> i64; -/// Remove the element at the specified `index` from the array and return it. +/// Remove any property of the specified `name` from the object map, returning its value. /// -/// * 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. +/// If the property does not exist, `()` is returned. /// /// # Example /// /// ```rhai -/// let x = [1, 2, 3]; +/// let m = #{a:1, b:2, c:3}; /// -/// print(x.remove(1)); // prints 2 +/// let x = m.remove("b"); /// -/// print(x); // prints "[1, 3]" +/// print(x); // prints 2 /// -/// print(x.remove(-2)); // prints 1 -/// -/// print(x); // prints "[3]" +/// print(m); // prints "#{a:1, c:3}" /// ``` -fn remove(array: Array, index: int) -> ?; +fn remove(map: Map, property: String) -> ?; /// Remove all occurrences of a character from the string. /// @@ -3960,6 +3947,19 @@ fn remove(array: Array, index: int) -> ?; /// ``` 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 @@ -3973,6 +3973,19 @@ fn remove(string: String, character: char) -> (); /// ``` 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 @@ -3999,41 +4012,38 @@ fn replace(string: String, find_string: String, substitute_character: char) -> ( /// ``` fn replace(string: String, find_string: String, substitute_string: String) -> (); -/// Replace all occurrences of the specified character in the string with another 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 -/// let text = "hello, world! hello, foobar!"; +/// fn large(x) { x >= 3 } /// -/// text.replace('l', "(^)"); +/// fn screen(x, i) { x + i <= 5 } /// -/// print(text); // prints "he(^)(^)o, wor(^)d! he(^)(^)o, foobar!" +/// 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 replace(string: String, find_character: char, substitute_string: String) -> (); - -/// 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; +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. @@ -4083,6 +4093,27 @@ fn retain(array: Array, filter: FnPtr) -> Array; /// ``` 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 @@ -4106,59 +4137,55 @@ fn retain(array: Array, range: Range) -> Array; /// ``` fn retain(blob: Blob, range: Range) -> Blob; -/// 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 +/// Remove all bytes in the BLOB not within an inclusive `range` and return them as a new BLOB. /// /// # Example /// /// ```rhai -/// fn large(x) { x >= 3 } +/// let b1 = blob(); /// -/// fn screen(x, i) { x + i <= 5 } +/// b1 += 1; b1 += 2; b1 += 3; b1 += 4; b1 += 5; /// -/// let x = [1, 2, 3, 4, 5]; +/// let b2 = b1.retain(1..=3); /// -/// let y = x.retain("large"); +/// print(b1); // prints "[020304]" /// -/// print(x); // prints "[3, 4, 5]" +/// print(b2); // prints "[0105]" /// -/// print(y); // prints "[1, 2]" +/// let b3 = b1.retain(1..=2); /// -/// let z = x.retain("screen"); +/// print(b1); // prints "[0304]" /// -/// print(x); // prints "[3, 4]" -/// -/// print(z); // prints "[5]" +/// print(b2); // prints "[01]" /// ``` -fn retain(array: Array, filter: String) -> Array; +fn retain(blob: Blob, range: RangeInclusive) -> Blob; -/// Remove all elements in the array not within an inclusive `range` and return them as a new array. +/// 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..=3); +/// let y = x.retain(1, 2); /// -/// print(x); // prints "[2, 3, 4]" +/// print(x); // prints "[2, 3]" /// -/// print(y); // prints "[1, 5]" +/// print(y); // prints "[1, 4, 5]" /// -/// let z = x.retain(1..=2); +/// let z = x.retain(-1, 1); /// -/// print(x); // prints "[3, 4]" +/// print(x); // prints "[3]" /// -/// print(z); // prints "[1]" +/// print(z); // prints "[2]" /// ``` -fn retain(array: Array, range: RangeInclusive) -> Array; +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. /// @@ -4189,32 +4216,18 @@ fn retain(array: Array, range: RangeInclusive) -> Array; /// ``` fn retain(blob: Blob, start: int, len: int) -> 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. +/// Reverse all the elements in the array. /// /// # Example /// /// ```rhai /// let x = [1, 2, 3, 4, 5]; /// -/// let y = x.retain(1, 2); +/// x.reverse(); /// -/// 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]" +/// print(x); // prints "[5, 4, 3, 2, 1]" /// ``` -fn retain(array: Array, start: int, len: int) -> Array; +fn reverse(array: Array) -> (); /// Reverse the BLOB. /// @@ -4233,66 +4246,34 @@ fn retain(array: Array, start: int, len: int) -> Array; /// ``` fn reverse(blob: 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) -> (); - /// Return the nearest whole number closest to the floating-point number. /// Rounds away from zero. fn round(x: float) -> f64; -/// Set the `index` position in the string to a new `character`. +/// Set the element at the `index` position in the array to a new `value`. /// -/// * 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. +/// * 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 text = "hello, world!"; +/// let x = [1, 2, 3]; /// -/// text.set(3, 'x'); +/// x.set(0, 42); /// -/// print(text); // prints "helxo, world!" +/// print(x); // prints "[42, 2, 3]" /// -/// text.set(-3, 'x'); +/// x.set(-3, 0); /// -/// print(text); // prints "hello, worxd!" +/// print(x); // prints "[0, 2, 3]" /// -/// text.set(99, 'x'); +/// x.set(99, 123); /// -/// print(text); // prints "hello, worxd!" +/// print(x); // prints "[0, 2, 3]" /// ``` -fn set(string: String, index: int, character: char) -> (); - -/// 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: ?) -> (); +fn set(array: Array, index: int, value: ?) -> (); /// Set the particular `index` position in the BLOB to a new byte `value`. /// @@ -4321,30 +4302,49 @@ fn set(map: Map, property: String, value: ?) -> (); /// ``` fn set(blob: Blob, index: int, value: int) -> (); -/// Set the element at the `index` position in the array to a new `value`. +/// Set the value of the `property` in the object map 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. +/// If `property` does not exist in the object map, it is added. /// /// # Example /// /// ```rhai -/// let x = [1, 2, 3]; +/// let m = #{a: 1, b: 2, c: 3}; /// -/// x.set(0, 42); +/// m.set("b", 42)' /// -/// print(x); // prints "[42, 2, 3]" +/// print(m); // prints "#{a: 1, b: 42, c: 3}" /// -/// x.set(-3, 0); +/// x.set("x", 0); /// -/// print(x); // prints "[0, 2, 3]" -/// -/// x.set(99, 123); -/// -/// print(x); // prints "[0, 2, 3]" +/// print(m); // prints "#{a: 1, b: 42, c: 3, x: 0}" /// ``` -fn set(array: Array, index: int, value: ?) -> (); +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. /// @@ -4383,19 +4383,6 @@ fn set tag(value: ?, tag: int) -> (); /// ``` fn set_bit(value: int, bit: int, new_value: bool) -> (); -/// 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 an exclusive range of bits in the number with a new value. /// /// # Example @@ -4409,6 +4396,19 @@ fn set_bits(value: int, range: RangeInclusive, new_value: int) -> (); /// ``` 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). @@ -4443,6 +4443,21 @@ fn set_bits(value: int, bit: int, bits: int, new_value: int) -> (); /// ``` 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. @@ -4460,21 +4475,6 @@ fn set_tag(value: ?, tag: int) -> (); /// ``` fn shift(blob: Blob) -> i64; -/// 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) -> ?; - /// Return the sign (as an integer) of the number according to the following: /// /// * `0` if the number is zero @@ -4482,6 +4482,20 @@ fn shift(array: Array) -> ?; /// * `-1` if the number is negative fn sign(x: int) -> i64; +/// 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: f64) -> int; + /// Return the sign (as an integer) of the number according to the following: /// /// * `0` if the number is zero @@ -4496,20 +4510,6 @@ fn sign(x: i128) -> i64; /// * `-1` if the number is negative fn sign(x: i16) -> i64; -/// 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 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) -> i64; - /// Return the sign (as an integer) of the number according to the following: /// /// * `0` if the number is zero @@ -4517,12 +4517,12 @@ fn sign(x: i8) -> i64; /// * `-1` if the number is negative fn sign(x: i32) -> i64; -/// Return the sign (as an integer) of the floating-point number according to the following: +/// 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: f64) -> int; +fn sign(x: i8) -> i64; /// Return the sine of the floating-point number in radians. fn sin(x: float) -> f64; @@ -4670,33 +4670,19 @@ fn sort(array: Array, comparer: String) -> (); /// ``` fn sort(array: Array, comparer: FnPtr) -> (); -/// Replace an inclusive `range` of the BLOB with another BLOB. +/// Replace an exclusive range of the array with another array. /// /// # Example /// /// ```rhai -/// let b1 = blob(10, 0x42); -/// let b2 = blob(5, 0x18); +/// let x = [1, 2, 3, 4, 5]; +/// let y = [7, 8, 9, 10]; /// -/// b1.splice(1..=4, b2); +/// x.splice(1..3, y); /// -/// print(b1); // prints "[4218181818184242 424242]" +/// print(x); // prints "[1, 7, 8, 9, 10, 4, 5]" /// ``` -fn splice(blob: Blob, range: RangeInclusive, replace: Blob) -> (); - -/// 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) -> (); +fn splice(array: Array, range: Range, replace: Array) -> (); /// Replace an inclusive range of the array with another array. /// @@ -4712,27 +4698,7 @@ fn splice(blob: Blob, range: Range, replace: Blob) -> (); /// ``` fn splice(array: Array, range: RangeInclusive, replace: Array) -> (); -/// 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 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. +/// Replace an exclusive `range` of the BLOB with another BLOB. /// /// # Example /// @@ -4740,15 +4706,25 @@ fn splice(array: Array, range: Range, replace: Array) -> (); /// let b1 = blob(10, 0x42); /// let b2 = blob(5, 0x18); /// -/// b1.splice(1, 3, b2); +/// b1.splice(1..4, 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) -> (); +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. /// @@ -4774,6 +4750,30 @@ fn splice(blob: Blob, start: int, len: int, replace: Blob) -> (); /// ``` 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 @@ -4785,6 +4785,26 @@ fn splice(array: Array, start: int, len: int, replace: Array) -> (); /// ``` 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). @@ -4831,37 +4851,6 @@ fn split(blob: Blob, index: int) -> Blob; /// ``` fn split(string: String, index: int) -> 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; - -/// 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; - /// Split the string into segments based on a `delimiter` string, returning an array of the segments. /// /// # Example @@ -4873,6 +4862,17 @@ fn split(array: Array, index: int) -> Array; /// ``` 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. /// @@ -4956,12 +4956,12 @@ fn split_rev(string: String, delimiter: char, segments: int) -> Array; /// Return the square root of the floating-point number. fn sqrt(x: float) -> f64; -/// Return the start of the inclusive range. -fn start(range: InclusiveRange) -> i64; - /// Return the start of the exclusive range. fn start(range: ExclusiveRange) -> i64; +/// Return the start of the inclusive range. +fn start(range: InclusiveRange) -> i64; + /// Return `true` if the string starts with a specified string. /// /// # Example @@ -5070,34 +5070,34 @@ fn timestamp() -> Instant; fn to_array(blob: Blob) -> Array; /// Convert the `value` into a string in binary format. -fn to_binary(value: i64) -> String; +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: u8) -> String; +fn to_binary(value: i32) -> String; /// 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: u64) -> String; - -/// Convert the `value` into a string in binary format. -fn to_binary(value: u128) -> String; +fn to_binary(value: i64) -> 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: i32) -> String; +fn to_binary(value: u32) -> String; /// Convert the `value` into a string in binary format. -fn to_binary(value: u32) -> String; +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. /// @@ -5123,118 +5123,118 @@ fn to_blob(string: String) -> Blob; /// ``` fn to_chars(string: String) -> Array; -/// Convert the value of `number` into a string. -fn to_debug(number: f64) -> String; - -/// Convert the string into debug format. -fn to_debug(string: String) -> String; - -/// Convert the value of the `item` into a string in debug format. -fn to_debug(item: ?) -> String; - -/// Convert the value of `number` into a string. -fn to_debug(number: f32) -> String; - /// 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 boolean value into a string in debug format. -fn to_debug(value: bool) -> 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: f64) -> 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) -> f64; -fn to_float(x: i32) -> f64; - -fn to_float(x: u32) -> f64; - /// Convert the 32-bit floating-point number to 64-bit. fn to_float(x: f32) -> f64; -fn to_float(x: i8) -> f64; - -fn to_float(x: u16) -> f64; - -fn to_float(x: u128) -> f64; - fn to_float(x: i128) -> f64; -fn to_float(x: u8) -> f64; - fn to_float(x: i16) -> f64; +fn to_float(x: i32) -> f64; + fn to_float(x: i64) -> f64; -/// Convert the `value` into a string in hex format. -fn to_hex(value: i32) -> String; +fn to_float(x: i8) -> f64; -/// Convert the `value` into a string in hex format. -fn to_hex(value: u32) -> String; +fn to_float(x: u128) -> f64; -/// Convert the `value` into a string in hex format. -fn to_hex(value: i8) -> String; +fn to_float(x: u16) -> f64; -/// Convert the `value` into a string in hex format. -fn to_hex(value: u16) -> String; +fn to_float(x: u32) -> f64; -/// 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: u64) -> String; +fn to_float(x: u8) -> f64; /// 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: u8) -> String; +fn to_hex(value: i16) -> String; /// Convert the `value` into a string in hex format. -fn to_hex(value: i16) -> String; +fn to_hex(value: i32) -> String; /// Convert the `value` into a string in hex format. fn to_hex(value: i64) -> String; -fn to_int(x: u32) -> i64; +/// 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) -> i64; + +/// 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: f64) -> int; +fn to_int(x: i128) -> i64; + +fn to_int(x: i16) -> i64; + fn to_int(x: i32) -> i64; -fn to_int(x: u64) -> i64; +fn to_int(x: i64) -> i64; + +fn to_int(x: i8) -> i64; fn to_int(x: u128) -> i64; fn to_int(x: u16) -> i64; -fn to_int(x: i8) -> i64; +fn to_int(x: u32) -> i64; -/// Convert the floating-point number into an integer. -fn to_int(x: f32) -> int; - -fn to_int(x: i16) -> i64; +fn to_int(x: u64) -> i64; fn to_int(x: u8) -> i64; -fn to_int(x: char) -> i64; - -fn to_int(x: i128) -> i64; - -fn to_int(x: i64) -> i64; - /// Return the JSON representation of the object map. /// /// # Data types @@ -5289,71 +5289,58 @@ fn to_octal(value: i128) -> String; fn to_octal(value: i16) -> String; /// Convert the `value` into a string in octal format. -fn to_octal(value: u8) -> String; +fn to_octal(value: i32) -> String; /// Convert the `value` into a string in octal format. fn to_octal(value: i64) -> String; /// Convert the `value` into a string in octal format. -fn to_octal(value: u32) -> String; +fn to_octal(value: i8) -> String; /// Convert the `value` into a string in octal format. -fn to_octal(value: i32) -> String; +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: i8) -> String; +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: u128) -> String; +fn to_octal(value: u8) -> String; /// Convert degrees to radians. fn to_radians(x: float) -> f64; -/// Return the boolean value into a string. -fn to_string(value: bool) -> String; +/// 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 array into a string. -fn to_string(array: Array) -> 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; -/// Return the empty string. -fn to_string(unit: ()) -> String; - -/// Return the `string`. -fn to_string(string: String) -> String; - -/// Convert the value of the `item` into a string. -fn to_string(item: ?) -> 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: f64) -> String; -/// Convert the value of `number` into a string. -fn to_string(number: f32) -> String; +/// Return the `string`. +fn to_string(string: String) -> String; -/// 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; +/// 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. /// @@ -5368,6 +5355,19 @@ fn to_upper(string: String) -> String; /// ``` 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 @@ -5381,6 +5381,26 @@ fn to_upper(character: char) -> char; /// ``` 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. @@ -5423,26 +5443,6 @@ fn truncate(blob: Blob, len: int) -> (); /// ``` fn truncate(string: String, len: int) -> (); -/// 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) -> (); - /// Return an array with all the property values in the object map. /// /// # Example @@ -5508,13 +5508,6 @@ fn write_ascii(blob: Blob, range: RangeInclusive, string: String) -> (); /// ``` fn write_ascii(blob: Blob, start: int, len: int, string: String) -> (); -/// 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 a `FLOAT` value to the bytes within an exclusive `range` in the BLOB /// in big-endian byte order. /// @@ -5522,6 +5515,28 @@ fn write_be(blob: Blob, range: RangeInclusive, value: float) -> (); /// * 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. /// @@ -5537,20 +5552,18 @@ fn write_be(blob: Blob, range: Range, value: float) -> (); /// ``` fn write_be(blob: Blob, range: RangeInclusive, value: int) -> (); -/// Write an `INT` value to the bytes within an exclusive `range` in the BLOB +/// Write a `FLOAT` value to the bytes beginning at the `start` position 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. +/// * 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. /// -/// ```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) -> (); +/// * 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. @@ -5573,18 +5586,12 @@ fn write_be(blob: Blob, range: Range, value: int) -> (); /// ``` fn write_be(blob: Blob, start: int, len: int, 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. +/// 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_be(blob: Blob, start: int, len: int, value: float) -> (); +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. @@ -5601,6 +5608,13 @@ fn write_be(blob: Blob, start: int, len: int, value: float) -> (); /// ``` 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. /// @@ -5616,20 +5630,6 @@ fn write_le(blob: Blob, range: Range, value: int) -> (); /// ``` fn write_le(blob: Blob, range: RangeInclusive, 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 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 a `FLOAT` value to the bytes beginning at the `start` position in the BLOB /// in little-endian byte order. /// @@ -5712,20 +5712,20 @@ fn write_utf8(blob: Blob, range: RangeInclusive, string: String) -> (); /// ``` fn write_utf8(blob: Blob, start: int, len: int, string: String) -> (); -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 |(i32, i32) -> i32; - -op |(u16, u16) -> u16; - -op |(u128, u128) -> u128; - -op |(i8, i8) -> i8; - -op |(i128, i128) -> i128; \ No newline at end of file +op |(u8, u8) -> u8; \ No newline at end of file From 4bc2079bd6992bda4655b5d246125069675ac53f Mon Sep 17 00:00:00 2001 From: tamasfe Date: Tue, 26 Jul 2022 15:10:39 +0200 Subject: [PATCH 11/11] fix(defs): builtin operator fixes --- .../.rhai/definitions/__builtin-operators__.d.rhai | 4 ++-- src/api/definitions/builtin-operators.d.rhai | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/definitions/.rhai/definitions/__builtin-operators__.d.rhai b/examples/definitions/.rhai/definitions/__builtin-operators__.d.rhai index 51bdb0e2..4a5bdfd6 100644 --- a/examples/definitions/.rhai/definitions/__builtin-operators__.d.rhai +++ b/examples/definitions/.rhai/definitions/__builtin-operators__.d.rhai @@ -242,8 +242,8 @@ op -=(String, char); op +=(char, String); op +=(char, char); -op +=(arraArray, Array); -op +=(arraArray, ?); +op +=(Array, Array); +op +=(Array, ?); op +=(Blob, Blob); op +=(Blob, i64); diff --git a/src/api/definitions/builtin-operators.d.rhai b/src/api/definitions/builtin-operators.d.rhai index 51bdb0e2..4a5bdfd6 100644 --- a/src/api/definitions/builtin-operators.d.rhai +++ b/src/api/definitions/builtin-operators.d.rhai @@ -242,8 +242,8 @@ op -=(String, char); op +=(char, String); op +=(char, char); -op +=(arraArray, Array); -op +=(arraArray, ?); +op +=(Array, Array); +op +=(Array, ?); op +=(Blob, Blob); op +=(Blob, i64);