[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Type Metatables for Table and Userdata - Powerpatch
- From: "John Hind" <john.hind@...>
- Date: Sun, 9 Dec 2012 15:44:46 -0000
I said:
>>> I want to create OO objects like this:
>>>
>>> obj = ({"item1","item2","item3"}):class("list")
Dick Laurie replied:
>> Why not simply create the object this way?
>>
>> obj = list {"item1","item2","item3"}
Denis Spir added:
> or just use a metatable's alias as pseudo-syntactic prefix (my preferred
> solution, as if Lua had native arrays/lists ;-):
> obj = L{"item1","item2","item3"}
> (by the way, why are items quoted in the op's syntax?)
Not sure I understand how the latter two suggestions differ, but the first
certainly requires a constructor function in the global namespace for every
class which is what I am trying to avoid. My way, the classes occupy their
own private namespace and even the "class" method is not global existing
only as a method of Table type.
I just used strings as an example, the table contents could be any type for
a generic list container.
- John (the op) Hind