Skip to content

Struct constructors work like built-in type constructors.#751

Merged
lgritz merged 1 commit intoAcademySoftwareFoundation:masterfrom
lgritz:lg-structctr
May 17, 2017
Merged

Struct constructors work like built-in type constructors.#751
lgritz merged 1 commit intoAcademySoftwareFoundation:masterfrom
lgritz:lg-structctr

Conversation

@lgritz
Copy link
Copy Markdown
Collaborator

@lgritz lgritz commented May 13, 2017

You know how you can have an expression for a built-in type like color?

foo = color(1,1,1)

or

void func (color c) { ...}
func (color(1,1,1);

It was really awkward to do this with structs.

So with this patch, for every struct, you can construct it by name
with a function-call-like syntax, where the arguments must be the same
types as the data members of the struct, in order.

For example:

struct RGBA {
    color rgb;
    float a;
};

RGBA x = RGBA(color(1,1,1), 1);

void func (RGBA x) { ... }
func (RGBA(Cblah,alpha));

You don't need to explicitly declare the constructor like in C++, it
just exists.

@lgritz
Copy link
Copy Markdown
Collaborator Author

lgritz commented May 17, 2017

So...

You know how you can have an expression for a built-in type like color?

    foo = color(1,1,1)

or

    void func (color c) { ...}
    func (color(1,1,1);

It was really awkward to do this with structs.

So with this patch, for every struct, you can construct it by name
with a function-call-like syntax, where the arguments must be the same
types as the data members of the struct, in order.

For example:

    struct RGBA {
        color rgb;
        float a;
    };

    RGBA x = RGBA(color(1,1,1), 1);

    void func (RGBA x) { ... }
    func (RGBA(Cblah,alpha));

You don't need to explicitly declare the constructor like in C++, it
just exists.
@aconty
Copy link
Copy Markdown
Contributor

aconty commented May 17, 2017

LGTM!

@lgritz lgritz merged commit 01615ad into AcademySoftwareFoundation:master May 17, 2017
@lgritz lgritz deleted the lg-structctr branch May 17, 2017 21:26
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.

2 participants