Allow passing interop types to C API, refactoring.

This commit is contained in:
Nikolay Igotti
2018-01-18 16:21:00 +03:00
committed by Nikolay Igotti
parent 76834dc7ce
commit 1599eddfe1
3 changed files with 33 additions and 19 deletions
@@ -1,3 +1,4 @@
import kotlinx.cinterop.*
// Top level functions.
fun hello() {
@@ -16,12 +17,14 @@ open class Base {
}
// Top level functions.
@konan.internal.CName(fullName = "topLevelFunctionFromC", shortName = "topLevelFunctionFromCShort")
fun topLevelFunction(x1: Int, x2: Int) = x1 - x2
@konan.internal.CName("topLevelFunctionVoidFromC")
fun topLevelFunctionVoid(x1: Int) {
fun topLevelFunctionVoid(x1: Int, pointer: COpaquePointer?) {
assert(x1 == 42)
assert(pointer == null)
}
// Enum.
@@ -36,8 +36,8 @@ int main(void) {
printf("object = %d\n", __ kotlin.root.Codeable.asCode(object1));
topLevelFunctionVoidFromC(42);
__ kotlin.root.topLevelFunctionVoid(42);
topLevelFunctionVoidFromC(42, 0);
__ kotlin.root.topLevelFunctionVoid(42, 0);
printf("topLevel = %d %d\n", topLevelFunctionFromC(780, 3), __ kotlin.root.topLevelFunctionFromCShort(5, 2));
__ DisposeString(string);