lua-users home
lua-l archive

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


On Sat, Jul 09, 2011 at 05:38:59PM +0200, HyperHacker wrote:
> On Sat, Jul 9, 2011 at 09:33, Dirk Laurie <dpl@sun.ac.za> wrote:
> > On Sat, Jul 09, 2011 at 04:58:10PM +0200, HyperHacker wrote:
> >> That one can easily do it with a metatable especially
> >> makes me wonder why it isn't done by the library itself
> > If this argument were valid for coroutines, it would apply equally
> > to tables:  why must one say table.insert(list,item) instead of just
> > list:insert(item)?
> >
> > To answer your question: it is not done by the library itself
> > _because_ one can easily do it with a metatable.
> >
> > "Less is more" — Mies van der Rohe (1886–1969), architect.
> >
> > Dirk
> >
> >
> 
> I'm pretty sure it's not done with tables because list:insert(item)
> already has a different meaning (to look up 'insert' in the table
> 'list'), and to set up a metatable like that could be confusing. (Why
> t:insert() doesn't work? Oh, because t has a key named 'insert'
> already... now is t2.insert a key in t2 or in table? etc)
> 
Sorry, I did not absorb your whole post when writing the reply
above.  Tables are indeed different in an important way.

The interesting question to me is, since it is so easy to say
debug.setmetatable('',{__index=string}), why the equivalent of that
has been built in.  There must have been a debate on that a few 
years ago: could an old-timer tell us the clinching reason?

Dirk