Skip to content

Commit

Permalink
Auto-generated commit
Browse files Browse the repository at this point in the history
  • Loading branch information
stdlib-bot committed Jan 17, 2024
1 parent 83274fc commit 36e5d16
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 80 deletions.
59 changes: 45 additions & 14 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"options": {},
"options": {
"task": "build"
},
"fields": [
{
"field": "src",
Expand All @@ -22,17 +24,46 @@
"relative": false
}
],
"confs": [
{
"src": [
"./src/main.c"
],
"include": [
"./include"
],
"libraries": [],
"libpath": [],
"dependencies": []
}
]
"confs": [
{
"task": "build",
"src": [
"./src/main.c"
],
"include": [
"./include"
],
"libraries": [],
"libpath": [],
"dependencies": [
"@stdlib/napi-export",
"@stdlib/napi-argv",
"@stdlib/napi-argv-double"
]
},
{
"task": "benchmark",
"src": [
"./src/main.c"
],
"include": [
"./include"
],
"libraries": [],
"libpath": [],
"dependencies": []
},
{
"task": "examples",
"src": [
"./src/main.c"
],
"include": [
"./include"
],
"libraries": [],
"libpath": [],
"dependencies": []
}
]
}
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
"url": "https://github.com/stdlib-js/stdlib/issues"
},
"dependencies": {
"@stdlib/napi-argv": "^0.1.1",
"@stdlib/napi-argv-double": "^0.1.1",
"@stdlib/napi-export": "^0.1.1",
"@stdlib/utils-library-manifest": "^0.1.1"
},
"devDependencies": {
Expand Down
74 changes: 8 additions & 66 deletions src/addon.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
*/

#include "stdlib/number/float64/base/assert/is_same_value.h"
#include "stdlib/napi/export.h"
#include "stdlib/napi/argv.h"
#include "stdlib/napi/argv_double.h"
#include <node_api.h>
#include <stdint.h>
#include <stdbool.h>
#include <assert.h>

/**
Expand All @@ -31,74 +32,15 @@
* @return Node-API value
*/
static napi_value addon( napi_env env, napi_callback_info info ) {
napi_status status;

// Get callback arguments:
size_t argc = 2;
napi_value argv[ 2 ];
status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL );
assert( status == napi_ok );

// Check whether we were provided the correct number of arguments:
if ( argc < 2 ) {
status = napi_throw_error( env, NULL, "invalid invocation. Insufficient arguments." );
assert( status == napi_ok );
return NULL;
}
if ( argc > 2 ) {
status = napi_throw_error( env, NULL, "invalid invocation. Too many arguments." );
assert( status == napi_ok );
return NULL;
}

napi_valuetype vtype0;
status = napi_typeof( env, argv[ 0 ], &vtype0 );
assert( status == napi_ok );
if ( vtype0 != napi_number ) {
status = napi_throw_type_error( env, NULL, "invalid argument. First argument must be a number." );
assert( status == napi_ok );
return NULL;
}

napi_valuetype vtype1;
status = napi_typeof( env, argv[ 1 ], &vtype1 );
assert( status == napi_ok );
if ( vtype1 != napi_number ) {
status = napi_throw_type_error( env, NULL, "invalid argument. Second argument must be a number." );
assert( status == napi_ok );
return NULL;
}

double a;
status = napi_get_value_double( env, argv[ 0 ], &a );
assert( status == napi_ok );

double b;
status = napi_get_value_double( env, argv[ 1 ], &b );
assert( status == napi_ok );

bool out = stdlib_base_float64_is_same_value( a, b );
STDLIB_NAPI_ARGV( env, info, argv, argc, 2 );
STDLIB_NAPI_ARGV_DOUBLE( env, a, argv, 0 );
STDLIB_NAPI_ARGV_DOUBLE( env, b, argv, 1 );

napi_value v;
status = napi_create_uint32( env, out, &v );
napi_status status = napi_create_uint32( env, stdlib_base_float64_is_same_value( a, b ), &v );
assert( status == napi_ok );

return v;
}

/**
* Initializes a Node-API module.
*
* @private
* @param env environment under which the function is invoked
* @param exports exports object
* @return main export
*/
static napi_value init( napi_env env, napi_value exports ) {
napi_value fcn;
napi_status status = napi_create_function( env, "exports", NAPI_AUTO_LENGTH, addon, NULL, &fcn );
assert( status == napi_ok );
return fcn;
}

NAPI_MODULE( NODE_GYP_MODULE_NAME, init )
STDLIB_NAPI_MODULE_EXPORT_FCN( addon )

0 comments on commit 36e5d16

Please sign in to comment.