nbind icon indicating copy to clipboard operation
nbind copied to clipboard

Passing JS Objects

Open computerquip-streamlabs opened this issue 7 years ago • 1 comments

V8 allows passing JS objects to and from C++, using a map-like API to fetch object fields. I don't see anyway to do this with nbind unfortunately which somewhat complicates things for my current use. Are there any plans or discussion for supporting them?

computerquip-streamlabs avatar May 29 '17 01:05 computerquip-streamlabs

I found a project (which I think is the first use of github projects I've seen) here: https://github.com/charto/nbind/projects/4 (Issue https://github.com/charto/nbind/issues/11)

It's unfortunately looking a bit on the old side. Looking at other solutions such as v8pp, They seem to use an std::map though I'm unsure how that's supposed to work with multiple types. In their example, they have a map of strings with int values (what if the object had strings...?).

That issue doesn't actually list any possible problems with a design for accepting object arguments as well which somewhat makes it hard to work with. Some features I would considered required:

  • Nested objects
  • Undefined fields
  • Returning objects

How about a class that holds member variables that map to an object? You can use introspection to figure out the names of the class in order to fetch the values from the V8 object. If it's a user-defined type, then we can iterate into it for nesting support.

EDIT - Eh, not sure if that type of introspection is possible with VC++ unfortunately. 👎

I unfortunately haven't looked much into how nbind works and it's been awhile since I've delved into C++ black magic. Any feedback would be nice.

computerquip-streamlabs avatar May 29 '17 05:05 computerquip-streamlabs