lua-users home
lua-l archive

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


On Wed, Feb 20, 2008 at 12:19 PM, Eric Tetz <erictetz@gmail.com> wrote:
>  If you want that behavior, you can always just use your own table constructor:
>
>    function table.new(t)
>       return setmetatable(t or {}, {__index=table})
>    end
>
>    t = table.new{ "One", "Two", "Three" }
>    t:insert("Foo")
>    t:insert("Bar")
>    t:sort()
>
>    for k,v in pairs(t) do print(k,v) end
>
>  Cheers,
>  Eric
>

I have done this on occassion (and it looked pretty close to exactly
the same, except I used a common default metatable).  It's fairly
simple to do, so why not that?

Ben