Created
July 5, 2015 17:14
-
-
Save bbuecherl/a01b453c9d202fc94ddc to your computer and use it in GitHub Desktop.
random node native addon macros (using nan)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define JSEXPORT_METHOD(tpl, name, cb) do { \ | |
v8::Local<v8::FunctionTemplate> t = NanNew<v8::FunctionTemplate>(cb); \ | |
tpl->InstanceTemplate()->Set(NanNew<v8::String>(name), \ | |
t->GetFunction(), v8::ReadOnly); \ | |
} while (0) | |
#define JSTOSTRING(handle) \ | |
(new v8::String::Utf8Value(handle->ToString()))->operator*() | |
#define MUTEX_LOCK(mutex, action) do { \ | |
uv_mutex_lock(mutex); \ | |
action; \ | |
uv_mutex_unlock(mutex); \ | |
} while (0) | |
#define JSFUNCTION(_0, ...) JSFUNCTION_(JSFUNCTION__STATIC(_0, __VA_ARGS__, 0),\ | |
JSFUNCTION__PROTO(_0, __VA_ARGS__, 0), __VA_ARGS__) | |
#define JSFUNCTION_(_2, _3, ...) JSFUNCTION__(__VA_ARGS__, _3, _2, 1, 0) | |
#define JSFUNCTION__(_1, _2, _3, ...) _3 | |
#define JSFUNCTION__STATIC(name, body, ...) NAN_METHOD(name) { \ | |
NanScope(); \ | |
if(1) body; \ | |
NanReturnUndefined(); \ | |
} | |
#define JSFUNCTION__PROTO(clas, name, body, ...) NAN_METHOD(clas::name) { \ | |
NanScope(); \ | |
clas *that = ObjectWrap::Unwrap<clas>(args.This()); \ | |
if(1) body; \ | |
NanReturnUndefined(); \ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
JSFUNCTION(my_clas, someFunction, { | |
that->someVariable = JSTOSTRING(args[0]); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment