Skip to content

Conversation

@Ghabry
Copy link

@Ghabry Ghabry commented Apr 6, 2018

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
Owner

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

@mean-ui-thread
Copy link
Contributor

I want that feature too!

@Ghabry
Copy link
Author

Ghabry commented Apr 12, 2018

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