I don't really know a real useful reason you would want to use this, but it's there if you need it.
The title says it all, this program will clear programs of comments, however it will not clear any multi line comments Aka --[[ Comment in Here ]] (EDIT HERE), Block Comments
if letters[i+2] == "[" and letters[i+3] == "[" then
return "empty", line
elseif letters[i-1] == "]" and letters[i-2] == "]" then
return "empty", line
end
local clearLine = {}
for t = 1, i-1 do
table.insert(clearLine, letters[t])
end
return "clearLine", table.concat(clearLine)
end
end
return "empty", line
end
function lines(str)
local t = {}
local function helper(line) table.insert(t, line) return "" end
helper((str:gsub("(.-)\r?\n", helper)))
return t
end
function clearFile(Path, newPath)
local file = fs.open(Path, "r")
fileTotal = file.readAll()
file.close()
local fileTable = {}
local newFile = {}
local fileTable = lines(fileTotal)
for i = 1,#fileTable do
local result, Q = comment(fileTable[i])
if result == "empty" then
table.insert(newFile, Q)
elseif result == "clearLine" then
table.insert(newFile, Q)
end
end
local file = fs.open(newPath, "w")
for i = 1, #newFile do
file.writeLine(newFile[i])
end
file.close()
end
if tArgs[2] == nil then
clearFile(tArgs[1], tArgs[1])
else
clearFile(tArgs[1], tArgs[2])
end
Usage:
ClearC file1 file2 -- This will clear file1 of comments and place the cleared file in file2
OR
ClearC file1 -- This will clear file1 of comments and replace it in the same file
Also note this program does not remove cleared lines if they are emptied and there is no text before the comment, so;
function this()
print("Some text here") -- Comment Here
-- And Another Comment
end
Will turn into this:
function this()
print("Some text here")
end
Post any bugs you get when using this program and if you really want me to fix the empty line thing just say, if there's enough interest then I will try and get it to work.
Edited by Kryptanyte, 22 November 2013 - 06:24 AM.
I actually find this useful for myself. I add a lot of comments in my code for myself for developing, but I really don't want other people to see them.
EDIT: Grammatical correction.
Edited by DiabolusNeil, 22 November 2013 - 02:14 PM.