From 540826fb6eed6496613aba727f90acee8f4454c6 Mon Sep 17 00:00:00 2001 From: Alex Zenla Date: Thu, 7 Sep 2023 01:07:43 -0700 Subject: [PATCH] ffi: shorthand for some java types --- examples/java.pork | 2 +- .../main/kotlin/gay/pizza/pork/ffi/JavaNativeProvider.kt | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/examples/java.pork b/examples/java.pork index 3aab150..1acd09b 100644 --- a/examples/java.pork +++ b/examples/java.pork @@ -2,7 +2,7 @@ func java_system_err() native java "java.lang.System:static-getter:err:java.io.PrintStream" func print_stream_println(stream, line) - native java "java.io.PrintStream:virtual:println:void:java.lang.String" + native java "java.io.PrintStream:virtual:println:void:String" export func main() { let error = java_system_err() diff --git a/ffi/src/main/kotlin/gay/pizza/pork/ffi/JavaNativeProvider.kt b/ffi/src/main/kotlin/gay/pizza/pork/ffi/JavaNativeProvider.kt index 4c42b96..4a3698e 100644 --- a/ffi/src/main/kotlin/gay/pizza/pork/ffi/JavaNativeProvider.kt +++ b/ffi/src/main/kotlin/gay/pizza/pork/ffi/JavaNativeProvider.kt @@ -13,7 +13,7 @@ class JavaNativeProvider : NativeFunctionProvider { val functionDefinition = JavaFunctionDefinition.parse(definition) val javaClass = lookupClass(functionDefinition.type) val returnTypeClass = lookupClass(functionDefinition.returnType) - val parameterClasses = functionDefinition.parameters.map { lookup.findClass(it) } + val parameterClasses = functionDefinition.parameters.map { lookupClass(it) } val handle = mapKindToHandle( functionDefinition.kind, functionDefinition.symbol, @@ -26,6 +26,12 @@ class JavaNativeProvider : NativeFunctionProvider { private fun lookupClass(name: String): Class<*> = when (name) { "void" -> Void.TYPE + "String" -> String::class.java + "byte" -> Byte::class.java + "char" -> Char::class.java + "short" -> Short::class.java + "int" -> Int::class.java + "long" -> Long::class.java else -> lookup.findClass(name) }