lua-users home
lua-l archive

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


While this may have been discussed many times in the past, speaking
of positive integer table indices, I find the 'n' field annoying. 
While it is debatable whether Lua itself should automatically keep
track 'n' (AFAIK only the table library uses it), why not at least
change the table library implementation to e.g. use a weak table to
store the information? 

local ns=setmetatable({}, {__mode='k'})

function table.getn(tab)
    if ns[tab]==nil then
        -- Calculate n
	ns[tab]=n
    end
    return ns[tab]
end

etc.

-- 
Tuomo