0

I wonder if it is possible to use the "os" module internally in native module, without passing it over as a param from javascript.

It's one of the core nodejs/electron modules so I assume it should be available in native module internally some way or another.

Konstantin
  • 339
  • 2
  • 15
  • 1
    I don't think any of the C++ code from node's os module is available to link against. You can call JS from C++, but it's by no means efficient -- see https://stackoverflow.com/a/11387695/1218408 for example. Most of what's in node's OS module is trivial to re-implement. – ZachB Sep 05 '17 at 23:34
  • Thank you for two nice ideas! If you can provide further info on how to easily grab the OS module functions as C++ native code in the form of an answer, I will gladly accept it ) – Konstantin Sep 07 '17 at 13:39

1 Answers1

0

Expanding on my comment:

As far as I know, none of node's "os" module C++ code is exported for use by other C++ code.

Executing JS from C++ is possible, but far from efficient. (See https://stackoverflow.com/a/11387695/1218408 for an example of how to do it.)

Most of node's "os" module is fairly simple, and you're probably better off re-implementing whatever you need. The source for it is here: https://github.com/nodejs/node/blob/master/src/node_os.cc

Another possibility is to call your C++ functions with the result of whatever JS function you need. For example, maybe myFunction(os.loadavg(), "hello"). Simple but also not super efficient.

ZachB
  • 13,051
  • 4
  • 61
  • 89