is is annoying when people post scripts without tabs, its harder to help them and its harder find errors, also they are uglier =<
PHP:
local file = "lol.lua"
local adding, closing, elses = {'function', 'if', 'while', 'for', 'repeat'}, {'end', 'until'}, {'else', 'elseif'}
function onSay(cid, words, param, channel)
local tmp = {}
for line in io.lines(file) do
line = line:gsub(' ', '')
line = line:gsub('\n', '')
if line:find(' ') then
line = (line:gsub(' ', '') == '') and '' or line
end
for _, char in ipairs({',', '='}) do
if line:find(char) then
if (char == '=') then
if line:find('==') or line:find('>=') or line:find('<=') or line:find('~=') then
break
end
end
local expl, new = line:explode(char), ''
for k, str in ipairs(expl) do
new = new .. str .. ((k < #expl) and ((char == ',') and ', ' or ' = ') or '')
end
line = new
end
end
if (line ~= '') then
table.insert(tmp, line)
end
end
local function makeTab(times)
local ret = ''
for i = 1, times do
ret = ret .. ' '
end
return ret
end
local times, text = 0, '-- generated script\n\n'
for _, rewrite in ipairs(tmp) do
local temp = nil
for _, char in ipairs(adding) do
if (rewrite:find(char)) then
if not (rewrite:find('.' .. char)) then
temp = times
times = times + 1
end
end
end
for _, char in ipairs(closing) do
if (rewrite:find(char)) then
if not (rewrite:find('.' .. char)) then
temp = times - 1
times = times - 1
end
end
end
for _, char in ipairs(elses) do
if (rewrite:find(char)) then
if not (rewrite:find('.' .. char)) then
temp = times - 1
end
end
end
text = text .. makeTab(temp or times) .. rewrite .. '\n'
end
local open = io.open('generated_' .. file, "w")
if open then
open:write(text)
open:close()
end
return true
end
Attachments
-
tab.rar735 bytes · Views: 16 · VirusTotal
Last edited: