openpeeps / denim

Node 💖 Nim = Denim! Build powerful NodeJS / BunJS addons with Nim language via Node API (NAPI)
https://openpeeps.github.io/denim/
MIT License
40 stars 1 forks source link

Macros for cleaner export Nim code #4

Closed jfilby closed 1 year ago

jfilby commented 1 year ago

It would be great to use macros to simplify the syntax of repetitive code.

E.g. instead of module.registerFn(3, "testWithArgs"): you could write registerFn testWithArgs (3 args):.

There are other possibilities too. Just an idea, not high priority.

georgelemon commented 1 year ago

Or, even better, using a pragma, something like {.export_napi.}. Should simplify many things:

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!"
jfilby commented 1 year ago

Sounds good.