daminetreg / js-bind

js::bind makes any C++ function, member function or lambda as a Javascript callback.
Boost Software License 1.0
22 stars 9 forks source link
bind emscripten javascript-callbacks js lambda wasm webassembly

js::bind

js::bind makes any C++ function, member function or lambda as a Javascript callable callback for Emscripten.

Easy to use

It's header only. You can set-it-up in 0-time with : nxxm ., add this to .nxxm/deps

{
  "nxxm/js-bind" : { "@" : "v0.0.3" } 
}

  using namespace std;
  using namespace std::placeholders;
  using emscripten::val;

  auto clickme_btn = val::global("document").call<val>("getElementById", "clickme_btn"s);

  auto onclick = [](val event){ 
    std::cout << "hello world ! " << std::endl; 
  };

  clickme_btn.set("onclick", js::bind(onclick, _1));

License

Please give copyright notice for this project : Boost Software License.

Copyright (c) 2017 Damien Buhl alias daminetreg (damien.buhl@lecbna.org)