Skip to content

Commit

Permalink
[OpenGL] Add support to function overload
Browse files Browse the repository at this point in the history
  • Loading branch information
squid233 committed Sep 23, 2023
1 parent e1f9ebd commit f2d977e
Showing 1 changed file with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,17 @@ data class Function(
val name: String,
val returnType: Type = void,
val nativeType: String?,
val params: List<Parameter>
)
val params: List<Parameter>,
val content: String? = null
) {
private val _overloads = ArrayList<Function>()
val overloads: List<Function>
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,
Expand Down Expand Up @@ -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}\") ")
Expand All @@ -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)
Expand All @@ -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("}")
Expand Down

0 comments on commit f2d977e

Please sign in to comment.