From 1880f8d56977a942c8f02ade3e33b351886e4a9b Mon Sep 17 00:00:00 2001 From: Katherine Kiefer Date: Mon, 13 Nov 2023 12:29:13 +1100 Subject: [PATCH] is_true --- crates/byondapi-rs/src/typecheck_trait.rs | 2 ++ crates/byondapi-rs/src/value/mod.rs | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/crates/byondapi-rs/src/typecheck_trait.rs b/crates/byondapi-rs/src/typecheck_trait.rs index ae82544..fc78168 100644 --- a/crates/byondapi-rs/src/typecheck_trait.rs +++ b/crates/byondapi-rs/src/typecheck_trait.rs @@ -16,4 +16,6 @@ pub trait ByondTypeCheck { fn is_list(&self) -> bool; /// Check if this is a pointer. fn is_ptr(&self) -> bool; + /// Check if this is true-ish. + fn is_true(&self) -> bool; } diff --git a/crates/byondapi-rs/src/value/mod.rs b/crates/byondapi-rs/src/value/mod.rs index 8c08d04..051837b 100644 --- a/crates/byondapi-rs/src/value/mod.rs +++ b/crates/byondapi-rs/src/value/mod.rs @@ -54,4 +54,9 @@ impl ByondTypeCheck for ByondValue { fn is_ptr(&self) -> bool { is_pointer_shim(self) } + + fn is_true(&self) -> bool { + // Safety: This operation only fails if our CByondValue is invalid, which cannot happen. + unsafe { byond().ByondValue_IsTrue(&self.0) } + } }