-
Notifications
You must be signed in to change notification settings - Fork 7
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
Come up with a better way to pass strings into the bindings. #6
Comments
...look at imgui-rs for inspiration: https://github.com/imgui-rs/imgui-rs/blob/main/imgui/src/string.rs ...sokol-rust can probably be easier it can temp-allocate before the C function is called, and free right after, because the sokol headers copy the data internally if needed. |
Yes. I partially did this for functions that took a string as a parameter. These functions will have a The reason I didn't do this for the structs (such as where the window title is needed^) was that it would become a bit more complicated since we would have to do this in all functions that take a struct that holds a string. This is of course possible but was a bit more bookkeeping than I was willing to think about for the initial bindings xP |
In #25, Floh commented:
I've been using this syntax in other crates and it is very nice. Trying this out in this repo, this compiles and runs on macOS:
|
So if you want, I can do this across the repo and submit a PR. |
Ah I see, so the new form would be If you want to provide a PR to fix the examples, please don't bother with the shader.rs files since those are code-generated via sokol-shdc anyway. But a fix for the actual example sources would be much appreciated :) I'm currently working on sokol-shdc in a branch anyway and will integrate the change there as a 'drive-by fix', and then convert the shader.rs files in the sokol-rust repo once that PR is merged (might take a little while, since the actual reason for the PR is storage-buffer support). |
Already did the shader files ... just 2 search / replace functions. :) I'll finish up and submit the PR tomorrow though as it is late here (and should also update docs to say that the samples require Rust 1.77). |
This doesn't look very nice:
If that's the only way to define a C string in Rust then maybe it would make sense to create 2 structs in the bindings, one internal struct with C compatible types, and a separate public struct with 'Rust-y' types. The wrapper function would then create a temporary C-compatible struct, copy the values from the public struct over and do any type conversion.
The text was updated successfully, but these errors were encountered: