Hello,

I am trying to use a simple C++ program containing using *std::function* with 
Embind. However, the latter does not seem to recognize *std::function*.

More specifically, here is the example I used:

*Foo.cpp*

 
#include <functional>
#include <emscripten/bind.h>

using namespace emscripten;

int bar(std::function<int(int)> func, int num) {
return func(num);
}

EMSCRIPTEN_BINDINGS(Foo) {
function("bar", &bar);
}


*Foo.html*


<!doctype html>
<html>
<script src="foo.js"></script>
<script>
console.log('Foo: ' + Module.bar);
</script>
</html>


*Compilation*


*$* emcc --bind foo.cpp -o foo.js


The compilation succeeds with no errors or warnings. You may find the 
generated *foo.js* attached.

*Result*

<https://lh3.googleusercontent.com/-cbSwX8ZiNag/WWNzyjMIwsI/AAAAAAAAKUA/06dRJmG-0C4b3_jHxB1c_Eu1Mny5947ZQCLcBGAs/s1600/Screen%2BShot%2B2017-07-10%2Bat%2B14.57.05.png>


I also tried to compile and/or run the test files of Embind (see 
embind_test.cpp 
<https://github.com/kripken/emscripten/blob/master/tests/embind/embind_test.cpp>
 and embind.test.js 
<https://github.com/kripken/emscripten/blob/master/tests/embind/embind.test.js>),
 
which also contain function that use *std::function* (e.g. 
emval_test_get_function_ptr 
(definition) 
<https://github.com/kripken/emscripten/blob/master/tests/embind/embind_test.cpp#L153>
 / emval_test_get_function_ptr (binding) 
<https://github.com/kripken/emscripten/blob/master/tests/embind/embind_test.cpp#L1780>),
 
with exactly the same command and they *do work fine*:

*Result*

<https://lh3.googleusercontent.com/-9Cn4jyhAPzg/WWN1pN3B8TI/AAAAAAAAKUQ/x_t2dM-qyi8n6hTcIf968IQSaxmfFxoDACLcBGAs/s1600/Screen%2BShot%2B2017-07-10%2Bat%2B14.56.02.png>

*Generated source code*

<https://lh3.googleusercontent.com/-80B9SjRLHME/WWN16hbcMCI/AAAAAAAAKUU/ZzP2QEes3Pk0gacNafhtMMgyUAazTTEkwCLcBGAs/s1600/Screen%2BShot%2B2017-07-10%2Bat%2B14.55.53.png>

I should also mention that I tried many different combinations, e.g. 
*std::function* with different types, as return type, as argument, as an 
independent function (like in the above example), as a class or struct 
method, but had no luck.

Any ideas would prove of great help.

Thank you very much, in advance.


― Vangelis

-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to