Skip to content

Default function parameters #381

Open
@you-win

Description

@you-win

Allow for exposing default function parameters to GDScript.

The proposed syntax would look like:

#[godot_api]
impl MyType {
    #[func(defaults = [ 1 ]]
    fn some_func(a: Option<i32>) -> i32 {
        a.unwrap_or(1)
    }
}

This would map roughly to this in C++:

ClassDB::bind_method(D_METHOD("some_func", "a"), &MyType::some_func, DEFVAL(1));

Ideally the macro would also allow for function calls from Godot to automatically insert the default parameters as well so that Option<T> is not required, but I'm not sure if that's feasible.

WIP in #380

Metadata

Metadata

Assignees

No one assigned

    Labels

    c: registerRegister classes, functions and other symbols to GDScriptfeatureAdds functionality to the library

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions