lua-users home
lua-l archive

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


This has been annoying me for a long time...

What is the purpose/point of the "n" that pops up in tables after calling tinsert and tremove? I wouldn't mind so much if was in -every- table, but it's not. So, I never use it, since I may not know if a table has had a value added to it "manually", or with tinsert(). I must always use getn(). For a minute, I though "n" kept track of the number of entries in a table, but it doesn't! (-That- would be useful) It does exactly what getn() does, except that it's not guaranteed to be present in the table...

IMHO, it's useless, redundant, and just forces me to add extra code to ignore it.

> x = {}
> x[1], x[2], x[4] = 1, 2, 4
> print(getn(x))
4
> print(x.n)
nil
> tinsert(x, 0)
> print(getn(x))
5
> print(x.n)
5
> wtf("is the point?")
error: attempt to call global `wtf' (a nil value)
stack traceback:
   1: main of string "wtf("is the point?")" at line 1
>

Or, am I just missing something? :-/

==
|    ._  _   Lune MUW Server
|_(_)| )(/_  http://lune.sourceforge.net/

_____________________________________________________________