LUA constant

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;
			end
		end
		}
		return mtt;
	end
	local tag = {}
	setmetatable(tag, smt(who))
	return tag	
end

function 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)
end

xpcall(main, function(msg)
	
end)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章