std::variant - returning multiple types EMSCRIPTEN_BINDINGS function.

25 views
Skip to first unread message

adam crockett

unread,
May 26, 2019, 5:13:51 PM5/26/19
to emscripten-discuss
Fingers crossed someone can help me,

I am working on the last phase of my project, long story short, I am trying to get Lua values from a table back into JavaScript.
Like JavaScript, Lua is dynamically typed, I am going to be puting all sorts of values into a c++ std::map

specification for this map:
  • keys can be double or string
  • values can be, boolean, string, null, double and map of the same type (recursive)
For simplicity and your sake I have reduced this down somewhat.
 
std::variant<std::string, int> returnsAllSorts (){
   
return stringOrInt(); // this could return either or.
}

EMSCRIPTEN_BINDINGS (my_module) {
    emscripten
::function("returnsAllSorts", &returnsAllSorts);
}


 If the above wont work, what else can I try, in order to get a map with different values? 

adam crockett

unread,
Jul 3, 2019, 6:57:25 PM7/3/19
to emscripten-discuss
For any future searches, the answer is to create a JavaScript object from inside your cpp.

Use emscripten::val

And return that instead of a Vector or Map.

Reply all
Reply to author
Forward
0 new messages