Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何确定lua全局值何时设置为nil?_Lua_Lua Table - Fatal编程技术网

如何确定lua全局值何时设置为nil?

如何确定lua全局值何时设置为nil?,lua,lua-table,Lua,Lua Table,我尝试过这个,但失败了__newindex仅在未设置键时触发 setmetatable(_G, { __newindex = function (table, key, value) print("key: ", key, "value: ", value) rawset(table, key, value) if key == "Config" then print("value: ", value) if value == nil then error(deb

我尝试过这个,但失败了__newindex仅在未设置键时触发

setmetatable(_G, {
__newindex = function (table, key, value)
print("key: ", key, "value: ", value)
rawset(table, key, value)
if key == "Config" then
    print("value: ", value)
    if value == nil then
        error(debug.traceback())
    end
end
end})
以下工作代码:

local m = {}
local t = {
    __newindex = function (table, key, value)
        m[key] = value
        if key == "Config" then
            print("config value: ", value)
        if value == nil then
            error("Config is set to nil!!!!!!"..debug.traceback())
        end
    end
end,
__index = m}
setmetatable(_G, t)

Config = Config or {}
Config = nil

您需要为Lua 5.2+中的全局表(也称为
\u ENV
)设置代理表。是否可以显示更多详细信息?设置代理意味着仅使用专用表来捕获写入/读取事件。实际数据应该存储在其他一些表中。这样你就得到了总是被触发的新索引。具体怎么做-取决于你的需要,因为有很多方法可以组织数据。谢谢,我明白了。