andreasmattsson
01/13/2020, 10:23 AMvsnprintf
Big Chungus
01/13/2020, 10:24 AMandreasmattsson
01/13/2020, 10:27 AMBig Chungus
01/13/2020, 10:33 AMfun run(args: Array<String>? = null) = memScoped {
vsnprintf(args?.size ?: 0, args?.toCStringArray(this))
}
andreasmattsson
01/13/2020, 10:39 AMe: /Users/am/projects/sdg12-deeds-ios/deedster-common/lib-common/src/iOSMain/kotlin/se/sdg12/deedster/util/sprintf.kt: (21, 25): Type mismatch: inferred type is CPointer<CPointerVar<ByteVar /* = ByteVarOf<Byte> */> /* = CPointerVarOf<CPointer<ByteVarOf<Byte>>> */> but va_list? /* = CPointer<__va_list_tag>? */ was expected
Big Chungus
01/13/2020, 10:42 AM.reinterpret()
after itandreasmattsson
01/13/2020, 10:46 AMDominaezzz
01/13/2020, 10:49 AMnull
as the argument.Dominaezzz
01/13/2020, 10:50 AM...
wrapper for it. Then you can call it through that.Dominaezzz
01/13/2020, 10:52 AMandreasmattsson
01/13/2020, 10:57 AM*Ã rrayOf(...)
, which means I need to know the amount of args ahead of time. If I try to call with *runtimeConstructedAssignedArrayVariable
it failes to compile.Dominaezzz
01/13/2020, 11:02 AMDominaezzz
01/13/2020, 11:03 AMandreasmattsson
01/13/2020, 11:03 AMDominaezzz
01/13/2020, 11:06 AMandreasmattsson
01/13/2020, 11:07 AMmsink
01/13/2020, 11:11 AM@CCall("knifunptr_platform_posix672_sprintf")
external fun sprintf(__s: CValuesRef<ByteVar>?, @CCall.CString __format: String?, vararg variadicArguments: Any?): Int
@CCall("knifunptr_platform_posix675_vsprintf")
external fun vsprintf(__s: CValuesRef<ByteVar>?, @CCall.CString __format: String?, __arg: __gnuc_va_list?): Int
Dominaezzz
01/13/2020, 11:14 AMmsink
01/13/2020, 11:25 AMimport platform.posix.printf
fun main() {
printf("Hello %s%c", "World", '!'.toInt())
}
Hello World!
andreasmattsson
01/13/2020, 11:27 AMDominaezzz
01/13/2020, 11:27 AMnapperley
01/13/2020, 9:32 PMmsink
01/14/2020, 2:01 AMmemScoped
function with vararg
parameter, something like
fun memScoped(va: Array<>, block: (va_list) -> Unit)