Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature suggestion. Implement is_XXX functions in the scripting language too #778

Open
bogzbonny opened this issue Nov 8, 2023 · 1 comment

Comments

@bogzbonny
Copy link

I found it a bit confusing to have access to 'is_string()', 'is_int()' etc. in rust but not in rhaiscript... seems a bit cumbersome to have to type a.type_of() = "()" as opposed to just something like a.is_unit() in a script.

I tossed this in my rhai instance:

    #[rhai_fn(pure)]
    pub fn is_unit(inp: &mut Dynamic) -> bool {
        inp.is_unit()
    }

    #[rhai_fn(pure)]
    pub fn is_int(inp: &mut Dynamic) -> bool {
        inp.is_int()
    }

    #[rhai_fn(pure)]
    pub fn is_float(inp: &mut Dynamic) -> bool {
        inp.is_float()
    }

    #[rhai_fn(pure)]
    pub fn is_bool(inp: &mut Dynamic) -> bool {
        inp.is_bool()
    }

    #[rhai_fn(name = "is_string", name = "is_str", pure)]
    pub fn is_string(inp: &mut Dynamic) -> bool {
        inp.is_string()
    }

    #[rhai_fn(pure)]
    pub fn is_char(inp: &mut Dynamic) -> bool {
        inp.is_char()
    }

    #[rhai_fn(pure)]
    pub fn is_array(inp: &mut Dynamic) -> bool {
        inp.is_array()
    }
@schungx
Copy link
Collaborator

schungx commented Nov 8, 2023

I considered this in the beginning but decided against it for the reason that it would introduce a new method of achieving something that can be done in another way.and the is_xxx API would need to be specific to known types.

I'm willing to put them in if enough people lobby for it though... As you know, it only involves defining those simple functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants