Skip to content

Instantly share code, notes, and snippets.

@verma
Created June 9, 2014 21:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save verma/6b4e9e8f7d4ce3f124aa to your computer and use it in GitHub Desktop.
Save verma/6b4e9e8f7d4ce3f124aa to your computer and use it in GitHub Desktop.
#include <emscripten/bind.h>
using namespace emscripten;
class LASZip {
public:
LASZip() {}
void open(const char *buf, size_t len) {
printf("Got buffer: %p, size: %i", buf, len);
}
};
float lerp(float a, float b, float t) {
return (1 - t) * a + t * b;
}
EMSCRIPTEN_BINDINGS(my_module) {
function("lerp", &lerp);
class_<LASZip>("LASZip")
.constructor()
.function("open", &LASZip::open, allow_raw_pointers());
}
<!doctype html>
<html>
<script src="laz-perf.js"></script>
<script>
document.write('lerp result: ' + Module.lerp(1, 2, 0.5));
var x = new Module.LASZip();
var a = new Int8Array(1024);
var buf = Module._malloc(a.length*a.BYTES_PER_ELEMENT);
Module.HEAPU8.set(a, buf);
x.open(buf, a.length);
Module._free(buf);
x.delete();
console.log("Done with deletion");
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment