lua-users home
lua-l archive

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


it always strikes me why would you need to count entries in a table? It seems to me that
this is rarely required, and that it is probably an instance of
The XY Problem <http://xyproblem.info/> and trying to use in Lua using
paradigms from other languages. Perhaps I'm missing something.
 
people are working in different fields and encounter different problems. In my opinion any "this isn't often required" argument is at most ignorance.

I had this issue also, for me it was simply keeping track of the count using a metatable.

This requests also springs from a misconception that Lua already
stores this value internally anyway, which it doesn't.

This is the good answer, making a native implementation is not going into a much faster thing than coding it in Lua. Otherwise if one is worried much of this in an inner perfomance critical loop. One can just copy/paste numusearray() and numusehash() from ltable.c into  a seperate c file (they are declared static there), count them together and export that function as a lua library call. Easy extension without need to change the core.

Kind regards, Axel