lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hello!

Just yesterday I started with Lua with the intention to emebed it in my fututre 3D Engine. Well I have a doub aout the length operator and about the lengths of lists. With this code:

[code]

print( "Experimentando con tablas:" );
mitabla = { primerE = 121, segundoE = "TablaE2", tercerE = 7878.1212};
print( mitabla.primerE );
print( mitabla.segundoE );
print( mitabla.tercerE );
--Insertamos un cuarto elemento a la tabla
print "N1 de la tabla"
print ( table.getn( mitabla) )
table.insert( mitabla,  table.getn(mitabla)+1, 7854546 );
print "N2 de la tabla"
print ( table.getn( mitabla) )
print( "Se va a a imprimir los valores de la tabala de manera iterativa" );
table.foreach( mitabla, print )
print "Fin del contenido de la tabla"


print( #mitabla );
print( table.getn(mitabla) );



[/code]

I have this output:

[code]

Experimentando con tablas:
121
TablaE2
7878.1212
N1 de la tabla
0
N2 de la tabla
1
Se va a a imprimir los valores de la tabala de manera iterativa
1    7854546
segundoE    TablaE2
tercerE    7878.1212
primerE    121
Fin del contenido de la tabla
1
1


[/code]

Why at the beginning, when I intialize the table it have length 0 :S ??? Why when I insert a value it have length 1. And why I have a expected result with the 'foreach' sentence.

I'm using  Lua 5.1.3 last release
Bye!