公民:/scripting/resource_init.lua:17:“然后”附近的意外符号

问题描述

我的FiveM服务器的代码以及当我尝试启动服务器时出现的错误提示为“ citizen:/scripting/resource_init.lua:17:'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行上的}完成了从第6行开始的功能定义,因此预期会出现end这个错误。


第三错误: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更加困难