GameManager.lua:
--单例模式是利用一个全局表来实现的 GameManager = {} Manager = {__index = GameManager} function GameManager:new()
local self = {}
setmetatable(self,Manager)
return self
end function GameManager:ShowName()
print("the is an singleton")
end
Main.lua:
require "GameManager" gm = GameManager:new() gm:ShowName() --[[
运行结果:
the is an singleton
--]]