summaryrefslogtreecommitdiff
path: root/src/02-enum/enum.lua
blob: b0e5abd12de1a3ef111e2261bdee7bdbf898d2d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
local function enum(tbl)
	if tbl == nil or type(tbl) ~= "table" then 
		return nil
	end 
	tbl.__index = tbl 
	tbl.__newindex = function() 
		print("can not modify enum")
	end 
	return setmetatable({}, tbl)
end

function main() 
	local mode = enum {
		SinglePlayer = 1, 
		TwoPlayers= 2,
		ThreePlayers= 3, 
		FourPlayers= 4,
		PVCom= 5,
	}
	mode.SinglePlayer = 2
	print(mode.SinglePlayer)
end 

main()