Closed jfilby closed 1 year ago
Or, even better, using a pragma, something like {.export_napi.}
. Should simplify many things:
/**
* Something useful here
* @param {string} name
* @param {int} age
* @param {object} address
* @param {number} zipcode
* @return {string}
*/
Error: Type mismatch parameter: `name`. Got `undefined`, expected `string`
Registering a new function using {.export_napi.}
:
init proc(module: Module) =
proc testWithArgs(name: string, age: int, address: object, zipcode: int = 123) {.export_napi.} =
## Something useful here
echo args[0].getStr # output `name`
echo args.get("name") # output `name`
return %* "Alright!"
Sounds good.
It would be great to use macros to simplify the syntax of repetitive code.
E.g. instead of
module.registerFn(3, "testWithArgs"):
you could writeregisterFn testWithArgs (3 args):
.There are other possibilities too. Just an idea, not high priority.