Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9074787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T18:43:07+00:00 2026-06-16T18:43:07+00:00

I am writing a C++ module for Node.js that wraps a C library, so

  • 0

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).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T18:43:08+00:00Added an answer on June 16, 2026 at 6:43 pm

    This is what I ended up doing:

    Local<Object> instance = constructor->NewInstance(2, argv);
    
    Local<Object> logLevel = Object::New();
    logLevel->Set(String::NewSymbol("ERROR"), cvv8::CastToJS(LOGLEVEL_ERROR), ReadOnly);
    logLevel->Set(String::NewSymbol("WARN"), cvv8::CastToJS(LOGLEVEL_WARN), ReadOnly);
    logLevel->Set(String::NewSymbol("INFO"), cvv8::CastToJS(LOGLEVEL_INFO), ReadOnly);
    
    instance->Set(String::NewSymbol("Level"), logLevel, ReadOnly);
    

    Then from JavaScript you can access logger.Level.ERROR.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a node.js module that exports two functions and I want to
I'm writing a kernel module that needs to read the value of bitrate from
I'm writing a Drupal module that deals with creating new nodes from CSV files.
I know that this is very un-Node/CommonJS-y—forgive me. (I'm writing a library of sorts
Problem Description I'm writing module for Android (JAVA) that use native code (C) .
I'm writing a scraper in node. Is there a module out there that will
I am writing a module for Drupal 7, that has 3 submodules. All submodules
I'm writing a module that has several methods. Let's consider this : package MyPackage;
When writing a Perl module, is it a good practice to use croak/die inside
I'm writing a python module for a device that interacts with a user supplied

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.