Add Dynamic::is_XXX API.

This commit is contained in:
Stephen Chung
2022-11-09 12:44:57 +08:00
parent ad018aaae3
commit ce046422f0
22 changed files with 327 additions and 91 deletions

View File

@@ -39,7 +39,7 @@ pub fn print_with_func(
value: &mut Dynamic,
) -> crate::ImmutableString {
match ctx.call_native_fn_raw(fn_name, true, &mut [value]) {
Ok(result) if result.is::<crate::ImmutableString>() => {
Ok(result) if result.is_string() => {
result.into_immutable_string().expect("`ImmutableString`")
}
Ok(result) => ctx.engine().map_type_name(result.type_name()).into(),
@@ -75,7 +75,7 @@ mod print_debug_functions {
/// Return the empty string.
#[rhai_fn(name = "print", name = "debug")]
pub fn print_empty_string(ctx: NativeCallContext) -> ImmutableString {
ctx.engine().get_interned_string("")
ctx.engine().const_empty_string()
}
/// Return the `string`.
@@ -121,7 +121,7 @@ mod print_debug_functions {
#[rhai_fn(name = "print", name = "to_string")]
pub fn print_unit(ctx: NativeCallContext, unit: ()) -> ImmutableString {
let _ = unit;
ctx.engine().get_interned_string("")
ctx.engine().const_empty_string()
}
/// Convert the unit into a string in debug format.
#[rhai_fn(name = "debug", name = "to_debug")]