macro-inferno
A header library with various helpers for native node.js addon development built on top of NAN. Write one-liners for typechecking and converting arguments, unpacking and packing v8::Arrays, unwrapping and wrapping objects and property getters.
Collapse complex statements into one-liners and avoid writing the same stuff over and over again in each function that your module exposes. Converting JS objects, wrapping and unwrapping instances, packing and unpacking arrays, type checking... , all this can be done using macro-inferno macros, which avoids repetitive and unreadable code and saves you a lot of time that you would spend copy and pasting.
Why? - Write one-liners instead of massive statements
Typechecked conversions:
If you care about displaying meaningful error messages to the user of your API, you may end up writing code like this ...
Simply write 3 lines of code instead:
Typechecked conversion of arrays:
Unpacking arrays to std::vector ...
Simply write:
Documentation
Shortcuts
FF_OBJ obj = FF_NEW_OBJ();v8::Local<v8::Object> obj = Nan::New<v8::Object>();FF_ARR arr = FF_NEW_ARRAY(10);v8::Local<v8::Array> arr = Nan::New<v8::Array>(10);FF_VAL val;v8::Local<v8::Value> val;std::string str = FF_NEW_STRING("foo");std::string str = Nan::New("foo").ToLocalChecked();info.GetReturnValue().Set(val);bool hasProperty = FF_HAS(obj, "aProperty");bool hasProperty = Nan::HasOwnProperty(obj, Nan::New("aProperty").ToLocalChecked()).FromJust();
Convert and typecheck native types
Required arguments:
Cast argument n to native type or throw a meaningful type error.
/* FF_ARG_type(arg number, variable declaration) */
For example:
invoked like this:
// will not throwmodule;module;module;// will throw: aMethodName - expected arg 0 to be of type: NUMBERmodule;module;module;module;module;module;
Optional arguments:
If defined, cast argument n to native type or throw a meaningful type error, else initialize with default value.
/* FF_ARG_type(arg number, variable declaration, default value) */
For example:
invoked like this:
// will not throwmodule;module;module;// will not throw and set arg 1 to the default valuemodule;// will throw: aMethodName - expected arg 1 to be of type: NUMBERmodule;module;module;module;module;module;
Typechecked conversion between arrays and std::vectors
// unpack v8::Local<v8::Array> to std::vector<double> vecFF_ARR someArray = ...// convert numberVec to a v8::Local<v8::Array>std::vector<double> numberVec = ...// convert stringVec to a v8::Local<v8::Array>std::vector<std::string> stringVec = ...