lua-users home
lua-l archive

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


It was thus said that the Great Dibyendu Majumdar once stated:
> Hi Sean,
> 
> On 1 August 2018 at 21:04, Sean Conner <sean@conman.org> wrote:
> > It was thus said that the Great Dibyendu Majumdar once stated:
> >> On 1 August 2018 at 19:46, Dirk Laurie <dirk.laurie@gmail.com> wrote:
> >> > 2018-08-01 19:57 GMT+02:00 Phil Leblanc <philanc@gmail.com>:
> >> >> Thought experiment level 2:
> >> >>
> >> >> -- Remove metatables
> >> >>
> >> >> i.e. less "object-oriented" things. Going more with plain functions,
> >> >> tables of functions and closures.
> >> >>
> >> > In fact, it is a nostalgia list for a previous Lua: 4.0 had no
> >> > metatables (but it did have tag methods).
> >> >
> >>
> >> Meta tables are indeed another problematic feature from optimization
> >> point of view.
> >
> >   You *really* don't use C-based modules at all, do you?  Because without
> > metatables, userdata becomes rather useless.
> 
> Apologies I don't mean to argue. But maybe you are thinking of meta methods?

  Yes, which require metatables to store.  You can also set the __index meta
method to said metatable to index methods other than the meta methods
without having to write a custom __index function (ore __newindex function
for that matter).  So you can do things like:

	data = file:read()

Yes, that is syntactic sugar for

	data = file.read(file)

but without the metatable on file containing __index pointing to itself, you
then have to do

	data = io.read(file)

and you lose the ability to pass in something that isn't the result of
io.open() to code but does have the ability to return data like io.read()
does, say, from, a socket or a mocked file.

  -spc