From 9c3443538a774d821a85954ab6a1df2999070a5a Mon Sep 17 00:00:00 2001 From: ltabis Date: Tue, 23 Aug 2022 16:36:43 +0200 Subject: [PATCH] feat(array): add an `empty` getter for arrays. --- examples/definitions/.rhai/definitions/__static__.d.rhai | 3 +++ src/packages/array_basic.rs | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/examples/definitions/.rhai/definitions/__static__.d.rhai b/examples/definitions/.rhai/definitions/__static__.d.rhai index 108ab58e..a7cf38ef 100644 --- a/examples/definitions/.rhai/definitions/__static__.d.rhai +++ b/examples/definitions/.rhai/definitions/__static__.d.rhai @@ -1973,6 +1973,9 @@ fn get is_zero(x: u8) -> bool; /// Number of elements in the array. fn get len(array: Array) -> int; +/// Return true if the array is empty. +fn get empty(array: Array) -> bool; + /// Return the length of the BLOB. /// /// # Example diff --git a/src/packages/array_basic.rs b/src/packages/array_basic.rs index d0a0b671..dd4f51fc 100644 --- a/src/packages/array_basic.rs +++ b/src/packages/array_basic.rs @@ -30,6 +30,11 @@ pub mod array_functions { pub fn len(array: &mut Array) -> INT { array.len() as INT } + /// Return true if the array is empty. + #[rhai_fn(name = "empty", get = "empty", pure)] + pub fn empty(array: &mut Array) -> bool { + array.len() == 0 + } /// 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).