dearimgui / dear_bindings

C header (and language binding metadata) generator for Dear ImGui
MIT License
221 stars 12 forks source link

Metadata: flag internal fields in public structure #7

Closed ocornut closed 2 years ago

ocornut commented 2 years ago

@emoon mentioned

You have named a bunch of enums with trailing _ to mark them as internal. I wonder if you have considered doing the same for struct variables as well? (the reason I'm asking is that in Rust you can expose visibility in structs on a per field basis) Currently there is a [internal] comment above the fields and I could perhaps use that, but that is a bit fragile really.

I first looked at adding an [Internal] marker on every line, but I think this rule would also work:

Assuming that's not difficult to handle in the parser/transform op. If it seems like a hassle I can add the marker on every line.

It would be good if dear_bindings could do that parsing and tag fields as "internal" for backend to decide.

I worry that hard-marking fields as non-visible in some languages may hinder some advanced use (there's sometime a blurry line where internal stuff can become useful), can Rust allow you to sort of bypass that?

ShironekoBen commented 2 years ago

This seemed like a pretty good idea to me, so I've implemented it as suggested and it seems to work. There's no affect on the .h file output, but in the JSON there is now an is_internal key that gets applied as appropriate. I've documented it with some notes to suggest implementers use it as a hint rather than an absolute barrier to access, as that seems most appropriate.

ocornut commented 2 years ago

Great! The commit is 4318b1ebb5f9ca22a8d73ad6cf6095f6244c107e it seems to work well. I imagine we might discover small bugs or inconsistent tagging in original sources and we can fix stuff when it happens.