-- Class.lua-- Defines functions and objects required for object modelfunction Class() local ClassContainer = { __Inheritance = {m_Object = {}, m_Next = nil} } local ClassMetaTable = { __index = function(Table, Key) --Check if a table has a key local function HasKey(T, Key) if T[Key] ~= nil then return T[Key] end return nil end --Iterate through the __Inheritance list local function Iter(T, Key) if T == nil then return nil end local x = HasKey(T.m_Object, Key) if x ~= nil then return x end return Iter(T.m_Next, Key) end local x = Iter(Table.__Inheritance, Key) if x == nil then return rawget(Table, Key) end return x end, __newindex = function(Table, Key, Value) rawset(Table.__Inheritance.m_Object, Key, Value) end } setmetatable(ClassContainer, ClassMetaTable) return ClassContainerendfunction DeriveClass(ClassFactory) DerivedClass = ClassFactory:new() DerivedClass.__Inheritance = { m_object = {}, m_Next = DerivedClass.__Inheritance } --At this point we can rename old constructors and such, depending on how --we want our object model to work. We could always create "Base" or "Super" --variables to deal with it, which isn't a bad way to go. --For example: DerivedClass.__Super = DerivedClass.__init --Because init will be overidden by --the class definition, which isn't yet shown. More specifically it would --be redefined, but the old definition would continue to exist up the heirarchy. return DerivedClassend