Last active
February 19, 2020 16:32
-
-
Save MindScriptAct/5a39f67bc816f16ceafb2ec1ddda6529 to your computer and use it in GitHub Desktop.
TableTop simulator lua singleton class template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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