Skip to content

jspanchu/wasm-bits

Repository files navigation

wasm-bits

This is a collection of concise, targeted C++/JS examples that show how to wrap a C++ feature to JavaScript with Embind.

Each directory has a single main.cpp file or other .cpp files, a CMakeLists.txt file which can generate the build system files and an index.html file which can be used to test the wasm module in a browser.

  • Args - Pass command line arguments to a main function.
  • Constants - Wrap constants with embind.
  • CrossModule - Doesn't work. Attempts to make call functions defined in one module with an argument from another module.
  • DynamicLinkingClasses - Create two shared libraries and use classes from the libraries in main.
  • DynamicLinkingGL - Use OpenGL in shared library.
  • DynamicLinkingSimple - Create a shared library and call a function from the library in main.
  • EmVal - Shows usage of emscripten::val to pass any JavaScript object to C++.
  • Enums - Wraps C/C++ style (un)scoped enums with embind.
  • Env - Shows how to populate runtime environment so that getenv can retrieve environment variables.
  • FunctionPointer - Shows how to pass a JavaScript function to a C/C++ function that accepts a function pointer and then invoke that JavaScript function from C++.
  • Memory64 - node.js example tries to use 64-bit integers and 64-bit memory.
  • PODPointers - wraps native functions that accept and return raw pointers as a view using emscripten::typed_memory_view.
  • SharedPointer - Shows how to construct embound objects with std::shared_ptr.
  • Threads - WIP
  • UnityBuildMultiLibsSingleModule - Similar to CrossModule, but the bindings are built as one whole translation unit.
  • Virtuals - Shows how to wrap (with embind) and implement C++ pure virtual classes in JavaScript
  • vtkSmartPointer - Implements the emscripten::smart_ptr_trait for vtkSmartPointer and shows how C++ vtkObject instances can be automatically garbage collected from JavaScript.
  • vtkWasmThreadedFilters - WIP