All pastes #621370 Raw Edit

Untitled

public lua v1 · immutable
·published 2007-07-16 03:28 UTC
rendered paste body
--Class system test script--Our class function.  This automates creating objects through--the meta table system.  It's really cheating, but we like cheating. ;)--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()    local cls = {}    cls.__index = cls    return setmetatable(cls,         {__call = function (c, ...)            self = setmetatable({__class = cls}, cls)            return self        end})end--All the user would have to do is define the class itselfPerson = Class()    function Person:new(name, age, cash)        self.name = name        self.age = age        self.account = account:new(cash) --Note, the class "account"        --is a class written in C++ and exposed to lua.  This was        --just really a test to make sure this works.        return self    end        function Person:printProfile()        print("---------------")        print("Name: ", self.name)        print("Age: ", self.age)        print("Account Balance: ", self.account:getBalance())        print("---------------")    end        function Person:deposit(amount)        self.account:deposit(amount)    end        function Person:withdraw(amount)        self.account:withdraw(amount)    end--Create a new object of type "Person"newPerson = Person:new("Pirogoth Wolfblood", 21, 500)newPerson:printProfile()newPerson:withdraw(600)