Diferencia entre revisiones de «Módulo:Tablas»
Apariencia
Página creada con «local z = {} function z.mostrar(tabla, identacion) identacion = identacion or '' for k,v in pairs(tabla) do if type(v)=='table' then return "...» |
Sin resumen de edición |
||
| Línea 2: | Línea 2: | ||
function z.mostrar(tabla, identacion) | function z.mostrar(tabla, identacion) | ||
identacion = identacion or '' | identacion = identacion or '\n' | ||
local resultado | |||
for k,v in pairs(tabla) do | for k,v in pairs(tabla) do | ||
if type(v)=='table' then | if type(v)=='table' then | ||
resultado = resultado .. identacion .. '{' .. mostrar(v,identacion .. ' ') .. '}' | |||
elseif type(v)=='string' then | |||
resultado = resultado .. identacion .. k .. ': "' .. v .. '"' | |||
else | else | ||
resultado = resultado .. identacion .. k .. ': ' .. tostring(v) | |||
end | end | ||
end | end | ||
Revisión del 12:03 7 dic 2014
La documentación para este módulo puede ser creada en Módulo:Tablas/doc
local z = {}
function z.mostrar(tabla, identacion)
identacion = identacion or '\n'
local resultado
for k,v in pairs(tabla) do
if type(v)=='table' then
resultado = resultado .. identacion .. '{' .. mostrar(v,identacion .. ' ') .. '}'
elseif type(v)=='string' then
resultado = resultado .. identacion .. k .. ': "' .. v .. '"'
else
resultado = resultado .. identacion .. k .. ': ' .. 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