You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If I got it right, the key might be a module API in N-API to allow N-API modules to directly access other type of modules. Currently you have to pass require function or module instance to N-API modules on a setup phase from JS. With require there is no differences between these 4 types of modules AFAIK.
@sudhakar3697 you can call JavaScript functions, but is up to you to get those to the N-API module. For example if you pass the result of fs = require('fs') to an N-API function it can use N-API methods to get fields/functions on that an then call them.
Having said that it might be easier to keep some of that functionality in JS and call a higher level function from the N-API C function as opposed to making many of those calls in the N-API functcion. I also believe it would likely be better optimized with more of the calls together at the JS level as each back and forth adds overhead.
Activity
legendecas commentedon Aug 22, 2019
If I got it right, the key might be a module API in N-API to allow N-API modules to directly access other type of modules. Currently you have to pass
requirefunction ormoduleinstance to N-API modules on a setup phase from JS. Withrequirethere is no differences between these 4 types of modules AFAIK.A module API is being proposed on nodejs/node#28464.
mhdawson commentedon Aug 22, 2019
@sudhakar3697 you can call JavaScript functions, but is up to you to get those to the N-API module. For example if you pass the result of fs = require('fs') to an N-API function it can use N-API methods to get fields/functions on that an then call them.
Having said that it might be easier to keep some of that functionality in JS and call a higher level function from the N-API C function as opposed to making many of those calls in the N-API functcion. I also believe it would likely be better optimized with more of the calls together at the JS level as each back and forth adds overhead.
sudhakar3697 commentedon Aug 30, 2019
Thank you all :)
https://gist.github.com/gabrielschulhof/fcfdf47703f9ee21a7eebbc1600c49c4