在我的元表脚本中调试意外的null

问题描述 投票:0回答:1

我一直在使用此元表,而此错误是最难修复的错误:

local Check = {
    InvitedMembers = {
        John = "Allowed",
        Mary = "Allowed",
        Halley = "Allowed"
    }
}
local Filter = {
    __index = function(t,k)
        for i ,v in pairs(t.InvitedMembers) do
            if i ~= k then
                error("You're not invited by us")
            elseif i == k then
                return "This way"
            end
        end
    end
}
local ConnectFilter = setmetatable(Check,Filter)
print(Check.InvitedMembers.Sans)

我试图进行过滤,但是此代码返回了nil值。

lua
1个回答
2
投票

您的代码中有两个错误:

© www.soinside.com 2019 - 2024. All rights reserved.