You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
626 B
Lua

-- https://github.com/ichesnokov/middleclass-mixin-singleton
local singleton = {
static = {},
}
function singleton:included(class)
-- Override new to throw an error, but store a reference to the old "new" method
class.static._new = class.static.new
class.static.new = function()
error("Use " .. class.name .. ":instance() instead of :new()")
end
end
function singleton.static:instance(...)
self._instance = self._instance or self._new(self, ...) -- use old "new" method
return self._instance
end
function singleton.static:clear_instance()
self._instance = nil
end
return singleton