v8pp icon indicating copy to clipboard operation
v8pp copied to clipboard

Indexed access

Open ayles opened this issue 6 years ago • 3 comments

What about setting indexed accessor on class_? (Simulating array behaviour, for examle). I tried to write it myself but I have no complete idea how to do it right. Maybe something like set_indexed_accessor(accessor<Getter, Setter>)? (Like property_ for set) So I need some recommendations and I'll try to do it.

ayles avatar Aug 29 '19 15:08 ayles

Hi,

I like the idea and some time ago there was a request for this feature in #47. Unfortunately, I've never used indexed accessors, so they are still not implemented.

A possible implementation could be generalized both for indexed and named property accessors, and it would be good to support also lambdas, similar to the current property accessor implementation. The next version (in c++17 branch) has no set_ prefixed bind functions, so it could be named as indexer(getter, setter).

Anyway, a pull request is greatly welcomed 😃

pmed avatar Aug 29 '19 19:08 pmed

Hmmmm.

I implemented indexer in c++17 as indexer(getter, setter), but there is one problem... Idk should I add support for (...query, deleter, enumerator). If should, it will be implementation separated from property, so I'm here with this question =)

ayles avatar Aug 30 '19 14:08 ayles

As I understand from comments to v8::IndexedPropertyHandlerConfiguration only getter is required, so other callbacks are optional. But as a generic solution, it would be nice to support them in the v8pp.

The property has a specialisation for read-only case with only a pointer to getter function. This allows to have sizeof(property) == sizeof(void*) with no extra memory management for v8::External data storage.

Similar way may be used for a new indexed_property implementation.

pmed avatar Sep 01 '19 15:09 pmed