hxcpp
hxcpp copied to clipboard
Embind
Embind is used to bind C++ functions and classes to JavaScript, so that the compiled code can be used in a natural way by “normal” JavaScript. According to this documentation how can i use Embind in my Haxe code ? https://kripken.github.io/emscripten-site/docs/porting/connecting_cpp_and_javascript/embind.html
#include <emscripten/bind.h>
using namespace emscripten;
float lerp(float a, float b, float t) {
return (1 - t) * a + t * b;
}
EMSCRIPTEN_BINDINGS(my_module) {
function("lerp", &lerp);
}
Have you considered automatically generating bindings using Haxe build macro?
First analyse your haxe class, and generate equivalent binding in c++ like this :
EMSCRIPTEN_BINDINGS(my_class_example) {
class_<MyClass>("MyClass")
.constructor<int, std::string>()
.function("incrementX", &MyClass::incrementX)
.property("x", &MyClass::getX, &MyClass::setX)
.class_function("getStringFromInstance", &MyClass::getStringFromInstance)
;
}
I did something similar for Wren bindings with Wrenegade
It depends on what you are trying to do.
- Write haxe, compile to hxcpp, compile to js - then using from native js
- Embed a js interpreter inside a hxcpp host.
- Use hxcpp build tool to compile a NDLL to be js callable
I. have decided not to really support this because I can't think of a use case where compiling haxe straight to js would not be the better solution. 2. I am not supporting really because this is what cppia is for. I you can do it with macros, then I highly recommend this solution. 3. This is how I have implemented NME in Js. It gets tricky with garbage collection, but it is possible.
Some native dependencies won't be available from browser, the steps highlighted by @hughsando seems like it will only work in nodejs environment.
Imagine I build a game engine that uses Wren for scripting, if I want the game to work in the browser, I need a way to make the wren VM run in the browser. This is where emscripten comes in.
Yes - makes sense - and also why I like to script in haxe.