summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authornea <nea@nea.moe>2023-08-22 12:39:32 +0200
committernea <nea@nea.moe>2023-08-22 12:39:32 +0200
commit2904a9a9bd4f4ed7681ebd1c821401020a6118c7 (patch)
tree42911e665bb4e130824747e2e1e100b36f1a82b9 /src
parent39f1849edcaa9005814525cd13f76a5daaa15ae0 (diff)
downloadnealisp-2904a9a9bd4f4ed7681ebd1c821401020a6118c7.tar.gz
nealisp-2904a9a9bd4f4ed7681ebd1c821401020a6118c7.tar.bz2
nealisp-2904a9a9bd4f4ed7681ebd1c821401020a6118c7.zip
Opaque foreign object mapping
Diffstat (limited to 'src')
-rw-r--r--src/bind/AutoBinder.kt17
-rw-r--r--src/bind/LispBinding.kt4
2 files changed, 21 insertions, 0 deletions
diff --git a/src/bind/AutoBinder.kt b/src/bind/AutoBinder.kt
index 6d2cac2..648aaef 100644
--- a/src/bind/AutoBinder.kt
+++ b/src/bind/AutoBinder.kt
@@ -22,6 +22,22 @@ class AutoBinder {
return null
}
+ private fun mapForeignObject(parameter: Parameter): ObjectMapper? {
+ parameter.getAnnotation(UnmapForeignObject::class.java) ?: return null
+ return { a, b, c, d ->
+ when (val x = a()) {
+ is LispData.ForeignObject<*> -> {
+ parameter.effectiveType.cast(x.obj)
+ }
+
+ else -> {
+ c.reportError("$x needs to be of type")
+ null
+ }
+ }
+ }
+ }
+
private fun mapErrorReporter(parameter: Parameter): ObjectMapper? {
if (ErrorReporter::class.java.isAssignableFrom(parameter.effectiveType)) return { a, b, c, d -> c }
return null
@@ -95,6 +111,7 @@ class AutoBinder {
::mapString,
::mapBoolean,
::mapAST,
+ ::mapForeignObject,
)
diff --git a/src/bind/LispBinding.kt b/src/bind/LispBinding.kt
index 7af0e67..2a4c688 100644
--- a/src/bind/LispBinding.kt
+++ b/src/bind/LispBinding.kt
@@ -5,3 +5,7 @@ package moe.nea.lisp.bind
annotation class LispBinding(
val name: String,
)
+
+@Retention(AnnotationRetention.RUNTIME)
+@Target(AnnotationTarget.VALUE_PARAMETER)
+annotation class UnmapForeignObject