kabiroberai / node-swift

Create Node modules in Swift
MIT License
492 stars 16 forks source link

How register the module ===> @_cdecl("node_swift_register") #31

Closed skeyboy closed 3 months ago

skeyboy commented 3 months ago

` @import CNodeAPI;

NAPI_MODULE_INIT() { napi_value node_swift_register(napi_env); return node_swift_register(env); }
@_cdecl("node_swift_register") ` Hi, I can not understand the above: How the module register and where called the functions above. I search the project but no find the register as C++ ,

kabiroberai commented 3 months ago

NAPI_MODULE_INIT is in fact the entrypoint — it’s a C macro defined by Node’s node-api.h that handles registration for us. The client (the library you write) statically links NodeModuleSupport, which declares an entrypoint via this macro, and forwards to the client’s node_swift_register in the implementation. Closing since I believe this answers the question but feel free to ask followups!