A set of utility classes to make writing native addons easier. The majority of the code is from zcbenz's native-mate library. See tests folder for example. Current list of classes:
- Converter: Converting from primitive and basic C++ variables to V8 variables and from V8 variables to C++ variables.
- Dictionary: Handle dictionaries that represents a Javascript Object.
- PersistentDictionary: Same as Dictionaries but stored on the heap.
- ScopedPersistent: Store V8 objects on the heap.
- Emitter: Event emitter class.
$ npm i native-huron
In your binding.gyp:
{
'includes': [ 'path/to/native-huron/module/native_huron_files.gypi' ],
'targets': [ {
'target_name': 'test'
, 'sources': [ '<@(native_huron_files)' ]
, 'include_dirs': [ "<!(node -e \"require('native-huron')\")" ]
} ]
}In your C++ files:
#include <native_huron/converter.h>
#include <native_huron/dictionary.h>
// Use utility classes...Converts the value, a primitive or simple C++ variable (e.g. double or std::string) to a V8 variable. Returns the converted V8 variable.
Tries to convert the value, a primitive or simple C++ variable (e.g. double or std::string) to a V8 variable. Returns a boolean wether the conversion was successful, if it was, the result is written to the result address.
Tries to convert the value, a V8 variable, primitive or simple C++ variable (e.g. double or std::string). Returns a boolean wether the conversion was successful, if it was, the result is written to the result address.
Convenience function to convert a std::string to a v8::String. Returns the converted string.
Convenience function to convert a v8::String to a std::string. Returns the converted string.
This class can also be used with Converter's ConvertTo/FromV8 functions.
Creates a Dictionary object from the object parameter, which is a v8::Local<v8::Object>.
Creates an empty Dictionary object. Returns the created dictionary.
Returns true, if the key (std::string) exists in the dictionary and writes it to the out address.
dict.GetHidden(key, out)
Returns true, if the key (std::string) exists as a hidden value in the dictionary and writes it to the out address.
Returns true, if the key (std::string) is successfully set in the dictionary with the given value.
dict.SetHidden(key, value)
Returns true, if the key (std::string) is successfully set as hidden value in the dictionary with the given value.
Returns true, if the key (std::string) method is successfully set in the dictionary with the given callback, which is a C++ method with V8 FunctionCallback signature (standard V8 addon method signature).
Returns true, if the key (std::string) is successfully deleted from the dictionary.
Returns if the dictionary is empty.
Same functionality as Dictionary, but it is stored on the heap. Use only if really neccessary.
Classes derived from this class can use the Emit method to fire listeners added in Javascript. In your class you have to add Emitter's On method to use it (see test folder).
Emits the eventName event handlers with the specified args. All parameters' type should be V8 types!
Alias for the above method.
Alias for the above method.
Emits the eventName event handlers with the dict object as a parameter. So you have to add the desired parameters in your lambda function your dictionary. This is needed to emit events from different threads as V8's thread.
Alias for the above method.
This member method lets you set listeners from c++ code.
This member method lets you remove listeners from c++ code.
This member method lets you set listeners from c++ code that fire only once.