Support --bind flag for emcc to allow usage of embind


#1

Hey, i’m playing around with creating HTML5 extensions for Defold.

I’ve tried to use embind (mostly for emval) to extend my interop capabilities. But it seems that cloud compiler does not have support for the --bind emcc flag that required for the embind.

Could you enable it on your side?

More specifically — i’m working on extension that allows to pass callbacks from lua to the js side. And embind (with emval) may be of great help here.

I’m trying to enable flag in my manifest file.

name: html5callback

platforms:
    js-web:
        context:
            flags: ["--bind", "-std=c++11"]

    wasm-web:
        context:
            flags: ["--bind", "-std=c++11"]

#2

Yep, forwarding of callback from Lua to JS code may be very useful for integration with asynchronous methods 3rd side JS SDK.
Example: call “Show Ad” JS method from Lua and waiting for the end of Ad.


#3

But it’s already possible to create a Javascript extension that can take a Lua function and invoke a callback. Check the code for the FBInstant extension for an example.


#4

Thank you for pointing out to FBInstant extension. It contains interesting Runtime.dynCall magick.

But my point is a bit different. In case of FBInstant we have to create cpp code to wrap calls, even if we could use callbacks.

I’d like to experiments with ways to make such calls without writing cpp code for each library i.e. create middleware that somehow handles this in more or less universal way.

And if i have right idea emval ( emscripten::val) probably may helps me to achieve this task. But it seems that emval does not work without enabled embind.


#5

We also have another simple example in extension-html5 which lets you call the engine directly from javascript (and no use of dynCall).

With that said, it should be an easy fix to add support for the ‘–bind’ flag in the next release.

Note that as opposed to the EM_ASM construct, the EMSCRIPTEN_BINDINGS needs a this extra compiler flag. That, to me, says that this is a special feature but I’m not sure if that’s good or bad :slight_smile:
Also, the fact that they mention Boost as an inspiration also makes me wonder about the executable size and performance.