Skip to content

Add support for static member functions and static properties - #5

Open
Ghabry wants to merge 3 commits into
vmanucharyan:masterfrom
Ghabry:static
Open

Ghabry wants to merge 3 commits into
vmanucharyan:masterfrom
Ghabry:static

Conversation

@Ghabry

@Ghabry Ghabry commented Apr 6, 2018

Copy link
Copy Markdown

Hello.

I'm not completely sure if PushConstructorInspector is a good place for the code but this adds support for static member functions and properties.

The syntax matches the i.method and i.property functions:

class Spaceship {
       [...]
       static std::string name () { return "ship"; }

       static int id;
       static GetId() { return id; }
       static SetId(int _id) { id = _id; }
}

// Inspect:
i.static_method("name", &Spaceship::name);
i.static_property("id", &Spaceship::GetId, &Spaceship::SetId);

// Javascript:
Spaceship.name()
--> "ship"

Spaceship.id = 42
--> <nothing>

Spaceship.id
--> 42

I used "static_"-prefix to make the difference more visual clear because this prevents unintentional bugs.

@vmanucharyan

Copy link
Copy Markdown
Owner

Hi! Thanks for contribution! Could you, please, also add some tests for this?

@mean-ui-thread

Copy link
Copy Markdown

I want that feature too!

@Ghabry

Ghabry commented Apr 12, 2018

Copy link
Copy Markdown
Author

Okay I will try to make up a few tests.
Except for the registration logic in duktape I used the already existing code for argument and return vaule handling, therefore I will keep the test suite small.

@vmanucharyan

Copy link
Copy Markdown
Owner

@Ghabry I think one high level test for property and one for static method will be enough (just check that it is callable from js). lower level logic such as passing around arguments and return values is already tested

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.

3 participants