Is it possible to create a new constructor in JLCXX_MODULE?

JLCXX_MODULE define_julia_module(jlcxx::Module& types)
{
   types.add_type<World>("World")
    .constructor<const std::string&>()
    .constructor<int_t>(false) // no finalizer
    .method("set", &World::set)
    .method("greet", &World::greet)
    .method("greet_lambda", [ ](const World& w) { return w.greet(); } );
}

As shown above, we can create a new member function “greet_lambda” that is not defined in C++ class. Is it possibe to create a new constructor? If yes, what is its syntax, may I have a simple demo? Thanks

Sorry for the late reply, I don’t follow the forum as closely as I’d like lately.

The preferred way to do this is to add the constructor on the Julia side, using existing C++ constructors. If you absolutely need to do it in C++, you can add a free function with the name of the type and return the value using create:

JLCXX_MODULE define_julia_module(jlcxx::Module& types)
{
   // ...

  types.method("World", [] (double d) { return jlcxx::create<World>("constructed from double"); });

}