lua-users home
lua-l archive

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


> Perhaps, better is initialize...

Or use metatables:

-- Metatable
local a = {}
setmetatable(a, {__index = function () return 0 end})
for i = 1, 5000 do
 for j = 1, 1000 do
    a[i] = a[i] + j
 end
end

It gives the same performance that `Init' and it is more flexible,
because you do not need to know beforehand which indices will be used.

-- Roberto