napperley
09/17/2019, 4:35 AMcfg_init
from libconfuse) that is expecting a CValuesRef<cfg_opt_t>?
as the first argument. Using the cValuesOf
function returns CValues<CPointerVar<cfg_opt_t>>
which doesn't match. Below is the sample code:
val targetStr = configString(name = "target".cstr, def = "NONE".cstr, flags = CFGF_NONE)
val end = configEnd()
val config = cfg_init(cValuesOf(targetStr, end), CFGF_NONE)
napperley
09/17/2019, 4:40 AMpublic fun cfg_init(opts: kotlinx.cinterop.CValuesRef<libconfuse.cfg_opt_t>?, flags: libconfuse.cfg_flag_t /* = <http://kotlin.Int|kotlin.Int> */): kotlinx.cinterop.CPointer<libconfuse.cfg_t>? { /* compiled code */ }
Artyom Degtyarev [JB]
09/17/2019, 11:03 AMval elements = arrayOf(targetStr, end)
val opts = createValues<cfg_opt_t>(elements.size) { index -> this.value = elements[index] }
val config = cfg_init(opts, CFGF_NONE)
napperley
09/17/2019, 10:11 PMnapperley
09/17/2019, 10:23 PMval opts = createValues<cfg_opt_t>(elements.size) { pos ->
val tmp = elements[pos]
if (tmp != null) {
this.name = tmp.pointed.name
this.flags = tmp.pointed.flags
}
}
Unfortunately this.def is read only which is a bit of a pain. Means a default value cannot be set for the first configuration option.napperley
09/17/2019, 10:28 PMnapperley
09/17/2019, 10:30 PMinternal error in cfg_init_defaults(@�")
/home/napperley/battery_telemetry.conf:1: no such option 'target'
Looks as though the config options haven't been properly initialised.napperley
09/17/2019, 10:44 PMcreateValues
function in the Kotlin Native documentation, for C interop in the Passing pointers to bindings section ( https://github.com/JetBrains/kotlin-native/blob/master/INTEROP.md#passing-pointers-to-bindings ).