LUA constant

来源:互联网 发布:德军总部新巨人 知乎 编辑:程序博客网 时间:2024/06/05 18:54
function constant(who)local smt = function(who)local mtt = {__index = function(t,k)return who[k]end,__newindex = function(t,k,v)if(who[k] == nil) then  who[k] = v;endend}return mtt;endlocal tag = {}setmetatable(tag, smt(who))return tagendfunction main()local PROTOCOLS = constant({TCP=1,UDP=2,ICMP=3,RAW=4})PROTOCOLS.IDP = 9;print(PROTOCOLS.TCP);PROTOCOLS.TCP = 5;print(PROTOCOLS.TCP)print(PROTOCOLS.IDP)endxpcall(main, function(msg)end)

0 0
原创粉丝点击