This is true, and the features of OOP can be implemented in other LUA code ways.
--
--Class Helper Routines
--
--Instantiates a class
Local function _instantiate (class, ...)
Local Inst = setmetatable ({}, {__index = class})
If Inst.__init__ Then
Inst:__init__ (...)
End
Return Inst
End
---Create a Class object (Python-style object model).
--The class object can be instantiated by calling itself.
--Any class functions or shared parameters can is attached to the this object.
--Attaching a table to the class object makes this table shared between
--all instances of the This class. For object parameters use the __INIT__ function.
--Classes can inherit member functions and values from a base class.
--Class can is instantiated by calling them. All parameters'll be passed
--The __init__ function of this class-if such a function exists.
--The __INIT__ function must is used to set any object parameters that is not shared
--with the objects of this class. Any return values would be ignored.
--@param base the base class to inherit from (optional)
--@return A class object
--@see instanceof
--@see Clone
function Class (Base)
--__parent Property Cache parent class for child class Index parent class method
Return setmetatable ({__parent = base}, {
__call = _instantiate,
__index = Base
})
End
--[[
Local function Searchparentclass (k, plist)
For I=1, #plist do
Local v = plist[i][k]
If v then return v end
End
End
---Create a Class object (Python-style object model).
--The class object can be instantiated by calling itself.
--Any class functions or shared parameters can is attached to the this object.
--Attaching a table to the class object makes this table shared between
--all instances of the This class. For object parameters use the __INIT__ function.
--Classes can inherit member functions and values from a base class.
--Class can is instantiated by calling them. All parameters'll be passed
--The __init__ function of this class-if such a function exists.
--The __INIT__ function must is used to set any object parameters that is not shared
--with the objects of this class. Any return values would be ignored.
--@param base the base class to inherit from (optional)
--@return A class object
--@see instanceof
--@see Clone
Function Class (...)
Local MTB = {}
Local parents = {...}
MTB = Setmetatable (MTB, {
__call = _instantiate,
__index = function (t,k)
Return Searchparentclass (k, parents)
End})
Mtb.__index = MTB
Return MTB
End
]]
---Test whether the given object is an instance of the given class.
--@param Object Object instance
--@param class class object to test against
--@return Boolean indicating whether the object is an instance
--@see Class
--@see Clone
function Instanceof (object, Class)
Local meta = getmetatable (object)
While Meta and Meta.__index do
If Meta.__index = = Class Then
return True
End
Meta = getmetatable (Meta.__index)
End
return False
End