arximboldi / schmutz

SCHeMe UnterstüTZung — easy Guile Scheme C++ bindings
https://sinusoid.es/schmutz
Boost Software License 1.0
45 stars 7 forks source link

Feature Request: Conversion of library types #10

Open CasparKielwein opened 2 years ago

CasparKielwein commented 2 years ago

Hi,

I have hit the point where I need to pass more complex types through my scheme bindings. The primitives as currently supported by schmutz through to_cpp and from_cpp are no longer enough. I have patched my version to support some types I need, but that's hardly sustainable.

I can see how support of std types could be provided by schmutz itself, like many other binding libraries for other script languages do. But I am using schmutz together with third party libraries, in particular QT.

Is there a concept how to add conversion functions as a user of schmutz? I haven't understood the internals enough to develop it from scratch myself. If you can provide a design outline, I'm happy to implement it.

It could be complicated by the fact, that some libraries, in particular QT, don't use namespaces properly, which makes an Argument Dependent Lookup based approach difficult.

arximboldi commented 2 years ago

I'm not a 100% sure what you're trying to achieve here. Does scm::type not work for you? Or you want to register aliases to float and so on, like qreal?

CasparKielwein commented 2 years ago

I would like to be able to do the following

group("foo")
    .define("bar", [](std::string text){ something_internal(text); })
    .define("barz", []() { return internal_string(); });

and use foo-bar and foo-barz in scheme code.

It would also be nice if there is a way to register converters from scheme lists, vectors, etc. to cpp containers. In my case I would prefer "std::vector <-> list", but I recognize that there are many alternatives.

group("foo2")
    .define("bar", [](std::vector<int> vec){ something_internal(vec); })
    .define("barz", []() { return internal_int_vector(); });

If I can achieve that with scm::type it would be nice if you could give me a hint how.

arximboldi commented 2 years ago

Not sure if this is exactly what you are looking for, but you can check the examples here where I use the library to create an efficient immtuable vector:

https://github.com/arximboldi/immer/blob/master/extra/guile/src/immer.cpp https://github.com/arximboldi/immer/blob/master/extra/guile/example.scm