Kotlin/Native newbie question… I’m trying to work ...
# kotlin-native
c
Kotlin/Native newbie question… I’m trying to work with a library that defines all string parameters as
unsigned char *
. How do I take a Kotlin string and convert it to that? (cinterop has given the parameter the type
CValuesRef<UByteVar>
, which means I can’t just use
.cstr
or
.wcstr
)
Header file is https://github.com/yaml/libyaml/blob/master/include/yaml.h, function I’m looking at in particular is
yaml_parser_set_input_string
d
You'll need to use,
memScoped
and
cstr.getPointer(memScope).reinterpret<UByteVar>()
c
Thanks!
d
Also be aware that the string passed in will only live as long as the
memScoped
block.
n
The line
cstr.getPointer(memScope).reinterpret<UByteVar>()
can be replaced with
cstr.ptr.reinterpret<UByteVar>()
, provided cstr is allocated in the memScoped block.
c
Perfect, thanks