Comments (3)
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.
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.
Let's track this in a project instead.
from nbind.
Related Issues (20)
- Delay in handoff from C++ to Node awaiter
- nbind doesn't work with electron-packager
- Can't pass char* from JS to cpp function HOT 1
- Windows | EMCC should have a batch file too. (emcc-path)
- Is there any way to call javascript method from c++ HOT 1
- Use of `eval` violates Content Security Policy in browsers HOT 7
- Incompatible with electron 4 and later? HOT 4
- NBind not working with Node 12.0.0
- Release on Node12 HOT 9
- Fail to build with electron 5.0.8, deprecated methods
- Problem when using with proton native HOT 1
- Node 13 build errors HOT 2
- unresolved external
- unresolved external HOT 2
- sample app refuses to run
- npm i produces error "type-check is deprecated" and "Type 'string' cannot be used to index type 'ExportType'."
- Error while dooing fourth step HOT 5
- Iterator support?
- Is this project dead? HOT 2
- std::string support is broken
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nbind.