Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
emscripten-core
GitHub Repository: emscripten-core/emscripten
Path: blob/main/test/embind/test_optional_val_main.cpp
6162 views
1
#include <emscripten/bind.h>
2
#include <emscripten/val.h>
3
#include <string>
4
#include <iostream>
5
6
using namespace emscripten;
7
8
class MyType {
9
public:
10
void RunCallback(emscripten::val callback);
11
};
12
13
int main() {
14
EM_ASM(
15
let value = new Module.MyType();
16
value.RunCallback((e) => {
17
console.log("Received: " + e);
18
if (e !== "Hey") throw "Expected 'Hey', got " + e;
19
});
20
);
21
std::cout << "done" << std::endl;
22
}
23
24
EMSCRIPTEN_BINDINGS(my_module) {
25
register_optional<std::string>();
26
27
class_<MyType>("MyType")
28
.constructor<>()
29
.function("RunCallback", &MyType::RunCallback);
30
}
31
32