How to get JS object for class instance using Embind #25431
-
|
For an Embind For example: struct MyClass {
void fun() {
// How to get reference to object that `fun` was called on as emscripten::val?
}
};
EMSCRIPTEN_BINDINGS(MyClass) {
emscripten::class_<MyClass>("MyClass")
.function("fun", &MyClass::fun);
} |
Beta Was this translation helpful? Give feedback.
Answered by
brendandahl
Oct 2, 2025
Replies: 2 comments 3 replies
-
Beta Was this translation helpful? Give feedback.
0 replies
-
val valThis(this, allow_raw_pointers());
val::global("console").call<void>("log", valThis); |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The JS object representing the C++ object is just a thin wrapper. Embind doesn't cache the wrappers so it's not able to provide the same wrapper everytime the C++ object is passed into JS. Some alternatives:
MyClassand add a binding for it.valmember toMyClassand put the properties there.