Skip to content

feat: Add optional arguments to script functions#225

Merged
makspll merged 3 commits into
stagingfrom
feat/optional-arguments
Jan 25, 2025
Merged

feat: Add optional arguments to script functions#225
makspll merged 3 commits into
stagingfrom
feat/optional-arguments

Conversation

@makspll

@makspll makspll commented Jan 25, 2025

Copy link
Copy Markdown
Owner

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
@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