There is such a class, no matter how the class is initialized, the resulting instance are the same object.
String.tohtmlcode = function (self)
return encodehtml (self)
End
--Instantiates a class
Local function _instantiate (class, ...)
--Singleton mode, if the instance is already generated, return directly
If Rawget (class, "__singleton") Then
--_g[class] value is an instance of this class
If _g[class] Then
return _g[class]
End
End
Local Inst = setmetatable ({__class=class}, {__index = class})
If Inst.__init__ Then
Inst:__init__ (...)
End
--Singleton mode, if the instance is not generated, logs the instance to a class
If Rawget (class, "__singleton") Then
If not _g[class] Then
_g[class] = Inst
End
End
Return Inst
End
--LUA class constructors
Local function class (base)
Local metatable = {
__call = _instantiate,
__index = Base
}
--__parent Property Cache parent class for child class Index parent class method
Local _class = {__parent = base}
--Record metatable in the class object to overload Metatable.__index
_class.__metatable = metatable
Return setmetatable (_class, metatable)
End
If you set a _singleton to true for the defined class, turn on simple interest mode.