Public feed
#602768
--Class system test script--Our class function. This automates creating objects through--the meta table system. It's really cheating, but we like cheating. ;)--Once the object itself is created, it calls the "__init" method of the--object. This supports inheritence...in an odd fashion.--This would all of course be rewritten in C or C++ for speed and--introduced or exposed to lua as part of the language.--And yes, I realize the code in this function is insane.function Class(superclass, name) local cls = superclass and superclass() or {} cls.__name = name or "" cls.__super = superclass cls.__index = cls return setmetatable(cls, {__call = function (c, ...) self = setmetatable({__class = cls}, cls) if cls.__init then cls.__init(self, ...) end return self end})end--All the user would have to do is define the class itselfPerson = Class() function Person:__init(name, age) self.name = name self.age = age end function Person:printName() print(self.name) end--Create a new Person objectnewPerson = Person("Pirogoth Wolfblood", 21)newPerson:printName()