Skip to content

feat: Add optional arguments to script functions #225

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

Merged
merged 3 commits into from
Jan 25, 2025

Conversation

makspll
Copy link
Owner

@makspll makspll commented Jan 25, 2025

Adds support for non-required arguments, with default values passed in during a call:

    #[test]
    fn test_optional_argument_not_required() {
        let fn_ = |a: usize, b: Option<usize>| a + b.unwrap_or(0);
        let script_function = fn_.into_dynamic_script_function();

        with_local_world(|| {
            let out = script_function
                .call(vec![ScriptValue::from(1)], FunctionCallContext::default())
                .unwrap();

            assert_eq!(out, ScriptValue::from(1));
        });
    }

Also bumps rhai version to actual release

@makspll makspll merged commit dbfef74 into staging Jan 25, 2025
14 checks passed
@makspll makspll deleted the feat/optional-arguments branch January 25, 2025 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant