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

Calling callback JS functions in Nim #10

Closed Ethosa closed 9 months ago

Ethosa commented 10 months ago

At JS side I pass some functions in Nim procedure:

...
lib.callFunc(() => {
  console.log(1);
});
...

But at Nim side I have error on denim build:

Error: internal error: getTypeDescAux(tyEmpty)
No stack traceback available
To create a stacktrace, rerun compilation with './koch temp c <file>', see https://nim-lang.github.io/Nim/intern.html#debugging-the-compiler for details

Nim code:

init proc(module: Module) =

  proc callFunc(callback: napi_function): void {.export_napi.} =
    discard callFunction(args.get("callback"), [])

Nim version:

Nim Compiler Version 2.0.0 [Linux: amd64]
Compiled at 2023-08-01
Copyright (c) 2006-2023 by Andreas Rumpf

git hash: a488067a4130f029000be4550a0fb1b39e0e9e7c
active boot switches: -d:release

UPD: on 1.6.14 I got same error UPD2: same on 1.6.8

Ethosa commented 10 months ago

Here is reason https://github.com/openpeeps/denim/blob/main/src/denimpkg/napi/bindings.nim#L438

right version:

proc callFunction*(fn: napi_value, args: openarray[napi_value] = [], this: napi_value = %*(emptyArr)): napi_value =
Ethosa commented 10 months ago

So ... I'll send PR in near future

Ethosa commented 9 months ago

solved in #12