lua-users home
lua-l archive

RE: [Q] newbie questions about timestamp, character code, ..

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


Makoto Kuwata wrote:
> * How to check whether table has key or not?
if table[key]==nil then
 print "Your table has no entry with that key"
end
You can't put nils in a table, neither as key or as values:
- table[key]=nil removes an entry from the table.
- table[nil]=value throws an error
Gergo Szakal wrote:
> if table[key] then ... end
> 
> means that if the given key in the table is non-nil, then...
Note that false is a valid table value, and in that case the test above
will fail. To be sure a key is not used check explicitly against nil.

AltStyle によって変換されたページ (->オリジナル) /