vvuk / idlebind

WebIDL to Emscripten bindings generator
MIT License
1 stars 1 forks source link

calling static method from javascript #1

Open timotheecour opened 6 years ago

timotheecour commented 6 years ago

pasting my example form https://github.com/kripken/emscripten/issues/6742

related: how to call a static method without a class instance in webIDL?
/// funs.cpp
class A{
  static void fun();
};
/// funs.idl
interface A{
  static void fun();
}
/// test.js
Module.A.fun(); // doesn't work
new Module.A().fun(); // works but shouldn't be necessary to have an instance since it's a static method

when using tools/webidl_binder.py as recommended in https://kripken.github.io/emscripten-site/docs/porting/connecting_cpp_and_javascript/WebIDL-Binder.html , calling Module.A.fun(); from javascript doesn't work ; however I see from your examples ClassA.StaticMethod(); in idlebind/test/test.js

is that a difference between idlebind and tools/webidl_binder.py ? what other differences are there? are free functions (not inside a class) supported (cf other part of https://github.com/kripken/emscripten/issues/6742 ) ?

Becavalier commented 6 years ago

As I said in kripken/emscripten#6742, You can try calling the function through the prototype of the corresponding object in JavaScript:

FYI: https://github.com/kripken/emscripten/blob/bf0bdc540ad45b7178c6ea77a947c1b9f70a127d/tests/webidl/post.js#L65