From f2d977ebe9288ff82cbef8cd2dbef68e71ccad68 Mon Sep 17 00:00:00 2001 From: squid233 <60126026+squid233@users.noreply.github.com> Date: Sat, 23 Sep 2023 19:43:42 +0800 Subject: [PATCH] [OpenGL] Add support to function overload --- .../overrungl/opengl/OpenGLGenerator.kt | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/modules/overrungl.opengl/src/generator/kotlin/overrungl/opengl/OpenGLGenerator.kt b/modules/overrungl.opengl/src/generator/kotlin/overrungl/opengl/OpenGLGenerator.kt index 35bb146c..091aecf8 100644 --- a/modules/overrungl.opengl/src/generator/kotlin/overrungl/opengl/OpenGLGenerator.kt +++ b/modules/overrungl.opengl/src/generator/kotlin/overrungl/opengl/OpenGLGenerator.kt @@ -118,8 +118,17 @@ data class Function( val name: String, val returnType: Type = void, val nativeType: String?, - val params: List -) + val params: List, + val content: String? = null +) { + private val _overloads = ArrayList() + val overloads: List + get() = _overloads + + operator fun String.invoke(returnType: Type, content: String, vararg params: Parameter, nativeType: String? = null) { + _overloads.add(Function(this, returnType, nativeType, params.toList(), content)) + } +} class OpenGLFile( val name: String, @@ -187,7 +196,7 @@ class OpenGLFile( appendLine(" }") appendLine() // functions - functions.forEach { f -> + fun appendFuncHeader(f: Function) { append(" public static ") if (f.nativeType != null) append("@NativeType(\"${f.nativeType}\") ") @@ -199,6 +208,9 @@ class OpenGLFile( append("${it.type} ${it.name}") } appendLine(") {") + } + functions.forEach { f -> + appendFuncHeader(f) appendLine(" final var ext = getExtCapabilities();") appendLine(" try {") if (f.returnType != void) @@ -215,6 +227,15 @@ class OpenGLFile( """.trimMargin() ) appendLine() + + // overloads + if (f.overloads.isNotEmpty()) { + f.overloads.forEach { overload -> + appendFuncHeader(overload) + appendLine(overload.content!!.prependIndent(" ")) + appendLine(" }\n") + } + } } } appendLine("}")