emscripten-core / emscripten-core/emscripten
Is it possible to pass a C++ lambda as argument to a js function ?
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
Is the code below or equivalent possible ?
What is the best way to achieve this functionality ?
```cpp
class_>("_callback")
.constructor<>()
.function("opcall", &std::function::operator())
;
emscripten::val window = emscripten::val::global("window");
std::function wrapped = []() {
std::cout << "Hello " << "\n";
};
emscripten::val intervalId = window.call("setInterval", wrapped, 1000);
```
The code below does not work on the js side. It is called periodically but produce an error on each call
```
Uncaught SyntaxError: missing ] after element list14 [lython.js line 3599 > Function:6:9](http://192.168.2.20:8000/build/Release/bin/lython.js%20line%203599%20%3E%20Function)note: [ opened at line 6, column 1
```
Contributor guide
Assessment
This issue has not been assessed yet.