[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: "namespaces" ?
- From: Edgar Toernig <froese@...>
- Date: Mon, 22 Apr 2002 18:01:42 +0200
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]
Now
print("abc"[3]) --> c
is the same as
print("abc":substr(3))
or
print("abc":gettable(3))
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.