Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- a simple fix for the fact that lua doesn't have the operator= operators
- -- works for +=, -=, /=, *=, and %=
- local args = {...}
- local file = io.open(args[1], "r")
- local file2 = fs.open(args[1]..".withOperators", "w")
- local function concentate(...)
- local fnArgs = {...}
- local ret = ""
- for i, v in ipairs(fnArgs) do
- ret = ret..v
- end
- return ret
- end
- for line in file:lines() do
- local editLine = line
- local words = {}
- for word in string.gmatch(line, "([^ \t]+)") do
- table.insert(words, word)
- end
- for i,word in ipairs(words) do
- if word == "+=" then
- editLine = concentate(words[1], " = "..words[1].." + ", unpack(words, 3))
- break
- elseif word == "-=" then
- editLine = concentate(words[1], " = "..words[1].." - ", unpack(words, 3))
- break
- elseif word == "*=" then
- editLine = concentate(words[1], " = "..words[1].." * ", unpack(words, 3))
- break
- elseif word == "/=" then
- editLine = concentate(words[1], " = "..words[1].." / ", unpack(words, 3))
- break
- elseif word == "%=" then
- editLine = concentate(words[1], " = "..words[1].." % ", unpack(words, 3))
- break
- elseif word == ">>=" then
- editLine = concentate(words[1], " = bit.brshift("..words[1]..", ", unpack(words, 3),")")
- break
- elseif word == "<<=" then
- editLine = concentate(words[1], " = bit.blshift("..words[1]..", ", unpack(words, 3),")")
- break
- elseif word == "&=" then
- editLine = concentate(words[1], " = bit.band("..words[1]..", ", unpack(words, 3),")")
- break
- elseif word == "^=" then
- editLine = concentate(words[1], " = bit.bxor("..words[1]..", ", unpack(words, 3),")")
- break
- elseif word == "|=" then
- editLine = concentate(words[1], " = bit.bor("..words[1]..", ", unpack(words, 3),")")
- break
- end
- end
- file2.writeLine(editLine)
- end
- file2.close()
- file:close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement