ScriptCompiler.lua 1.2 KB

1234567891011121314151617181920
  1. -- Script to recursively compile lua files located in specified rootFolder to luc (bytecode)
  2. -- Usage: require "LuaScripts/Utilities/LuaScriptCompiler"
  3. -- Set root folder containing lua files to convert
  4. local rootFolder = "Data/LuaScripts/" -- Starting from Bin folder
  5. if not fileSystem:DirExists(rootFolder) then log:Write(LOG_WARNING, "Cannot find " .. rootFolder) return end -- Ensure that rootFolder exists
  6. -- Get lua files recursively
  7. local files = fileSystem:ScanDir(fileSystem:GetProgramDir() .. rootFolder, "*.lua", SCAN_FILES, true)
  8. if table.maxn(files) == 0 then log:Write(LOG_WARNING, "No lua file found in " .. rootFolder .. " and subfolders") return end -- Ensure that at least one file was found
  9. -- Compile each lua file found in rootFolder and subfolders to luc
  10. for i=1, table.maxn(files) do
  11. local filename = rootFolder .. files[i] -- Get file with its path
  12. if not fileSystem:FileExists(filename) then log:Write(LOG_WARNING, "Cannot find " .. filename) return end
  13. print(filename .. "\n")
  14. local args = {"-b", filename, ReplaceExtension(filename, ".luc")} -- Set arguments to pass to the luajit command line app
  15. fileSystem:SystemRun(fileSystem:GetProgramDir() .. "luajit", args) -- Compile lua file to luc
  16. end