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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:37:47+00:00 2026-06-11T10:37:47+00:00

I’m currently developing a simulator that runs on a server and should display data

  • 0

I’m currently developing a simulator that runs on a server and should display data in the browser.

For serving files, communication and things like that, I’d like to use Node.js. But, I’m not sure if it will perform as well as I’d want it to in the computation department, so I would like to develop the simulation part in C++.

The simulation is divided into separate “worlds”, which all start with some initial parameters.

What is the best way to do 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-11T10:37:48+00:00Added an answer on June 11, 2026 at 10:37 am

    Well, V8 allows for C++ code to be called from JavaScript.

    So you can have 3 parts of your code:

    • Normal C++, unaware of node.js and V8. This would be where World is.
    • Glue node.js/V8-C++ code, allowing JS to “see” parts of your World class.
    • Normal JavaScript code, which communicates with the C++ side via the “glue” layer

    First, understand how V8 and C++ communicate. Google provides a guide for this: https://developers.google.com/v8/embed

    Then, you need node.js specific glue. See http://www.slideshare.net/nsm.nikhil/writing-native-bindings-to-nodejs-in-c and http://syskall.com/how-to-write-your-own-native-nodejs-extension

    From the slideshare link above:

    #include <v8.h>
    #include <node.h>
    
    using namespace v8;
    
    extern "C" {
       static void init(Handle<Object> target) {}
       NODE_MODULE(module_name, init)
    }
    

    We can expand that into something closer to what you want:

    src/world.h

    #ifndef WORLD_H_
    #define WORLD_H_
    
    class World {
        public:
            void update();
    };
    
    extern World MyWorld;
    
    #endif
    

    src/world.cpp

    #include "world.h"
    #include <iostream>
    
    using std::cout;
    using std::endl;
    
    World MyWorld;
    
    void World::update() {
        cout << "Updating World" << endl;
    }
    

    src/bind.cpp

    #include <v8.h>
    #include <node.h>
    #include "world.h"
    
    using namespace v8;
    
    static Handle<Value> UpdateBinding(const Arguments& args) {
        HandleScope scope;
    
        MyWorld.update();
    
        return Undefined();
    }
    
    static Persistent<FunctionTemplate> updateFunction;
    
    extern "C" {
       static void init(Handle<Object> obj) {
          v8::HandleScope scope;
    
            Local<FunctionTemplate> updateTemplate = FunctionTemplate::New(UpdateBinding);
    
            updateFunction = v8::Persistent<FunctionTemplate>::New(updateTemplate);
    
          obj->Set(String::NewSymbol("update"), updateFunction->GetFunction());
       }
    
       NODE_MODULE(world, init)
    }
    

    demo/demo.js

    var world = require('../build/Release/world.node');
    world.update();
    

    wscript

    def set_options(opt):
      opt.tool_options("compiler_cxx")
    
    def configure(conf):
      conf.check_tool("compiler_cxx")
      conf.check_tool("node_addon")
    
    def build(bld):
      obj = bld.new_task_gen("cxx", "shlib", "node_addon") 
      obj.cxxflags = ["-g", "-D_FILE_OFFSET_BITS=64", "-D_LARGEFILE_SOURCE", "-Wall"]
      # This is the name of our extension.
      obj.target = "world"
      obj.source = "src/world.cpp src/bind.cpp"
      obj.uselib = []
    

    On Linux shell, some setup:

    node-waf configure
    

    To build, run:

    node-waf
    

    To test:

    node demo/demo.js
    

    Output:

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I want use html5's new tag to play a wav file (currently only supported
I have a French site that I want to parse, but am running into
In my XML file chapters tag has more chapter tag.i need to display chapters

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.