Replies: 2 comments
-
Beta Was this translation helpful? Give feedback.
0 replies
-
|
There's not an official/documented way to do this currently. You could set up your own conversion, but this may break in the future. namespace emscripten {
namespace internal {
template <>
struct BindingType<your_type> {
using ValBinding = BindingType<val>;
using WireType = ValBinding::WireType;
static WireType toWireType(const your_type& yourObj) {
val obj = val::object();
// ... copy data from yourObj
return ValBinding::toWireType(obj);
}
static your_type fromWireType(WireType value) {
val val = ValBinding::fromWireType(value);
your_type mine;
mine.set(val);
return mine;
}
};
template <typename T>
struct TypeID<T,
typename std::enable_if_t<
std::is_same<typename Canonicalized<T>::type, your_type>::value>> {
static constexpr TYPEID get() { return TypeID<val>::get(); }
};
}} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi!
Is it possible to hook into embind, such that I can specify conversion from/to
emscripten::valfor C++ types? For example, I would like to mapEigentypes to correspondingThree.jsones, for whichvalue_objectmight not be sufficient, as I need the whole JS object at once to set up the type on the C++ side.Or phrased differently. Can a
value_objecthave a constructor takingemscripten::valand can I provide lambdas forvalue_objectmembers, that take a reference to the underlying object as argument?Like
value_object<Eigen::MatrixXd>{"Matrix"} .constructor([](const emscripten::val& value) { Eigen::MatrixXd object; object.resize(value["rows"].as<int>(), value["cols"].as<int>()); // set up the rest ... return object; }) .field("rows", [](const Eigen::MatrixXd& self) { return self.rows(); }) .field("elements", [](const Eigen::MatrixXd& self) { return toTypedArray(self.data())});Thanks and greetings from Berlin.
Beta Was this translation helpful? Give feedback.
All reactions