pmed / v8pp

Bind C++ functions and classes into V8 JavaScript engine
http://pmed.github.io/v8pp/
Other
901 stars 121 forks source link

Auto wrap pointer #134

Closed cr-mitmit closed 2 years ago

cr-mitmit commented 4 years ago

Support auto_wrap when a pointer type is returned from function. In existing code, when a pointer type is returned from wrapped method, it will ignore the autowrap flag and only wrap if object is already wrapped using `class::referenceexternalorclass::import_external`. With this patch, when a pointer type is returned (technically when passed to find_object) if auto-wrap is supported either of the following two happens.

  1. If the return type is std::shared_ptr and we've defined auto_wrap for class_<T, shared_ptr_traits>, this object is wrapped and returned.
  2. If the return type is T and we've defined auto_wrap for class_<T, raw_ptr_traits> and T is std::is_copy_constructible than T is copy-constructed the copy* is wrapped. Otherwise, the existing behavior (i.e. returning an empty handle) is kept

This patch includes the changes in ptr_traits.hpp and additional tests to ensure the above works correctly.

Nelson-numerical-software commented 2 years ago

any reason that it was not merged ?

pmed commented 2 years ago

any reason that it was not merged ?

Hi,

this feature has been already implemented in c++17 branch that was recently merged onto the master one.

I've added a section to documentation: Auto-wrapping objects

So I'm closing this pull request.