emscripten-core / emscripten-core/emscripten
EMSCRIPTEN_BINDINGS and classes
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
I'm trying to do a pretty simple thing - create a button fully using emscripten. Bindings however don't seem to work in this situation.
Button.h:
```c++
class Button {
public:
Button(const std::string &id, std::function callback);
void onClick();
private:
std::string id;
emscripten::val element;
std::function onClickCallback;
};
```
Button.cpp:
```c++
Button::Button(const std::string &id, std::function callback) : id(id) {
onClickCallback = callback;
element = val::global("document").call("getElementById", id);
element.call(
"addEventListener",
std::string("click"),
val::module_property("onClick")
);
}
void Button::onClick() {
if (onClickCallback) onClickCallback();
}
EMSCRIPTEN_BINDINGS(button_bindings) {
class_("Button")
.constructor>()
.function("onClick", &Button::onClick);
}
```
I have a general understanding of why it might not work, but I want to clarify and perhaps find a solution.
Contributor guide
Assessment
This issue has not been assessed yet.