Demonbholder 420 Postado Maio 13, 2011 Share Postado Maio 13, 2011 (editado) Faaala galera! Tudo tranquilo? Estreando a seção de bibliotecas, vamos a uma função que eu criei hoje a tarde. Como funciona: O parâmetro da função deve obrigatoriamente ser uma tabela, uma array. Exemplo: doOrderString({'demon', 'casa', 'xtibia'}) A função vai ordenar essas strings, e retorna uma tabela assim: {'casa', 'demon', 'xtibia'}. Função function doOrderString(tab) local t = {} local a = {} local k = {} local b = {} if type(tab) ~= "table" then return error("Param should be a table") end for x, y in pairs(tab) do if type(y) == "string" then table.insert(t, string.lower(y)) end end if #t == 0 then return error("No strings in table") end for i = 1, #t do str = nil for c, d in pairs(t) do stats = FALSE for s = 1, #d do if str == nil or string.byte(str, s, s) ~= nil then if str == nil or (string.byte(d, s, s) < string.byte(str, s, s) and stats == FALSE) then str = d end if string.byte(d, s, s) ~= string.byte(str, s, s) then stats = TRUE end if s == #d and #str > #d then str = d end end end end table.insert(a, str) table.remove(t, table.find(t, str)) end for p, w in pairs(tab) do if type(w) == "string" then for e = 1, #w do table.insert(b, w) table.insert(b, table.find(a, string.lower(w))) end end end for d = 1, #a do table.insert(k, b[table.find(b, d) -1]) end return k end Caso, você não possua a função table.find, eu a criei, ai esta ela: table.find function table.find(t, val) ret = nil for pos, mat in pairs(t) do if mat == val then ret = pos break end end return ret end É isso, deve ter alguns erros na função e foi bem difícil criá-la. Até mais. Editado Maio 14, 2011 por Demonbholder Link para o comentário Compartilhar em outros sites More sharing options...
Kuro o Shiniga 87 Postado Maio 17, 2011 Share Postado Maio 17, 2011 (editado) Hm bem inovador demonbholder irei usar gostei da sua ideia creio qe outras pessoas irão usar tambem Rep+ Editado Maio 17, 2011 por Pinpao Link para o comentário Compartilhar em outros sites More sharing options...
Posts Recomendados