关于Lua中const型变量或者常量的实现

来源:互联网 发布:集思宝a5软件 编辑:程序博客网 时间:2024/05/16 10:39
--定义一个常量local const = {}local temp = {} local mt = { --创建一个元表__newindex = function(t,k,v)    if not temp[k] then        temp[k] = v    else        error("尝试给 const."..k.." 赋值")    endend,__index = temp}setmetatable(const, mt)const.test1 = "test1=="const.test2 = "test2=="print(const.test1, const.test2)

0 0
原创粉丝点击