-
Notifications
You must be signed in to change notification settings - Fork 85
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
Write access into std::vector #10
Comments
I'm getting the same issue Is there a workaround for this? |
I 'resolved' this issue by implementing the extending the c++ class in javascript; I believe you can also implement a Example of extending pattern: template <typename _NumberT>
class RobVector
{
public:
std::vector<_NumberT> pos;
...
} // Wrapper around RobVector
export class Vector extends _librob.RobVector {
constructor(vec) {
super(vec?.pos || (Array.isArray(vec) ? vec : undefined) || [])
if (!isNaN(Number(vec))) {
this.pos = Array(vec).fill(0);
}
}
elementWise (b, op, defaultVal = 0) {
// Requires full object copy (no member access)
let ret = Array.from(this.pos);
for (let i = 0; i < ret.length; i++) {
ret[i] = op(ret[i], b.pos[i] || defaultVal, i)
}
return new Vector(ret);
}
toString()
{
let ret = Array.from(this.pos);
return ret.join(", ")
}
}
operators_set(Vector.prototype,{
"-" (a, b) => a.elementWise(b, (x, y, i) => { return x - y; }, 0),
"+" (a, b) => a.elementWise(b, (x, y, i) => { return x + y; }, 0)
}); |
Amazing, Thank-you |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is it possible to set a member of std::vector in qjs?
Currently only you can only write the full vector.
Test case:
The text was updated successfully, but these errors were encountered: