Skip to content

Instantly share code, notes, and snippets.

@wujiyu115
Created February 11, 2014 11:57
Show Gist options
  • Save wujiyu115/8933564 to your computer and use it in GitHub Desktop.
Save wujiyu115/8933564 to your computer and use it in GitHub Desktop.
lua:instance
Hello = {}
function Hello:new() --private method.
local store = nil
return function(self)
if store then return store end
print"create." --for test.
local o = {}
setmetatable(o, self)
self.__index = self
store = o
return store
end
end
Hello.instance = Hello:new() --implement single instance object.
--test following
local hello = Hello:instance() --> create.
local hellohello = Hello:instance() --no output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment