Diferencia entre revisiones de «Módulo:Tablas»
Apariencia
Sin resumen de edición |
Sin resumen de edición |
||
| Línea 6: | Línea 6: | ||
for k,v in pairs(tabla) do | for k,v in pairs(tabla) do | ||
if type(k) == 'string' then | |||
k2='"' .. k .. '"' | |||
else | |||
k2=k | |||
end | |||
if type(v)=='table' then | if type(v)=='table' then | ||
resultado = resultado .. identacion .. | resultado = resultado .. identacion .. k2 .. ': {' .. z.tostring(v,identacion .. ' ') .. identacion .. '}' | ||
elseif type(v)=='string' then | elseif type(v)=='string' then | ||
resultado = resultado .. identacion .. | resultado = resultado .. identacion .. k2 .. ': "' .. v .. '"' | ||
else | else | ||
resultado = resultado .. identacion .. | resultado = resultado .. identacion .. k2 .. ': ' .. tostring(v) | ||
end | end | ||
end | end | ||
Revisión del 21:45 3 ene 2015
La documentación para este módulo puede ser creada en Módulo:Tablas/doc
local z = {}
function z.tostring(tabla, identacion)
identacion = identacion or '\n'
local resultado = ''
for k,v in pairs(tabla) do
if type(k) == 'string' then
k2='"' .. k .. '"'
else
k2=k
end
if type(v)=='table' then
resultado = resultado .. identacion .. k2 .. ': {' .. z.tostring(v,identacion .. ' ') .. identacion .. '}'
elseif type(v)=='string' then
resultado = resultado .. identacion .. k2 .. ': "' .. v .. '"'
else
resultado = resultado .. identacion .. k2 .. ': ' .. tostring(v)
end
end
return resultado
end
function z.en(tabla, elemento)
if not elemento then
return
end
for k,v in pairs( tabla ) do
if v == elemento then
return k
end
end
end
return z