I am writing a C++ module for Node.js that wraps a C library, so we can use the C library from JavaScript. One of the functions in the C library takes an enum parameter, with the enum values included in the corresponding header file. I would like to export the enum values as integers from the C++ module so the Node.js application wouldn't have to hardcode the value. Here is the basic idea:
C:
typedef enum
{
LOGLEVEL_ERROR = 0,
LOGLEVEL_WARN,
LOGLEVEL_INFO
} log_level_t;
write_to_log(log_level_t level, char* message);
C++:
Logger::Write(int level, char* message)
{
write_to_log(level, message);
}
Node.js:
// This is what I want:
logger.write(logger.ERROR, "Oh no! Something bad happened.");
How do I expose LOGLEVEL_ERROR from C++ so I can use logger.ERROR in JS? (I would even be OK with logger.LOGLEVEL_ERROR in JS.) I found an old Node.js native module that used a macro EXPORT_INT32 but this doesn't seem to exist anymore (I'm using Node.js 0.8.8).