mercredi 8 novembre 2017

Using reflection to pass and modify a primitive without using array

Working on a imgui port, I've been always used primitive arrays to simulate c++ pointers/addresses pass.

For example:

checkbox("Anti-aliased lines", bool.apply { set(0, style.antiAliasedLines) })
style.antiAliasedLines = bool[0]

where bool: BooleanArray

I just explored the possibility to directly pass the field instead, sort of c++:

ImGui::Checkbox("Anti-aliased lines", &style.AntiAliasedLines);

kotlin:

checkbox("Anti-aliased lines", style::antiAliasedLines })

I just needed to accomodate a corresponding KMutableProperty0<Boolean> on checkbox(), and I also double checked to have the possibility to set that field within the same function: there is a get(): Boolean and a set(Boolean)

My concerns are:

  • does this play nice with java?

  • are there any contraindications I should be aware of, if I go down this route? Such as performances or whatever?

Because I got the feeling that since this approach is somehow hacky and dirty





Aucun commentaire:

Enregistrer un commentaire