Lua For Java Programmers

What is this abot worrying about always spelling the variance name correctly?
Also I’d like to point out to you that you can do this:
[lua]Hi = “Hi”
length = Hi:len()[/lua]
I prefer this style, partly because it’s much shorter.

There are important reasons for using the Java ‘enhanced’ loops. Starting with the fact that it would properly balance the comparison, you are currently comparing a numeric for and a generic for.
Secondly the Java generic for (enhanced for) is faster and more uniform for accessing values in a collection. Suppose you tried your numeric for with a Linked List, using the index the whole time would increase the running time by a factor of the list’s size.

It’s better to leave them out in something like this, though - if you add semicolons people might think they’re necessary, which they aren’t.

Nice =) I think this tutorial will be helpful for C# / .NET family coders as well seing as they’re pretty similar.

People should stop telling people whether or not they should use a semi colon in their example code in my opinion and just let the coder do whatever they like. If people see it as such an issue they can just ask the author to state that it is not mandatory in the tutorial itself.

Quite a nice tutorial dorfy for people who know Java and want to learn Lua. Good of you to take the time.

Agreed, however this is not Java for Lua Programmers, so why should I talk about efficient java programming. -.-

Thanks ^.^, and I already added the fact that it is not mandatory.

Not hard to replicate though.

A guy I know wrote this - using __index, I think.

Hence why I said*** intended***. It is very possible, in fact its name is called LOOP. xD

Your point is valid, however such efficiency gains also exist for lua.
[lua]tbl = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
for i, v in ipairs(tbl) do
print(i, v)
– the above is more efficient than the below
for i=1, #tbl, 1 do
print(i, tbl*)
I merely found it odd that you would compare a for and a foreach in your example.

Holy shit one KiB? What ever shall we do? Today’s broadband and modern hard drives can’t handle these insane numbers.

I completely agree, which is why I setup a foreach. I did also show how to do a for regularly, so I assumed that they could put two and two together for the #Tbl part themselves if they wanted to use that :P. :smiley:

Thanks for the laugh :v:

Yeah I just meant in general. It happens too often when someone posts a code sample with semi colons.

And you’re welcome. :buddy: