lua-users home
lua-l archive

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


On Sun, May 01, 2011 at 09:04:38PM +0200, lin_style wrote:
> thanks!
Your subject line was:
    table.setn was deprecate, what is new function to replace it?

In Lua 5.2, something like this:

function setn(t,n)
    setmetatable(t,{__len=function() return n end})
    end

a={1,2,3,nil,5}
print(#a)   --> 5
setn(a,3)
print(#a)   --> 3

Dirk