Hello, I’m trying to implement Kotlin/Native bindings for tree-sitter
and I have a Node
class that looks kinda like this:
class Node(internal val self: CValue<TSNode>) {
val symbol: UShort
get() = ts_node_symbol(self)
/* etc. */
fun edit(/* args */): Unit {
val edit = cValue<TSInputEdit> {
/* set fields */
}
ts_node_edit(self, edit)
// ^ how do I pass a _reference_ to self here?
}
}
In the C API, every ts_node_
function uses a TSNode
by value,
except for ts_node_edit
which takes a reference and modifies the value.
TSSymbol ts_node_symbol(TSNode self);
void ts_node_edit(TSNode *self, const TSInputEdit *edit);
How do I achieve this in Kotlin? Methods like place()
and getPointer()
return a reference to a copy and don’t modify the original value.