Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bind C++ enums declared as enum in the IDL file. #2618

Merged
merged 3 commits into from
Aug 7, 2014

Conversation

mlogan
Copy link
Contributor

@mlogan mlogan commented Aug 2, 2014

Tests passed: tests/runner.py test_webidl

@mlogan
Copy link
Contributor Author

mlogan commented Aug 5, 2014

So, it turns out that WebIDL does not allow extended attributes to be specified for enums. This means there is no obvious way to declare enums that are within namespaces or classes.

In turn, this makes me wonder if WebIDL is really a viable option for emscripten bindings in the long run. I don't want to put a lot of effort into this if it's likely to be abandoned.

It would be trivial to modify the WebIDL parser to allow extended attributes on enums, but then we're not using WebIDL, we're using EmIDL, and I don't know if you want to go down that road.

Thoughts?

@mlogan
Copy link
Contributor Author

mlogan commented Aug 5, 2014

There is an OK solution after all:

In the stub file:

typedef MyClass::MyEnum MyClassMyEnum;
#include "glue.cpp"

In the interface file:

enum MyClassMyEnum {
  "MyClass::e_value1",
  "MyClass::e_value2"
};
interface {
  MyClassMyEnum Foo();
};

The typedef allows the generated code to compile without any scope resolution operators. The scope resolutions in the enum values just get written directly into the binding code.

It does require binding authors to add a boilerplate typedef, but at least they aren't manually assigning integer enum values in their js glue (which is horrible).

@kripken
Copy link
Member

kripken commented Aug 7, 2014

That looks like a reasonable approach, nice.

@kripken kripken merged commit 72449f0 into emscripten-core:incoming Aug 7, 2014
@kripken
Copy link
Member

kripken commented Aug 7, 2014

Merged, thanks!

In general, we have already had to add some attributes to WebIDL for things to work. We may need to add more over time, but hopefully will stay close enough to normal WebIDL to be able to use existing IDL files without much conversion.

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