-
Notifications
You must be signed in to change notification settings - Fork 126
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
Callbacks cannot be copied on the v8 codepath #52
Comments
A workaround is to use pointers, as mentioned in #15. However, a better alternative is to use std::unique_ptr<nbind::cbFunction> fnPtr;
fnPtr = std::make_unique<nbind::cbFunction>(otherFnFunction); |
This sounds like a bug. I'll look into it. |
This should work: nbind::cbFunction fn(otherFnFunction); While that should be enough for basic use, I guess the move constructor and assignment operators should also be implemented... |
Hm, the move constructor isn't really necessary, but the assignment operator is interesting because it's the only way to reassign the callbacks attributes of a class instance (otherwise, using pointers will still be required). |
@arcanis once I declare a unique_ptr to a callback function, how do I go about callling that callback function? I seem to be having some issues with the syntax... |
@samuelnj226 try: Full working example: #include "nbind/api.h"
/* If using C++11 instead of C++14, uncomment this:
namespace std {
template<typename T, typename... Args>
std::unique_ptr<T> make_unique(Args&&... args) {
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}
}
*/
void callMe(nbind::cbFunction cb) {
std::unique_ptr<nbind::cbFunction> fn;
fn = make_unique<nbind::cbFunction>(cb);
(*fn)();
}
#include "nbind/nbind.h"
NBIND_GLOBAL() {
function(callMe);
} JS: var nbind = require('nbind');
var lib = nbind.init().lib;
lib.callMe(() => console.log('Hello, World!')); |
The following lines do not compile with the v8 codepath:
I've found this line in the documentation that seems to imply that this is a bug (plus, it work fine on the emscripten codepath):
The text was updated successfully, but these errors were encountered: