1

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

1 Answer 1

2

Does this play nice with java?

One thing that won't work is referencing synthetic properties that Kotlin uses to represent Java getters and setters, e.g. getFoo + setFoofoo (and you cannot use a bound callable reference bar::foo). This is not supported for now.

You can try to workaround that by a custom KMutableProperty0 implementation that accepts unbound callable references to Bar::getFoo, Bar::setFoo and bar and acts as a property reference in the sense of getting and setting its value.

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

A bound callable reference holds a reference to the receiver, so style::antiAliasedLines will keep style from GC, and you have to be careful about which callable references you store.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.