Convert a Node-API value corresponding to a DataView to a pointer having a specified data type.
var headerDir = require( '@stdlib/napi/argv-dataview-cast' );Absolute file path for the directory containing header files for C APIs.
var dir = headerDir;
// returns <string>var headerDir = require( '@stdlib/napi/argv-dataview-cast' );
console.log( headerDir );
// => <string>#include "stdlib/napi/argv_dataview_cast.h"Macro for converting an add-on callback argument corresponding to a DataView to a pointer having a specified data type.
struct complex128 {
double re;
double im;
};
static void fcn( const struct complex128 *X, struct complex128 *Y ) {
Y->re = X->re + Y->re;
Y->im = X->im + Y->im;
}
// ...
static napi_value addon( napi_env env, napi_callback_info info ) {
// Retrieve add-on callback arguments:
STDLIB_NAPI_ARGV( env, info, argv, argc, 2 );
// Convert the first argument to a C type:
STDLIB_NAPI_ARGV_DATAVIEW_CAST( env, X, struct complex128, argv, 0 );
// Convert the second argument to a C type:
STDLIB_NAPI_ARGV_DATAVIEW_CAST( env, Y, struct complex128, argv, 1 );
// ...
fcn( X, Y );
}The macro expects the following arguments:
- env: environment under which the callback is invoked.
- X: output variable name.
- type: output variable type.
- argv: name of the variable containing add-on callback arguments.
- index: argument index.