| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- --[[
- Object base class
- @author : Siapran Candoris
- Features instance of class determination and prototype function (init)
- ]]--
- local make_class = require("class")
- --------------------------------
- -- object class
- --
- local object = make_class()
- function object:new( ... )
- local res = {}
- setmetatable(res, self)
- if res.init then
- res:init(...)
- end
- return res
- end
- function object:instanceof( class )
- local cache = self.__instanceof_cache
- if cache[class] ~= nil then
- return cache[class]
- else
- for _,v in ipairs(self.__genealogy) do
- if class == v then
- cache[class] = true
- return true
- end
- end
- cache[class] = false
- return false
- end
- end
- -- asssign unique ids to tables
- do
- local cache = setmetatable({}, {__mode = "k"})
- local id = 0
- function identifier( table )
- if cache[table] then
- return cache[table]
- else
- cache[table] = id
- id = id + 1
- return id
- end
- end
- end
- return object
|