lua-users home
lua-l archive

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

Roberto Ierusalimschy wrote:
> Just to remind you, Lua 4.0 already had support for this kind of OO
> programming with basic types. For instance,
>   settagmethod(tag(""), "gettable", function (a,b)
>     return getglobal('str'..b)
>   end)
> >   ansiStr = "Hello"
> >   print(ansiStr:lower())

That may look the same but it's quite different.  Not only that you
don't have to use tag methods (and the performance hit that takes),
try to simulate for example this in _addition_ to your code above:

  String.gettable = String.substr  -- [1]


  print("abc"[3])  --> c

is the same as




That aside, since the introduction of the 'metatables' your example
is no longer allowed.  The only metatable a Lua app has access to is
that of tables.

Ciao, ET.