hermes icon indicating copy to clipboard operation
hermes copied to clipboard

C++ class bindings

Open verenkoska opened this issue 1 year ago • 3 comments

Problem

As mentioned in the title, is there any plan to introduce class bindings? It’s nice we now have support for classes in Hermes, but I haven’t found any method for class bindings yet.

This could be useful for my use case, Thank you

verenkoska avatar May 04 '24 21:05 verenkoska

Unfortunately we don't have support for classes. There is an AST transformation, but it is unsupported, undocumented, not fully spec-compliant and we don't recommend using it. However we are working on classes and we will publish fully working classes implementation in the Static Hermes branch within a month.

What does "class bindings" mean?

tmikov avatar May 05 '24 03:05 tmikov

Nice to know, thanks @tmikov ! Let's say I have two classes in C++:

class Base {
    ....
}

class Derived : public Base {
    ....
}

I want to be able to bind all methods and constructor, so I can use and instantiate objects of the two classes inside JS. Will you have specific methods to do so in the Static Hermes branch?

verenkoska avatar May 05 '24 07:05 verenkoska

@verenkoska unrelated, but I built a framework called Nitro that allows you to do that.

C++, and even Swift or Kotlin classes can be exposed to JS. With methods, property (getter + setter), and inheritance support. See Hybrid Objects for more info

mrousavy avatar Dec 06 '24 17:12 mrousavy