lua-users home
lua-l archive

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


I wrote a Lua programming handout for my job for use by the long-time C programmers in our department. In it there is a section called "Footguns" where I listed these 5 gotchas. 

  1. The "key" in t.key is the constant string "key", not a variable named "key".
  2. A table that contains at least one nil is a hash, not an array. This means that #t may not return the number of elements in the table.
  3. Be careful to distinguish between a period and a colon when calling functions. t.f() is not the same thing as t:f().
  4. Lua arrays start at 1, not 0.
  5. Only false and nil are false. 0 is true.
  6. Undeclared variables are global.

On Dec 1, 2010, at Dec 1 3:28 PM, Pierre-Yves Gérardy wrote:

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