[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Documenting Lua gotchas for newbies.
- From: Axel Kittenberger <axkibe@...>
- Date: Thu, 2 Dec 2010 00:10:29 +0100
Back when I started with Lua ipairs() and pairs() where quite a gotcha
for me. ipairs() not retrieving all elements if there is one missing,
and pairs() not returning stuff "in order". Getting to the mechanics a
little its all very understandable why it is the way it is. As newbie
it can be a bit confusing/surprising tough. At the start I always
used pairs() as most the time it did came up in the order I expected,
until there came that huh?moment.
Another surprise was when starting to take us of metatables that
__newindex and __index are only called if the value isnt there.
Altough it would have helped to read the docs better.
2010/12/1 Pierre-Yves Gérardy <pygy79@gmail.com>:
> Following the floating point discussion, I tried to look for a compilation
> of the various gotchas Lua beginners encounter, but I couldn't find one, so
> I decided to compile one...
> Right now, I can think of two of them:
> - Floating point inaccuracies. A simplified version of Patrick Rapin's
> "math.compare (x,y,delta)" [1] could be proposed as a workaround.
> - The fact that you have to declare locals before using them.
>
> Are there other potential traps? On what did you stumble while learning the
> language?
> Kind regards,
> -- Pierre-Yves
>
> 1. http://article.gmane.org/gmane.comp.lang.lua.general/71397