-3

I am getting an error when i compile this lua script. The LUA editor and ptokaX Server seem to think so. I am unable to figure out the error. The LUA Editor says the error is in dofile( path.."files/mcunsubs.txt" ). The PtokaX Editor says that the error is in this part of the code :

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

Here is the code.

--[[
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

hjpotter92
  • 78,589
  • 36
  • 144
  • 183
  • What errors are they each giving you? Where does `path` come from? Does `path` end in a `\` or are you missing one before `files/...`? – Etan Reisner May 01 '14 at 20:22
  • lua uses `%` to escape magic characters in patterns, not `\`. Your first gsub (the one with the `Removing the terminating ...` comment) does not only remove a terminating `|`. – Etan Reisner May 01 '14 at 20:23

1 Answers1

0

The Lua editor (which I assume is SciTE) is giving you the error in line #12 because SciTE doesn't recognise the Core table in the next line:

tabUsers = Core.GetOnlineUsers()

When you execute the same script in PtokaX, the Core table is defined and no error is encountered there. Since you are using a newer Lua version than the one in which this file was originally written (written for Lua 5.1, you've Lua 5.2) you are getting the error. Lua 5.1 was more permissive with wrong patterns for string matching, whereas the latter isn't.

For a solution, you can use the following:

data = data:gsub( "|", "" ):gsub( "|", "|" ):gsub( "$", "$" )
hjpotter92
  • 78,589
  • 36
  • 144
  • 183
  • Hi hjpotter92, I have posted on the Github hhfh repository issues the problem. Let me know what i can do to help solve the issues. I understand most of the errors are occurring as I am running the hhfh script on a Windows Machine. – Ananya Chandra May 02 '14 at 18:26