Piorjade

ComputerCraft LUA veeery simple preprocessor

Sep 11th, 2017
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.05 KB | None | 0 0
  1. --[[
  2.     CCLUA prepocessor
  3.    
  4.     This can be ported to vanilla LUA very simply
  5.  
  6.     ~Piorjade
  7.  
  8. ]]
  9.  
  10. local arguments = {...}
  11.  
  12. if #arguments ~= 1 then
  13.     print("Usage: prepoc <file> <outputName>")
  14. end
  15.  
  16. local currentLine
  17. local fileData = "---Processed with LUAPreProc---"
  18. local file = fs.open(arguments[1], "r")
  19. repeat
  20.     currentLine = file.readLine()
  21.     if currentLine ~= nil and currentLine:sub(1, 3) == "--#" then
  22.         local command = currentLine:sub(currentLine:find("%b[]"))
  23.         if command == "[include]" then
  24.             local argument = currentLine:sub(14, #currentLine)
  25.             local argumentFile = fs.open(argument, "r")
  26.             print("Including: "..tostring(argument))
  27.             local argumentData = argumentFile.readAll()
  28.             argumentFile.close()
  29.             fileData = fileData.."\n"..argumentData
  30.         end
  31.     elseif currentLine ~= nil then
  32.         fileData = fileData.."\n"..currentLine
  33.     end
  34. until currentLine == nil
  35. file.close()
  36. local file = fs.open(arguments[1], "w")
  37. file.write(fileData)
  38. file.close()
Advertisement
Add Comment
Please, Sign In to add comment