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 7860557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:20:26+00:00 2026-06-02T22:20:26+00:00

I’m trying to write a Node.js module, using C++, that wraps and exposes some

  • 0

I’m trying to write a Node.js module, using C++, that wraps and exposes some classes from libhdf5.

I’m currently interested in two classes from libhdf5. The first one is File, and it opens an hdf5 file. The second one is Group, and it represents groups within that file. You get Group objects from a File object.

I’ve written some code in which I create a File object and attempt to get a Group from it. I am trying to make my Node.js module as JavaScripty as possible, so I want to return the group using a callback. So, I am trying to code my module so that it’s used like this:

var hdf5 = require('hdf5');
var file = new hdf5.File('/tmp/example.h5');
file.getGroup('foobar', function (err, group) { console.log(group); });

So, in the C++ code for my File wrapper, I’d have a function that maps to the getGroup function here, and it’d call the given anonymous function, passing in any errors as well as the new Group object wrapper.

Given that this sounded to me like what the Node.js documentation shows to be a factory of wrapped objects, I have modeled my Group code after the examples there.

So, I have my Group wrapper coded up, but am stuck trying to instantiate it. I don’t know enough yet to know how to stray away from using the v8 Arguments class for function parameters. Because of that, I can’t seem to be able to pass in some parameters that I need for my v8 persistent constructor function (because I am instantiating this from C++, and not from JS-land).

  • 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-02T22:20:27+00:00Added an answer on June 2, 2026 at 10:20 pm

    You are almost there. You don’t need to pass Arguments to Group::Instantiate. Just pass what you need and use the constructor to create the new instance of Group. For example:

    Handle<Value> Group::Instantiate(const std::string& name) {
        HandleScope scope;
    
        Local<v8::Value> argv[1] = {
            Local<v8::Value>::New(String::New(name.c_str()))
        };
    
        return scope.Close(Constructor->NewInstance(1, argv));
    }
    

    The method Group::New does the rest of the construction work.

    Handle<Value> Group::New(const Arguments& args) {
        HandleScope scope;
    
        if (!args[0]->IsString()) {
            return ThrowException(Exception::TypeError(String::New("First argument must be a string")));
        }
        const std::string name(*(String::Utf8Value(args[0]->ToString())));
        Group * const group = new Group(name);
        bar->Wrap(args.This());
    
        return args.This();
    }
    

    In File::OpenGroup you can do this:

    Handle<Value> File::OpenGroup (const Arguments& args) {
        HandleScope scope;
    
        if (args.Length() != 2 || !args[0]->IsString() || !args[1]->IsFunction()) {
            ThrowException(Exception::SyntaxError(String::New("expected name, callback")));
            return scope.Close(Undefined());
        }
        const std::string name(*(String::Utf8Value(args[0]->ToString())));
        Local<Function> callback = Local<Function>::Cast(args[1]);
    
        const unsigned argc = 2;
        Local<Value> argv[argc] = {
            Local<Value>::New(Null()),
            Local<Value>::New(Group::Instantiate(name))
        };
        callback->Call(Context::GetCurrent()->Global(), argc, argv);
    
        return scope.Close(Undefined());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am currently running into a problem where an element is coming back from
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.