Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Compile ACT code
- -- By Fenthis
- -- This program takes a specified file, removes Lua
- -- style comments, and spaces. It also allows you to
- -- define macros like:
- --
- -- macroname = macrotext
- --
- -- And use them as [macroname].
- --
- -- Extra arguments to the program are turned into macros
- -- such as [1], [2], etc.
- -- macro store
- macros = {}
- -- parsed code
- code = ""
- -- Arguments!
- args = { ... }
- if #args < 1 then
- print("Usage: dofile <filename> [<arg1> ...]")
- return
- end
- -- Dur
- if not turtle then
- print("I am not running on a turtle.")
- return
- end
- -- Check to see if the API is loaded
- if not act then
- print("act api not installed.")
- return
- end
- -- Open the file, make sure we can read it.
- filename = args[1]
- f = fs.open(filename, 'r')
- if not f then
- print("Can not read file: "..filename)
- return
- end
- -- Define arguments as macros
- if #args > 1 then
- for i = 2, #args do
- macros[i-1] = args[i]
- end
- end
- -- Process the file
- line = f:readLine()
- while line do
- -- Remove comments
- line = line:gsub("%-%-.*", "")
- -- Remove whitespace
- line = line:gsub("%s", "")
- -- Define macros
- macro, value = line:match("^([^=]*)=(.*)$")
- if macro then
- if not macro:match("^[%w_%-]*$") then
- print("Macro names may only contain letters, numbers, _ and -.")
- return
- end
- -- print("Defining macro "..macro.." with value "..value)
- macros[macro] = value
- line = ""
- -- Or apply macros
- else
- for key, value in pairs(macros) do
- line = line:gsub("%["..key.."%]", value)
- end
- end
- -- save to code
- code = code .. line
- -- Next!
- line = f:readLine()
- end
- -- Let them know what we are doing
- print("Code: "..code)
- -- Dooo et!
- act.act(code)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement