<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="es">
	<id>https://guanches.org/index.php?action=history&amp;feed=atom&amp;title=M%C3%B3dulo%3ATablas</id>
	<title>Módulo:Tablas - Historial de revisiones</title>
	<link rel="self" type="application/atom+xml" href="https://guanches.org/index.php?action=history&amp;feed=atom&amp;title=M%C3%B3dulo%3ATablas"/>
	<link rel="alternate" type="text/html" href="https://guanches.org/index.php?title=M%C3%B3dulo:Tablas&amp;action=history"/>
	<updated>2026-05-12T12:51:44Z</updated>
	<subtitle>Historial de revisiones de esta página en la wiki</subtitle>
	<generator>MediaWiki 1.45.1</generator>
	<entry>
		<id>https://guanches.org/index.php?title=M%C3%B3dulo:Tablas&amp;diff=218167&amp;oldid=prev</id>
		<title>Atamankad: Página creada con «local z = {}  -- Código copiado de http://lua-users.org/wiki/SortedIteration function __genOrderedIndex( t )     local orderedIndex = {}     for key in pairs(t) do         table.insert( orderedIndex, key )     end     table.sort( orderedIndex )     return orderedIndex end  function orderedNext(t, state)     -- Equivalent of the next function, but returns the keys in the alphabetic     -- order. We use a temporary ordered key table that is stored in the     -- table b…»</title>
		<link rel="alternate" type="text/html" href="https://guanches.org/index.php?title=M%C3%B3dulo:Tablas&amp;diff=218167&amp;oldid=prev"/>
		<updated>2026-02-10T20:33:13Z</updated>

		<summary type="html">&lt;p&gt;Página creada con «local z = {}  -- Código copiado de http://lua-users.org/wiki/SortedIteration function __genOrderedIndex( t )     local orderedIndex = {}     for key in pairs(t) do         table.insert( orderedIndex, key )     end     table.sort( orderedIndex )     return orderedIndex end  function orderedNext(t, state)     -- Equivalent of the next function, but returns the keys in the alphabetic     -- order. We use a temporary ordered key table that is stored in the     -- table b…»&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Página nueva&lt;/b&gt;&lt;/p&gt;&lt;div&gt;local z = {}&lt;br /&gt;
&lt;br /&gt;
-- Código copiado de http://lua-users.org/wiki/SortedIteration&lt;br /&gt;
function __genOrderedIndex( t )&lt;br /&gt;
    local orderedIndex = {}&lt;br /&gt;
    for key in pairs(t) do&lt;br /&gt;
        table.insert( orderedIndex, key )&lt;br /&gt;
    end&lt;br /&gt;
    table.sort( orderedIndex )&lt;br /&gt;
    return orderedIndex&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function orderedNext(t, state)&lt;br /&gt;
    -- Equivalent of the next function, but returns the keys in the alphabetic&lt;br /&gt;
    -- order. We use a temporary ordered key table that is stored in the&lt;br /&gt;
    -- table being iterated.&lt;br /&gt;
&lt;br /&gt;
    local key = nil&lt;br /&gt;
    --print(&amp;quot;orderedNext: state = &amp;quot;..tostring(state) )&lt;br /&gt;
    if state == nil then&lt;br /&gt;
        -- the first time, generate the index&lt;br /&gt;
        t.__orderedIndex = __genOrderedIndex( t )&lt;br /&gt;
        key = t.__orderedIndex[1]&lt;br /&gt;
    else&lt;br /&gt;
        -- fetch the next value&lt;br /&gt;
        for i = 1,table.getn(t.__orderedIndex) do&lt;br /&gt;
            if t.__orderedIndex[i] == state then&lt;br /&gt;
                key = t.__orderedIndex[i+1]&lt;br /&gt;
            end&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if key then&lt;br /&gt;
        return key, t[key]&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    -- no more value to return, cleanup&lt;br /&gt;
    t.__orderedIndex = nil&lt;br /&gt;
    return&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function orderedPairs(t)&lt;br /&gt;
    -- Equivalent of the pairs() function on tables. Allows to iterate&lt;br /&gt;
    -- in order&lt;br /&gt;
    return orderedNext, t, nil&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function z.tostringordered(tabla, identacion)&lt;br /&gt;
    identacion = identacion or &amp;#039;\n&amp;#039;&lt;br /&gt;
    local identacion2 = identacion .. &amp;#039;  &amp;#039;&lt;br /&gt;
    &lt;br /&gt;
    if not tabla then&lt;br /&gt;
    	return&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    local valores = {}&lt;br /&gt;
    local k2, v2&lt;br /&gt;
 &lt;br /&gt;
    for k,v in orderedPairs(tabla) do&lt;br /&gt;
    	if type(k) == &amp;#039;string&amp;#039; then&lt;br /&gt;
    		k2 = &amp;#039;&amp;quot;&amp;#039; .. k .. &amp;#039;&amp;quot;&amp;#039;&lt;br /&gt;
    	else&lt;br /&gt;
    		k2 = k&lt;br /&gt;
    	end&lt;br /&gt;
        if type(v) == &amp;#039;table&amp;#039; then&lt;br /&gt;
            v2 = z.tostringordered(v, identacion2)&lt;br /&gt;
        elseif type(v)==&amp;#039;string&amp;#039; then&lt;br /&gt;
        	v2 = &amp;#039;&amp;quot;&amp;#039; .. v .. &amp;#039;&amp;quot;&amp;#039;&lt;br /&gt;
        else&lt;br /&gt;
        	v2 = tostring(v)&lt;br /&gt;
        end&lt;br /&gt;
        &lt;br /&gt;
        table.insert(valores, &amp;#039;[&amp;#039; .. k2 .. &amp;#039;] = &amp;#039; .. v2)&lt;br /&gt;
    end&lt;br /&gt;
 &lt;br /&gt;
    return &amp;#039;{&amp;#039; .. identacion2 .. (table.concat(valores, &amp;#039;, &amp;#039; .. identacion2) or &amp;#039;&amp;#039;) .. identacion .. &amp;#039;}&amp;#039;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function z.tostring(tabla, identacion)&lt;br /&gt;
    identacion = identacion or &amp;#039;\n&amp;#039;&lt;br /&gt;
    local identacion2 = identacion .. &amp;#039;  &amp;#039;&lt;br /&gt;
    &lt;br /&gt;
    if not tabla then&lt;br /&gt;
    	return&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    local valores = {}&lt;br /&gt;
    local k2, v2&lt;br /&gt;
 &lt;br /&gt;
    for k,v in pairs(tabla) do&lt;br /&gt;
    	if type(k) == &amp;#039;string&amp;#039; then&lt;br /&gt;
    		k2 = &amp;#039;&amp;quot;&amp;#039; .. k .. &amp;#039;&amp;quot;&amp;#039;&lt;br /&gt;
    	else&lt;br /&gt;
    		k2 = k&lt;br /&gt;
    	end&lt;br /&gt;
        if type(v) == &amp;#039;table&amp;#039; then&lt;br /&gt;
            v2 = z.tostring(v, identacion2)&lt;br /&gt;
        elseif type(v)==&amp;#039;string&amp;#039; then&lt;br /&gt;
        	v2 = &amp;#039;&amp;quot;&amp;#039; .. v .. &amp;#039;&amp;quot;&amp;#039;&lt;br /&gt;
        else&lt;br /&gt;
        	v2 = tostring(v)&lt;br /&gt;
        end&lt;br /&gt;
        &lt;br /&gt;
        table.insert(valores, &amp;#039;[&amp;#039; .. k2 .. &amp;#039;] = &amp;#039; .. v2)&lt;br /&gt;
    end&lt;br /&gt;
 &lt;br /&gt;
    return &amp;#039;{&amp;#039; .. identacion2 .. (table.concat(valores, &amp;#039;, &amp;#039; .. identacion2) or &amp;#039;&amp;#039;) .. identacion .. &amp;#039;}&amp;#039;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function z.elemento(tabla, indice1, indice2, indice3, indice4, indice5, indice6, indice7)&lt;br /&gt;
	local resultado&lt;br /&gt;
	&lt;br /&gt;
	if not tabla or not indice1 then&lt;br /&gt;
		return&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	resultado = tabla[indice1]&lt;br /&gt;
	&lt;br /&gt;
	if not indice2 or not resultado then&lt;br /&gt;
		return resultado&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	resultado = resultado[indice2]&lt;br /&gt;
&lt;br /&gt;
	if not indice3 or not resultado then&lt;br /&gt;
		return resultado&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	resultado = resultado[indice3]&lt;br /&gt;
	&lt;br /&gt;
	if not indice4 or not resultado then&lt;br /&gt;
		return resultado&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	resultado = resultado[indice4]&lt;br /&gt;
	&lt;br /&gt;
	if not indice5 or not resultado then&lt;br /&gt;
		return resultado&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	resultado = resultado[indice5]&lt;br /&gt;
	&lt;br /&gt;
	if not indice6 or not resultado then&lt;br /&gt;
		return resultado&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	resultado = resultado[indice6]&lt;br /&gt;
	&lt;br /&gt;
	if not indice7 or not resultado then&lt;br /&gt;
		return resultado&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	resultado = resultado[indice7]&lt;br /&gt;
	&lt;br /&gt;
	return resultado&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function z.en(tabla, elemento)&lt;br /&gt;
    if not elemento then&lt;br /&gt;
        return&lt;br /&gt;
    end&lt;br /&gt;
    for k,v in pairs( tabla ) do&lt;br /&gt;
        if v == elemento then&lt;br /&gt;
            return k&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function z.copiarElementosConValor(original)&lt;br /&gt;
	local copia= {}&lt;br /&gt;
	&lt;br /&gt;
    for k,v in pairs(original) do&lt;br /&gt;
        if v~=&amp;#039;&amp;#039; then&lt;br /&gt;
            copia[k] = original[k]&lt;br /&gt;
        end&lt;br /&gt;
    end	&lt;br /&gt;
    &lt;br /&gt;
    return copia&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function z.insertar(tabla, elemento)&lt;br /&gt;
	if not elemento then&lt;br /&gt;
		return false&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	if not z.en(tabla, elemento) then&lt;br /&gt;
		table.insert(tabla, elemento)	&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	return true&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function z.insertarElementosConValor(origen, destino)&lt;br /&gt;
    for k,v in pairs(origen) do&lt;br /&gt;
        if v~=&amp;#039;&amp;#039; then&lt;br /&gt;
            table.insert(destino, v)&lt;br /&gt;
        end&lt;br /&gt;
    end	&lt;br /&gt;
    &lt;br /&gt;
    return copia&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function z.sonIguales(tabla1, tabla2)&lt;br /&gt;
	if not tabla1 or not tabla2 then&lt;br /&gt;
		return false&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	if tabla1 == tabla2 then&lt;br /&gt;
		return true&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	for k,v in pairs(tabla1) do&lt;br /&gt;
		if tabla2[k] ~= v then&lt;br /&gt;
			return false&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	for k,v in pairs(tabla2) do&lt;br /&gt;
		if not tabla1[k] then&lt;br /&gt;
			return false&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	return true&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function z.ordenarFuncion(tabla, funcion)&lt;br /&gt;
	local funcionInestable = funcion&lt;br /&gt;
	&lt;br /&gt;
	-- Añadir a la tabla un campo con el orden&lt;br /&gt;
	for i,n in ipairs(tabla) do tabla[i].__orden = i end&lt;br /&gt;
	&lt;br /&gt;
	table.sort(tabla, &lt;br /&gt;
		function(a,b) &lt;br /&gt;
		   if     funcionInestable(a, b) then return true -- a &amp;lt; b&lt;br /&gt;
		   elseif funcionInestable(b, a) then return false -- b &amp;lt; a&lt;br /&gt;
		   elseif a.__orden &amp;lt; b.__orden  then return true -- a = b y a aparece antes que b&lt;br /&gt;
		   else                               return false -- a = b y b aparece antes que a&lt;br /&gt;
		   end&lt;br /&gt;
		end&lt;br /&gt;
	)&lt;br /&gt;
    &lt;br /&gt;
    -- Eliminar de la tabla el campo con el orden&lt;br /&gt;
	for i,n in ipairs(tabla) do tabla[i].__orden = nil end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function z.ordenar(tabla, criterio)&lt;br /&gt;
	if type(criterio) == &amp;#039;table&amp;#039; then&lt;br /&gt;
		z.ordenarFuncion(tabla,&lt;br /&gt;
			function(a,b)&lt;br /&gt;
				local valorA, valorB&lt;br /&gt;
				for i,campo in ipairs(criterio) do&lt;br /&gt;
					valorA = a[campo]&lt;br /&gt;
					valorB = b[campo]&lt;br /&gt;
					if not valorA and not valorA then&lt;br /&gt;
						-- No hacer nada&lt;br /&gt;
					elseif not valorA and valorB then&lt;br /&gt;
						return true&lt;br /&gt;
					elseif valorA and not valorB then&lt;br /&gt;
						return false&lt;br /&gt;
					elseif valorA &amp;lt; valorB then&lt;br /&gt;
						return true&lt;br /&gt;
					elseif valorA &amp;gt; valorB then&lt;br /&gt;
						return false &lt;br /&gt;
					end&lt;br /&gt;
				end	&lt;br /&gt;
		   		return false -- Todos los valores son iguales&lt;br /&gt;
			end&lt;br /&gt;
		)	&lt;br /&gt;
	else&lt;br /&gt;
		z.ordenarFuncion(tabla, criterio)&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function z.agrupar(tabla, clave, campo)&lt;br /&gt;
	local tabla2 = {}&lt;br /&gt;
	&lt;br /&gt;
	local v2&lt;br /&gt;
	&lt;br /&gt;
	for k,v in ipairs(tabla) do&lt;br /&gt;
		if not v[campo] then&lt;br /&gt;
			table.insert(tabla2, v)&lt;br /&gt;
			v2 = nil&lt;br /&gt;
		elseif v2 and v2[clave] == v[clave] then&lt;br /&gt;
			-- Agrupar&lt;br /&gt;
			table.insert(v2[campo], v[campo])&lt;br /&gt;
		else&lt;br /&gt;
			v2 = v&lt;br /&gt;
			v2[campo] = {v[campo]}	&lt;br /&gt;
			table.insert(tabla2, v2)&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	return tabla2&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
return z&lt;/div&gt;</summary>
		<author><name>Atamankad</name></author>
	</entry>
</feed>