fork/m-overlay
git clone https://git.julia.blue/fork/m-overlay
a8034e9
v2.1.4
1local class ={ 2structs ={} , 3inherits ={} , 4} 5 6function ACCESSOR ( object , field , internal , default ) 7if not object then 8return error ( "attempt to call ACCESSOR on a nil value" ) 9end 10object [ internal ] =default 11 12local getter =function ( this ) return this [ internal ] end 13local setter =function ( this , value ) this [ internal ] =value end 14 15if type ( default ) == "boolean" then 16object [ "Is" .. field ] =getter 17end 18object [ "Get" .. field ] =getter 19object [ "Set" .. field ] =setter 20end 21 22local STRUCT ={} 23STRUCT . __index =STRUCT 24 25function STRUCT : ACCESSOR ( field , internal , default ) 26if type ( field ) == "table" then 27for k , v in pairs ( field ) do 28ACCESSOR ( self , v , internal , default ) 29end 30elseif type ( field ) == "string" then 31ACCESSOR ( self , field , internal , default ) 32end 33end 34 35function STRUCT : extends ( basename ) 36class . inherits [ self . classname ] =basename 37return self 38end 39 40function class . create ( classname , basename ) 41local struct ={} 42struct . classname =classname 43class . structs [ classname ] =struct 44class . inherits [ classname ] =basename 45return setmetatable ( struct , STRUCT ) 46end 47 48function class . get ( classname ) 49return class . structs [ classname ] 50end 51 52function class . getBase ( classname ) 53return class . inherits [ classname ] 54end 55 56return class