Hi all,

I came across the BindingType template and tried to use it to convert an 
integer to my own Id-type. Given for example

class Id {
public:
  explicit Id(int v) : value(v) {}
  int toInt() const { return value; }
private:
  int value;

}

I can add the following template specializations

template <> struct TypeID<Id> {
static constexpr TYPEID get() {
return TypeID<int>::get();
}
};

template <> struct BindingType<Id> {
using WireType = int;
static WireType toWireType(const Id& v) {
return v.toInt();
}
static Id fromWireType(WireType v) {
return Id(v);
}
};

and get a transparent conversion for functions calling/returning Id-types. 
I have two questions:

1) Is this a supported way to use BindingType? (asking because it is 
defined in 'Internal')
2) What if the conversion is not infallible? Maybe.I only want to accept 
numbers larger than 0 or similar. I would like the JS-side to fail with an 
exception (similar to throwBindingError if I try to pass a null as a 
string).

I would like something like this be able to deal with JS-native types on 
the Java-script side and to avoid writing all the boilerplate to convert 
between the JS-native types and the C++ types.

Hope this makes sense, Any feedback appreciated.
Søren

-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/emscripten-discuss/77411b31-6bd3-48f1-a016-09caa81d5651n%40googlegroups.com.

Reply via email to