Kaotar 5 #1 Posted March 4, 2010 (edited) Estava ficando cansado do Etherpad que muda toda a tabulação do script, então fiz esse coisinha ai. Pra quem quiser esta ae. function AjustEscop(file) newFile = "" script = io.open(file, "r") tab = 0 if (script) then for line in script:lines() do line = removeEspaces(tostring(line)) if (line:match("{.-}")) then newFile = newFile .. stringTab(tab) .. line .. "\n" elseif (line:match("function") or line:match("if .- then") or line:match("for .- do") or line:match("while .- do") or line:match("{")) or line:match("repeat") then newFile = newFile .. stringTab(tab) .. line .. "\n" tab = tab + 1 elseif (line:match("end") or line:match("}") or line:match("until")) then tab = tab - 1 newFile = newFile .. stringTab(tab) .. line .. "\n" else newFile = newFile .. stringTab(tab) .. line .. "\n" end end local script = io.open(file, "w+") script:write(newFile) script:close() else error("ERROR: File not found") end script:close() end function removeEspaces(s) _, v = s:find("%s*") return string.sub(s, v+1) end function stringTab(num) s = "" while (num > 0) do s = s .. " " num = num - 1 end return s end Edited March 4, 2010 by Kaotar Share this post Link to post Share on other sites
Mock 32 #2 Posted March 4, 2010 Boa cara, alem do etherpad o proprio otscript live q muita gente usa nao tabula direito, eu uso o scite. agora que vi, você usou line:match("{.-}") { } como pattern, eu nunca tinha visto alguem usar eu estava acostumado a (.-) Share this post Link to post Share on other sites
Kaotar 5 #3 Posted March 4, 2010 Isso nao é pattern UAHuaHauha Isso é a tabela mesmo, é que se for uma tabela de uma linha so entende AUhauhAUhauah Share this post Link to post Share on other sites
pejuge2 1 #4 Posted March 4, 2010 (edited) Primeira vez também, uhauhahuuh! P.S.: Claro que isso é pattern O.o. Aprovado Edited March 4, 2010 by pejuge2 Share this post Link to post Share on other sites
dragonlorde 0 #5 Posted March 7, 2010 Muito bom cara... Mas voce boto como 1 tabela e não como padrão? >> line:match("{.-}") Share this post Link to post Share on other sites