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

Support for argument names, keyword arguments and argument default values #399

Closed
wants to merge 6 commits into from

Conversation

melven
Copy link
Contributor

@melven melven commented Jan 8, 2024

Inspired by pybind11, this allows to write:

m.method("name", &function, jlcxx::arg("firstArg"), jlcxx::arg("secondArg")=7, jlcxx::kwarg("hello")=5, jlcxx::kwarg("there")=42);

Which translates roughly to:

name(firstArg::Type1, secondArg::Type2 = 7; hello::Type3, there::Type4 = 42)

Also supports docstrings (just a const char* argument) and additional arguments of some variants of method (calling convention) have extra enum types (to allow parsing arbitrary arguments).
Example:

  mod.method("test_exception", test_exception, jlcxx::calling_policy::std_function);

@melven
Copy link
Contributor Author

melven commented Jan 8, 2024

Needs again corresponding changes in libcxxwrap-julia: JuliaInterop/libcxxwrap-julia#142

Is based on the docstring merge request #396 ...

@barche
Copy link
Collaborator

barche commented Jan 12, 2024

Thanks for this, I would like to integrate this together with the docstring support in the next release, so that way we only have one breaking change.

@barche
Copy link
Collaborator

barche commented Jan 13, 2024

If this is ready for you I can merge this into the testjll branch before merging JuliaInterop/libcxxwrap-julia#142 so everything is tested.

@melven
Copy link
Contributor Author

melven commented Jan 13, 2024

Ready from my side - only remaining thing is to further update the README (breaking changes and examples for keyword/default arguments)

@melven melven marked this pull request as ready for review January 13, 2024 20:42
@barche
Copy link
Collaborator

barche commented Jan 13, 2024

It seems that sometimes an extra \0 is added to the method symbols:

Expression: ((methods(CppTestFunctions.concatenate_numbers_with_named_args))[1]).slot_syms == "#self#\0i\0d\0val\0"
    Evaluated: "#self#\0i\0d\0val\0\0" == "#self#\0i\0d\0val\0"

See log at e.g. https://github.com/JuliaInterop/libcxxwrap-julia/actions/runs/7514928755/job/20458329641#step:4:495

And there is also a precompile error on Julia 1.6:
https://github.com/JuliaInterop/libcxxwrap-julia/actions/runs/7514928755/job/20458329374#step:4:343

@melven
Copy link
Contributor Author

melven commented Jan 16, 2024

I tried to fix both problems, can you triger the checks @barche ?

@barche
Copy link
Collaborator

barche commented Jan 16, 2024

Thanks, I added your last commit to the testjll branch and did one more small fix, and now all tests pass. I'll rebuild a JLL now on Yggdrasil, and then manually merge this from testjll to main.

@barche
Copy link
Collaborator

barche commented Jan 17, 2024

The changes are merged into main now, it should be possible to test by doing add CxxWrap#main.

@barche barche closed this Jan 17, 2024
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

Successfully merging this pull request may close these issues.

2 participants