Giter Club home page Giter Club logo

Comments (3)

bsergeev avatar bsergeev commented on September 26, 2024 1

How about adding support for (some) STL containers like std::pair?
If nbind could define some typical types like std::pair<int,int> as well as provide their JS counterparts and default bindings, this would make passing such containers much easier.
(I am not sure if embind provides similar facilities...)

from nbind.

jjrv avatar jjrv commented on September 26, 2024

Embind supports both std::vector and emscripten::val for passing JavaScript arrays, and std::vector support is also planned for nbind very soon. Then std::map corresponding to JavaScript objects would be next.

More complicated structures have 2 issues. A JavaScript Array or Object might consist of different types of elements, so it's not mappable to a standard library type (unless the values are then like emscripten::val). Also, we don't know how it will be used in C++. If all the fields are needed, possibly several times, it would be better to copy the structure to the C++ heap to avoid constant round-trips across languages. But if just a few fields are needed, it's best not to copy everything and instead access them through function calls like Embind does.

In Node.js, C++ and JavaScript share the same heap and a good C++ API is available for accessing everything, so copying data to any other structure doesn't really make sense (except to std::vector for quick access in all sorts of algorithms). In Emscripten C++ has no access to the JavaScript heap in general and accessing the C++ heap from JavaScript is painful. Complicated structures should be processed fully in JavaScript to avoid bloat.

Finally, for targeting React Native or Cordova or similar, complicated data probably needs to pass through an Objective C, Swift or Java bridge and it would be easiest to serialize it somehow. Probably still not to JSON, but a binary format copied from one heap to another.

The syntax for accessing the data from C++ should be identical and sensible in all cases. This will take some long-term effort to figure out.

from nbind.

jjrv avatar jjrv commented on September 26, 2024

Let's track this in a project instead.

from nbind.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.