@@ -13,34 +13,41 @@ fun main(args: Array<String>) {
1313 return
1414 }
1515
16+ // Parse the --output-dir flag
17+ val outputDirFlag = args.find { it.startsWith(" --output-dir=" ) }
18+ val outputDirPath = outputDirFlag?.substringAfter(" =" ) ? : " ./stubs"
19+ val outputDir = File (outputDirPath)
20+
21+ // Ensure the output directory exists
22+ if (! outputDir.exists() && ! outputDir.mkdirs()) {
23+ println (" Error: Could not create output directory at $outputDirPath " )
24+ return
25+ }
26+
1627 // Initialize the emitter
1728 val luaEmitter = LuaEmitter ()
1829
19- args.forEach { jarFilePath ->
20- // Check if the file exists
30+ args.filterNot { it.startsWith(" --output-dir=" ) }.forEach { jarFilePath ->
2131 val file = File (jarFilePath)
2232 if (! file.exists()) {
2333 println (" Warning: File $jarFilePath does not exist." )
2434 return @forEach
2535 }
2636
27- // Determine if the file is a source JAR or compiled JAR
28- val parser : ClassParser = if (jarFilePath.endsWith(" -sources.jar" )) {
37+ val parser: ClassParser = if (jarFilePath.endsWith(" -sources.jar" )) {
2938 println (" Using JavaSourceParser for $jarFilePath " )
3039 JavaSourceParser ()
3140 } else {
3241 println (" Using CompiledClassParser for $jarFilePath " )
33- JavaSourceParser ()
42+ JavaSourceParser () // Placeholder for compiled class parser
3443 }
3544
3645 try {
37- // Parse the JAR file
3846 val parsedClasses = parser.parse(JarFile (file))
3947
40- // Generate Lua stubs for each parsed class
4148 parsedClasses.forEach { parsedClass ->
4249 val luaOutput = luaEmitter.emit(parsedClass)
43- val outputFile = File (" stubs/ ${parsedClass.name} .lua" )
50+ val outputFile = File (outputDir, " ${parsedClass.name} .lua" )
4451 outputFile.writeText(luaOutput)
4552 println (" Generated Lua stubs for ${parsedClass.name} in ${outputFile.absolutePath} " )
4653 }
0 commit comments