TheLartians / Glue

⛓️ Bindings that stick. A simple and generic API for C++ to other language bindings supporting bidirectional communication, inheritance and automatic declarations.
MIT License
56 stars 2 forks source link

Using smart pointer constructor #73

Open janvorisek opened 9 months ago

janvorisek commented 9 months ago

Thanks for a really useful library!

Is it possible to make addConstructor use smart pointers?

I.e., in emscripten I can do

EMSCRIPTEN_BINDINGS(better_smart_pointers) {
    class_<C>("C")
        .smart_ptr_constructor("C", &std::make_unique<C>)
        ;
}

My cpp library works with smart pointers all the time. Now I want to utilize it in Typescript via emglue.

Is that possible?

TheLartians commented 9 months ago

Hey, thanks for the issue! If I remember correctly this should already be possible (see here for an example), however the library uses std::shared_ptr instead of std::unique_ptr, as multiple references to the same object may be kept in different places.

It should be easily possible to construct a shared pointer from a unique one to bind your library to TypeScript.