New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to create value_object binding with optional fields? #6226
Comments
I think I figured out a quick work around: I manually modified 'toWireType': function(destructors, o) {
// todo: Here we have an opportunity for -O3 level "unsafe" optimizations:
// assume all fields are present without checking.
for (var fieldName in fields) {
if (!(fieldName in o)) {
throw new TypeError('Missing field');
}
}
var ptr = rawConstructor();
for (fieldName in fields) {
fields[fieldName].write(ptr, o[fieldName]);
}
if (destructors !== null) {
destructors.push(rawDestructor, ptr);
}
return ptr;
}, to 'toWireType': function(destructors, o) {
var ptr = rawConstructor();
for (fieldName in fields) {
if (fieldName in o) {
fields[fieldName].write(ptr, o[fieldName]);
}
}
if (destructors !== null) {
destructors.push(rawDestructor, ptr);
}
return ptr;
}, and I think it works now. |
You can use emscripten::val && hasOwnProperty(width) === You can use emscripten::val && hasOwnProperty to create overloaded constructors. We can call native constructor based on properties && typeof:
typeof(emscripten::val) === string -> call string contructor
|
This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 7 days. Feel free to re-open at any time if this issue is still relevant. |
consider the following example:
Then works flawlessly when I do this in Javascript:
However, if I just want to only provide the fields I want to override and leave the other fields to their default value like so:
then I get the following error:
How do we make optional fields with embind's value_object? Thanks!
The text was updated successfully, but these errors were encountered: