@stdlib/napi-argv-dataview-cast
v0.1.1
Published
Convert a Node-API value corresponding to a DataView to a pointer having a specified data type.
Readme
ARGV_DATAVIEW_CAST
Convert a Node-API value corresponding to a DataView to a pointer having a specified data type.
Installation
npm install @stdlib/napi-argv-dataview-castUsage
var headerDir = require( '@stdlib/napi-argv-dataview-cast' );headerDir
Absolute file path for the directory containing header files for C APIs.
var dir = headerDir;
// returns <string>Examples
var headerDir = require( '@stdlib/napi-argv-dataview-cast' );
console.log( headerDir );
// => <string>C APIs
Usage
#include "stdlib/napi/argv_dataview_cast.h"STDLIB_NAPI_ARGV_DATAVIEW_CAST( env, X, type, argv, index )
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.
Notice
This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
Community
License
See LICENSE.
Copyright
Copyright © 2016-2026. The Stdlib Authors.
