Skip to content

Commit

Permalink
ffi: shorthand for some java types
Browse files Browse the repository at this point in the history
  • Loading branch information
azenla committed Sep 7, 2023
1 parent 953679b commit 540826f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion examples/java.pork
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 7 additions & 1 deletion ffi/src/main/kotlin/gay/pizza/pork/ffi/JavaNativeProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
}

Expand Down

0 comments on commit 540826f

Please sign in to comment.