The glue code does look wrong, yes... but oddly this does work. We even
have a test for a static method in the webidl test (tests/webidl/test.idl).
I think what happens is that it's ok to call a static method with any
instance, even NULL. Although it's probably not defined behavior ;)

Sure, this should be fixed, that would be great.

- Alon



On Sat, May 10, 2014 at 12:31 PM, Joseph Adams <[email protected]> wrote:

> Hi,
>
> I was wondering if there was any way to have WebIDL generate bindings for
> static methods? Here is my .idl:
>
> [Prefix="Panther::"]
> interface World {
>
> void addScene(Scene scene);
> Scene getScene(DOMString sceneName);
> Scene removeScene(DOMString sceneName);
> Scene getCurrentScene();
> void transitionScene(DOMString sceneName);
>
> void process();
> void start();
> void pause();
>
> static World getInstance();
> static void processInstance();
> static void setFps(long fps);
> };
>
>
> [Prefix="Panther::"]
> interface Scene {
> };
>
> The three static methods are generated as instance methods. Here is an
> example:
>
> void EMSCRIPTEN_KEEPALIVE emscripten_bind_World_setFps_1(Panther::World*
> self, int arg0) {
>   self->setFps(arg0);
> }
>
> I was able to change the generated code to make these static by editing
> glue.cpp and glue.js to be something like this:
>
> void EMSCRIPTEN_KEEPALIVE emscripten_bind_World_setFps_1(Panther::World*
> self, int arg0) {
>   Panther::World::setFps(arg0);
> }
>
> World.__proto__.setFps = function(arg0) {
>   var self = this.ptr;
>   if (arg0 && typeof arg0 === 'object') arg0 = arg0.ptr;
>   else arg0 = ensureString(arg0);
>   _emscripten_bind_World_setFps_1(self, arg0);
> };
>
>
> Is there any way to generate this? If not, I would be interested in adding
> this feature.
>
> Thanks
>
> Joe
>
> --
> 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 [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to