DEV Community

Adam Crockett 🌀
Adam Crockett 🌀

Posted on

Emscripten overloading

I'm trying to get one function to return 2 type different values to JavaScript with embind. A string or a number, does anyone have any example code?

Top comments (1)

Collapse
 
adam_cyclones profile image
Adam Crockett 🌀 • Edited

So, heres what I have learned.

I don't need to overload, using embind, you can do this.

#include <emscripten/val.h>

auto someFunction()
{
   val my_js_object = val::object();
   my_js_object.set("hello", "world");
   return my_js_object;
}

Contrary to what I believed to be true, you can use val for all sorts of things but most importantly, return JavaScript objects.