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

  • Home
  • SEARCH
  • 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 8432315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:05:40+00:00 2026-06-10T06:05:40+00:00

I am trying to write a nodejs bindings for a C++ library and I

  • 0

I am trying to write a nodejs bindings for a C++ library and I seem to have hit a roadblock.

I am working on trying to make all the calls to the C++ library asynchronous and thats why I am using libuv. I am basically following this tutorial.

I want to be able to call class member functions from libuv’s uv_queue_work. Have a look at this code —

class test {
  private:
    int data;
    void Work(uv_work_t *req);
    void After(uv_work_t *req);
  public:
    Handle<Value> Async(const Arguments& args) {
      HandleScope scope;
      Local<Function> callback = Local<Function>::Cast(args[0]);
      int status = uv_queue_work(uv_default_loop(), **something**, Work, After);
      assert(status == 0);
      return Undefined();
    }
};

Basically I expect the Work and After functions to work on the data element of the class. However this doesnt seem to work. I have tried typecasting the pointers to Work and After after from type void test::(*)(uv_work_t*) to void (*)(uv_work_t*). But that also doesnt seem to work.

Could you guys give me some tips on how to work around this??

  • 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-10T06:05:42+00:00Added an answer on June 10, 2026 at 6:05 am

    So as you’ve realized, you cannot call the member functions directly.

    The second argument “something” is of type uv_work_t, which has a member “void* data”.

    What you will need to do is create static methods inside your class for “Work” and “After”, create a uv_work_t structure, and assign data to “this”.

    Once that is done inside your static “Work” and “After” methods you do a static cast on “req->data” (To your class type) and then call your member functions.

    For example:

    uv_work_t* baton = new uv_work_t();
    baton->data = this;
    int status = uv_queue_work(uv_default_loop(), baton, StaticWork, StaticAfter);
    

    And then in the static methods

    test* myobj = static_cast<test>(req->data);
    myobj->Work();
    

    And similar code for the StaticAfter function

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

Sidebar

Related Questions

I am trying to write a scientific graph library, it works but I have
I'm trying to write a web application using nodejs and couchdb. In couch i
Trying to write app for service technicians that will display open service calls within
I am trying to write a nodejs server that will take a time input
I'm trying to make a report treeview thing. Where I could write some text
I am trying to write a routing framework of nodejs, I need to add
I am trying to write a simple polling application using NodeJS. I'm wanting to
I have been trying to write a powershell program that checks to see if
I'm trying to write a REST-API server with NodeJS like the one used by
I am trying to write an XQuery which would find all text nodes that

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.