lua-users home
lua-l archive

Re: Why coroutine can't be indexed?

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


On Sun, Jul 10, 2011 at 08:19:52AM +0200, Eike Decker wrote:
> 2011年7月10日 Lorenzo Donati <lorenzodonatibz@interfree.it>:
> >> On Sat, Jul 9, 2011 at 10:14, Dirk Laurie<dpl@sun.ac.za>  wrote:
> >>> 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?
> > Lua tend to be simple, so no metatable trickery by default. 
> > … Moreover tables are the only type for which metatable trickery is
> > favoured
> > on Lua side (for other types you have to resort to debug.metatable)
> > … I think that string is an exception only because string functions 
> > are *so* commonly used that that was a sort of compromise for the 
> > sake of convenience.
> >
> Actually, I've been wondering myself why co:status() doesn't work. I
> would be a bit more convenient, like it is for strings. About
> simplicity: Creating such a metatable for coroutines is just a matter
> of a few lines of code in C.
But, as shown above, only one line in Lua. 
Another reason may be that the rawest novice to Lua uses strings
(`print "Hello, world!"`), whereas by the time you understand 
coroutines you probably understand metatables too.
Dirk

AltStyle によって変換されたページ (->オリジナル) /