middleclass.mixin.singleton - singleton mixin for middleclass OO library
local MyClass = require('middleclass')('MyClass')
:include(require('middleclass.mixin.singleton'))
-- Get the first instance
local obj1 = MyClass:instance()
-- Get the second instance, which is the same as the first one
local obj2 = MyClass:instance()
This is a simple mixin that allows to have middleclass-based singletone objects. See "SYNOPSIS" section for usage example.
MIT/X11
This code is taken from Love2d forums, where the author of middleclass itself published it. I only copied the code from there, modified it slightly according to my taste and released as a module.