How to write an IDL describing a deeply namespaced enum

34 views
Skip to first unread message

Kristina Chodorow

unread,
Jan 31, 2017, 10:59:17 PM1/31/17
to emscripten-discuss
I'm trying to write an IDL to describe http://bulletphysics.org/Bullet/BulletFull/btSoftBody_8h_source.html#l00486, basically:

class btSoftBody {
  struct Joint {
    struct eType {
      enum _ {
        Linear, Angular, Contact
      };
    };
  };
}; 

However, I can't figure out how to express this in my .idl file. Based on https://kripken.github.io/emscripten-site/docs/porting/connecting_cpp_and_javascript/WebIDL-Binder.html#enums, I tried:

enum btSoftBody_Joint_eType__ {
  "btSoftBody::Joint::eType::Linear",
  "btSoftBody::Joint::eType::Angular",
  "btSoftBody::Joint::eType::Contact"
};

[Prefix="btSoftBody::Joint::"]
interface eType {
};

... // So on for Joint and btSoftBody.

But that gives me:

Traceback (most recent call last):
  File "/Users/k/emsdk_portable/emscripten/incoming/tools/webidl_binder.py", line 709, in <module>
    raise Exception("Illegal enum value %s" % value)

So then I tried:

enum btSoftBody_Joint_eType__ {
  "eType::Linear",
  "eType::Angular",
  "eType::Contact"
};

This gets further (it generates the cpp bindings) but when it tries to compile them, the types don't resolve to anything:

glue.cpp:4539:1: error: unknown type name 'btSoftBody_Joint_eType__'
btSoftBody_Joint_eType__ EMSCRIPTEN_KEEPALIVE emscripten_enum_btSoftBody_Joint_eType___Linear() {
^
glue.cpp:4539:26: error: expected unqualified-id
btSoftBody_Joint_eType__ EMSCRIPTEN_KEEPALIVE emscripten_enum_btSoftBody_Joint_eType___Linear() {
                         ^
/Users/k/emsdk_portable/emscripten/incoming/system/include/emscripten/emscripten.h:64:30: note: expanded from macro 'EMSCRIPTEN_KEEPALIVE'
#define EMSCRIPTEN_KEEPALIVE __attribute__((used))
                             ^
glue.cpp:4542:1: error: unknown type name 'btSoftBody_Joint_eType__'
...

Does anyone know what I'm doing wrong?  Or how to express this?

Alon Zakai

unread,
Feb 1, 2017, 5:19:54 PM2/1/17
to emscripten-discuss
Hmm, this looks like a current limitation of the webidl binder,

https://github.com/kripken/emscripten/blob/master/tools/webidl_binder.py#L695

Seems like it only handles one "::" (or none). In principle it should be straightforward to generalize it, although it has some special logic to check if the name before the "::" is a class or not, and it's not immediately obvious to me how that would work for more elements.

--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-discuss+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Kristina Chodorow

unread,
Feb 2, 2017, 10:26:11 AM2/2/17
to emscripten-discuss

Okay, thanks. It's probably easier just to skip the IDL and write a C++ wrapper directly.


To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "emscripten-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/emscripten-discuss/MUrJ9WbN1oQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to emscripten-disc...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages