Interoperability with web frameworks (Vue, Reactor, Angular)

Alessandro Pignotti edited this page Mar 9, 2018 · 1 revision

Let's say, for the sake of example, that you have a JavaScript function that expects the following syntax:

jsFuncWithObjectParam({requiredParam1:42, requiredParam2:"String", optionalParam1:null});

In C++ you can do the following:

namespace client
{
struct ParamObject
{
    void set_requiredParam1(int);
    void set_requiredParam2(const client::String&);
    void set_optionalParam1(client::Object*);
};

void jsFuncWithObjectParam(ParamObject*);
};

void webMain()
{
    client::ParamObject* p = new client::ParamObject();
    p->set_requiredParam1(42);
    p->set_requiredParam2("String");
    //p->set_optionalParam1(nullptr);
    client::jsFuncWithObjectParam(p);
}

We recommend this solution since it's more type safe. You can also use the shorter code example:

client::Object* p = new client::Object();
p->set_("requiredParam1",new client::Number(42));
p->set_("requiredParam2",new client::String("String"));
p->set_("optionalParam1",nullptr);
Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.