-
Notifications
You must be signed in to change notification settings - Fork 63
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
How to convert options hash with Rice? #202
Comments
That should work with one minor adjustment, you need to explicitly splat out the hash to be considered "keyword arguments" with the double star opts = { "opt_1" => 1, "opt_2" => "string", "opt_3" => 5.0 }
MyClass.new.foo(**opts) Then, as long as you wrap |
Ok, apologies, I went and made absolutely sure, and no Rice does not currently support this kind of splatting. It still comes across as a Hash argument. So for now you'll need to do what it sounds like you've already done, splitting the Hash apart yourself and passing the values through as needed. |
It would be a nice addition to handle keyword args. When calling define_function/method Rice currently supports
Rice could then update its code that generates an Which in this case would be Having said all that, Rice determines the number of of arguments to a function at compile time based on the C++ function definition and send a tuple of that size to Nice summary here - https://blog.appsignal.com/2023/01/18/how-to-parse-arguments-in-your-ruby-c-extension.html. Pybind does this a bit differently - see https://pybind11.readthedocs.io/en/stable/advanced/functions.html#accepting-args-and-kwargs. |
The intent of making We'll probably need to play with some ideas here to see what would work and what doesn't. |
Thanks for the link to Magnus. |
I'm integrating Rice into Ruby-C extension and wondered what is the Rice way to convert options hash to cpp types. I ended up checking for each type explicitly, is there a generic way to do it?
For example, Ruby code I'd like to execute:
Underlying cpp class:
The text was updated successfully, but these errors were encountered: