lua-users home
lua-l archive

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


After way too much Tequila shots, here is the delusion of the premiss of my grandly named "LUObject"... :o)

A couple of arbitrary conventions:

- One class per file.
- A class is a "package" as shown in PIL, Chapter 15.2 [1].
- An object is a table of closures as shown in PIL, Chapter 16.4 [2].
- Everything is defined in terms of table of functions.

In theory, "LUObject" supports both class and instance methods, inheritance and encapsulation.

See attachments for examples:

- LUObject is the root class. It defines 3 class methods (class, new and methods) and 5 instance methods (class, equals, hashCode, this and toString) - MySubClass extends LUObject. It defines no new methods, but extends the toString instance method of its parent. - MyOtherSubClass extends MySubClass. It defines 1 new class method (doIt) and one new instance method (doItQuick) as well as extending the toString instance method of its parent.

anObject = MySubClass.new()
print( anObject.toString() )

MyOtherSubClass.doIt()
anotherObject = MyOtherSubClass.new()
print( anotherObject.toString() )

anotherObject.class().doIt()
anotherObject.doItQuick()

anObject.equals( anotherObject )

Does any of this make sense? At all? Or do I need more Tequila? :P

Cheers

--
PA
http://alt.textdrive.com/

[1] http://www.lua.org/pil/15.2.html
[2] http://www.lua.org/pil/16.4.html

Attachment: LUObject.lua
Description: Binary data

 

Attachment: MySubClass.lua
Description: Binary data

 

Attachment: MyOtherSubClass.lua
Description: Binary data