From e0696227c435ae09fc33d0820ff9757cdbccd706 Mon Sep 17 00:00:00 2001 From: nea Date: Sat, 16 Sep 2023 13:19:56 +0200 Subject: Better definitions --- src/main/kotlin/DefMain.kt | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/main/kotlin/DefMain.kt b/src/main/kotlin/DefMain.kt index 6d58a99..843b2a2 100644 --- a/src/main/kotlin/DefMain.kt +++ b/src/main/kotlin/DefMain.kt @@ -6,9 +6,11 @@ import java.io.PrintWriter @Serializable data class LModule( + val Name: String? = null, val Namespace: String? = null, val Functions: List = listOf(), val Tables: List = listOf(), + val Type: String = "System" ) @Serializable @@ -125,6 +127,32 @@ fun main() { for (module in json1.decodeFromString>(File("generated.json").readText())) { luaMeta.println() + if (module.Type == "ScriptObject") { + val interfaceName = module.Name!!.removeSuffix("API") + luaMeta.println("---@class $interfaceName") + luaMeta.println("$interfaceName = {}") + luaMeta.println() + for (function in module.Functions) { + luaMeta.println("---@param self $interfaceName") + for (par in function.Arguments) { + luaMeta.println("---@param ${par.Name}${if (par.Nilable) "?" else ""} ${compositeTypeStr(module, par)}") + require(par.Name != "self") + } + for (ret in function.Returns) { + luaMeta.println( + "---@return ${ + compositeTypeStr( + module, + ret + ) + }${if (ret.Nilable) "|nil" else ""} ${ret.Name}" + ) + } + luaMeta.println("function $interfaceName.${function.Name}(${(listOf("self") + function.Arguments.map { it.Name }).joinToString()}) end") + luaMeta.println() + } + continue + } if (module.Namespace != null) { luaMeta.println("${module.Namespace} = {}") luaMeta.println() -- cgit