summaryrefslogtreecommitdiff
path: root/src/02-enum
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2019-09-23 08:00:18 +0800
committerchai <chaifix@163.com>2019-09-23 08:00:18 +0800
commit0382bd8a03b82b9c154d896e819ee7fed24025eb (patch)
tree5e398fb2cc0e94046cfeee1f556a3a089b419570 /src/02-enum
parent695f88366e507032a3a9e1eb747cc48610a4cbe1 (diff)
*枚举
Diffstat (limited to 'src/02-enum')
-rw-r--r--src/02-enum/enum.lua18
1 files changed, 8 insertions, 10 deletions
diff --git a/src/02-enum/enum.lua b/src/02-enum/enum.lua
index 9c64c1f..b0e5abd 100644
--- a/src/02-enum/enum.lua
+++ b/src/02-enum/enum.lua
@@ -1,24 +1,22 @@
-local function makeEnum(enumtable)
- if enumtable == nil or type(enumtable) ~= "table" then
+local function enum(tbl)
+ if tbl == nil or type(tbl) ~= "table" then
return nil
end
- enumtable.__index = enumtable
- enumtable.__newindex = function()
+ tbl.__index = tbl
+ tbl.__newindex = function()
print("can not modify enum")
end
- local e = {}
- setmetatable(e, enumtable)
- return e
+ return setmetatable({}, tbl)
end
-local function main()
- local mode = makeEnum({
+function main()
+ local mode = enum {
SinglePlayer = 1,
TwoPlayers= 2,
ThreePlayers= 3,
FourPlayers= 4,
PVCom= 5,
- })
+ }
mode.SinglePlayer = 2
print(mode.SinglePlayer)
end