Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Conversion of library types #10

Open
CasparKielwein opened this issue Mar 18, 2022 · 3 comments
Open

Feature Request: Conversion of library types #10

CasparKielwein opened this issue Mar 18, 2022 · 3 comments

Comments

@CasparKielwein
Copy link

CasparKielwein commented Mar 18, 2022

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
Copy link
Owner

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
Copy link
Author

CasparKielwein commented Mar 21, 2022

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
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants