File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed
Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -51,6 +51,10 @@ fun main(args: Array<String>) {
5151 outputFile.writeText(luaOutput)
5252 println (" Generated Lua stubs for ${parsedClass.name} in ${outputFile.absolutePath} " )
5353 }
54+ val importsOutput = luaEmitter.emitAvailableImports(parsedClasses)
55+ val importsFile = File (outputDir, " imports.lua" )
56+ importsFile.writeText(importsOutput)
57+ println (" Generated Lua imports in ${importsFile.absolutePath} " )
5458 } catch (e: Exception ) {
5559 println (" Error processing $jarFilePath : ${e.message} " )
5660 }
Original file line number Diff line number Diff line change @@ -20,7 +20,11 @@ class LuaEmitter {
2020
2121 // Process fields (variables)
2222 parsedClass.fields.forEach { field ->
23- sb.appendLine(" ---@field ${field.visibility.toString().lowercase()} ${field.name} ${mapJavaTypeToLua(field.type)} " )
23+ sb.appendLine(
24+ " ---@field ${
25+ field.visibility.toString().lowercase()
26+ } ${field.name} ${mapJavaTypeToLua(field.type)} "
27+ )
2428 }
2529
2630 parsedClass.constructors.forEach { constructor ->
@@ -79,4 +83,16 @@ class LuaEmitter {
7983
8084 return sb.toString()
8185 }
86+
87+ fun emitAvailableImports (parsedClasses : List <ParsedClass >): String {
88+ val sb = StringBuilder ()
89+ sb.appendLine(" ---@alias JavaClasses" )
90+ parsedClasses.forEach { parsedClass ->
91+ val fullName = " ${parsedClass.packageName} .${parsedClass.name} "
92+ sb.appendLine(" ---| '\" $fullName \" '" )
93+ }
94+ // Add normal string to the alias as to not cause warnings when someone uses an import not in the list
95+ sb.appendLine(" ---| string" )
96+ return sb.toString()
97+ }
8298}
You can’t perform that action at this time.
0 commit comments