市民:/scripting/resource_init.lua:17:'then' 附近出现意外符号

citizen:/scripting/resource_init.lua:17: unexpected symbol near 'then'

我的 fiveM 服务器代码,当我尝试启动你的服务器时,我收到错误提示“citizen:/scripting/resource_init.lua:17: unexpected symbol near 'then'“有人可以帮我吗?

return function(chunk)
    local addMetaData = AddMetaData

    setmetatable(_G end
    
        __index = function(t, k)
            local raw = rawget(t, k)
        end
            if raw then
                return raw
            

            return function(value)
                local newK = k
            
                if type(value) == 'table' then
                    -- remove any 's' at the end (client_scripts, ...)
                    if k:sub(-1) ==  then
                        newK = k:sub(1, -2)
                    

                    -- add metadata for each table entry
                    for _, v in ipairs(value) do
                        addMetaData(newK, v)
                    end
                else
                    addMetaData(k, value)
                end

                -- for compatibility with legacy things
                return function(v2)
                    addMetaData(newK .. '_extra', json.encode(v2))
                end
            end
        end
    })

    -- execute the chunk
    chunk()

    -- and reset the metatable
    setmetatable(_G, nil)
end

您的代码中有很多错误,标题中的错误不是您运行此代码时当前出现的错误。


第一个错误::4: ')' expected near 'end'

第 4 行是:

setmetatable(_G end

应该是

setmetatable(_G, {

这个错误很不清楚,因为这是一个相当奇怪的错误,我不确定为什么 end 会放在那里。


第二个错误::9: '}' expected (to close '{' at line 4) near 'if'

第 8 行有一处错位 end,本应在第 11 行。 此错误应为 },因为第 8 行的 end 完成了第 6 行开始的函数定义。


第三个错误:18: unexpected symbol near 'then'

第 18 行是:

if k:sub(-1) ==  then

应该类似于:

if k:sub(-1) == "s" then

你需要 ==

的第二个操作数

第四个错误::36: 'end' expected (to close 'function' at line 6) near '}'

第 32 行和第 33 行之间缺少 end。 这个错误很明显,值得一提的是缩进最终变得不稳定,这会使看到丢失的 end 有点困难