我无法理解为什么两个编辑器在相同的脚本上会给出不同的语法错误。

当我编译这个 Lua 脚本时,出现错误。LUA 编辑器和 ptokaX 服务器似乎也是这样认为的。我无法找出错误所在。 LUA 编辑器显示错误在 dofile( path.."files/mcunsubs.txt" ) 处。 PtokaX 编辑器显示错误在以下代码部分:

data = data:gsub( "[\|]", "" )
data = data:gsub( "\&\#124\;", "\|" )
data = data:gsub( "\&\#036\;", "\$" )

以下是代码。

--[[
This file is part of HiT Hi FiT Hai's PtokaX scripts
Copyright: © 2014 HiT Hi FiT Hai group
Licence: GNU General Public Licence v3 https://www.gnu.org/licenses/gpl-3.0.html
--]]

unsubbed={}
subbed={}
dofile( path.."files/mcunsubs.txt" )
tabUsers = Core.GetOnlineUsers()

for k,v in ipairs(tabUsers) do
    if not isthere_key(v.sNick,unsubbed) then
        table.insert(subbed,v.sNick)
    end
end

ircout = function(data)
    data = data:gsub( "[\|]", "" )  --  Removing the terminating '|'     character only.
    data = data:gsub( "\&\#124\;", "\|" )
    data = data:gsub( "\&\#036\;", "\$" )
    local file= io.open("/root/DCout.txt","a+")
    file:write(data.."\n")
    file:flush()
    file:close()
   end

dcmcout = function(data)
    for k,v in ipairs(subbed) do
        Core.SendToNick(v,data)
    end
end

UserConnected= function (tUser)
    if not isthere_key(tUser.sNick,unsubbed) then
        if not isthere_key(tUser.sNick,subbed) then
            table.insert(subbed,tUser.sNick)
        end
    end
end
RegConnected = UserConnected
OpConnected = UserConnected
UserDisConnected= function (tUser)
    key = isthere_key(tUser.sNick,subbed)
    while key do
        table.remove( subbed, key)
        key = isthere_key(user.sNick,subbed)
    end
end
RegDisConnected = UserDisConnected
OpDisConnected = UserDisConnected
点赞
用户1190388
用户1190388

我假设SciTE是Lua编辑器,当在第12行 中输入 Core 表时,它会给你一个错误信息,因为SciTE无法识别它。

tabUsers = Core.GetOnlineUsers()

当你在PtokaX中执行相同的脚本时,Core表被定义了,所以不会遇到错误。由于您使用的是比写入此文件的Lua 5.1更新的Lua版本(您使用的是Lua 5.2),因此会出现错误。 Lua 5.1对带有不正确的字符串匹配模式更宽容,而后者则不是。

要解决这个问题,您可以使用以下方法:

data = data:gsub( "|", "" ):gsub( "|", "|" ):gsub( "$", "$" )
2014-05-01 22:18:12