What i want to do
What I want to do is very simple. I want to use Lua to check the lines in a Plist file.
Say if the string is in Plist,, <integer>-1.00</integer>I need to cut .00it so that it is <integer>-1</integer>.
What I've done
I use the function to read the entire contents of the file and perform a line check and replace.
local function doLineClean( cont )
newcont = ''
string.gsub( cont, "(.-)\r?\n", function(line)
if string.match( line, "<integer>.-<%/integer>" ) then
string.gsub( line, "<.->(.-)<.->", function(v)
a, b = string.find(v,"%..*")
if a and b then
v = string.sub( v, 0, a - 1 )
end
line = "\t\t<integer>"..v.."</integer>"
end )
end
newcont = newcont .. line .. '\n'
end )
return newcont
end
My question
Is there a more efficient and elegant way to do the same job?
source
share