lua-users home
lua-l archive

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

Best practice is whatever suits you. One possibility is to create
a unique element that you call "deleted" or whatever, and setting
the middle elements to that instead of to nil. Then you can iterate
using #tbl or pairs and simply skip over any elements equal to

2013/9/26 Rafis Ganeyev <>:
> Tables can't be used so easily as array() in PHP. All Lua developers should
> know their peculiarities to use them properly: distinctions between vector
> and hash parts, no count() function, maybe vector and hash parts grew
> strategy, etc.
> My question is simple. If I have some collection of objects in vector part
> and I create holes by setting nil to middle elements, length operator and
> ipairs begin work improperly, how to I traverse this collection? Only with
> pairs() or should I use table.getn(), which seems have been removed in Lua
> 5.2? Or should I create element called "n" in hash part and create
> add/remove functions for collection? What are best practices for that case?
> --
> RG