Skip to content

Instantly share code, notes, and snippets.

@MindScriptAct
Last active February 19, 2020 16:32
Show Gist options
  • Save MindScriptAct/5a39f67bc816f16ceafb2ec1ddda6529 to your computer and use it in GitHub Desktop.
Save MindScriptAct/5a39f67bc816f16ceafb2ec1ddda6529 to your computer and use it in GitHub Desktop.
TableTop simulator lua singleton class template
local MySingleton = {}
MySingleton.__index = MySingleton
setmetatable(MySingleton, {__call = function (cls, ...) return cls.GetInstance(...) end })
local instance
function MySingleton.GetInstance()
if instance == nil then
instance = setmetatable({}, MySingleton)
end
return instance
end
function MySingleton:SetData(newData)
self.data = newData
end
function MySingleton:PrintData()
print(self.data)
end
function MySingleton:DoStuff()
print("doStuff!!")
end
return MySingleton
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment