可以自己写一个lua来实现,简单的例子带入如下:
--删除文件的注释的示例代码
--[[
注意:修改下面的代码的f1、f2变量
--]]
f1 = 'i:/Temp/1/a.lua'--需要处理的文件名
f2 = 'i:/Temp/1/b.lua'--处理后保存的文件名
innote = false --当前是否在多行注释中
function notePos(line)--获取一行文本里面注释开始的位置
local n, i, c, instr1, instr2
instr1 = false --在单引号里面
instr2 = false --在双引号里面
n = string.len(line)
i = 1
while i<n do
c = string.sub(line, i, i)
if "'"==c then
instr1 = not instr1
elseif '"'==c then
instr2 = not instr2
elseif '-'==c and instr1==false and instr2==false then
if '-'==string.sub(line, i+1, i+1) then
return i
end
end
i = i+1
end
return 0
end
fh1 = io.open(f1, 'r')
fh2 = io.open(f2, 'w')
while true do
line = fh1:read()
if nil==line then break end
i = notePos(line) --获取这行里面--的位置,引号内的不算
if 0~=i then
if i+3<=string.len(line) then
t = string.sub(line, i+2, i+3)
if '[['==t and false==innote then innote = true end
if ']]'==t and true==innote then innote = false end
else
t = ''
end
line=string.sub(line, 1, i-1)
end
if false==innote and ''~=line then
fh2:write(line..'\n')
end
end
fh2:close()
fh1:close()