PtokaX forum

Archive => Archived 5.0 boards => Request for scripts => Topic started by: Light on 09 October, 2005, 03:04:02

Title: To lua5
Post by: Light on 09 October, 2005, 03:04:02
Help, can someone convert this to lua5?


hubUsers = {}

function readfile(fName)
   local fHandle = io.open(fName, "r")
   if fHandle then local tmp = f:read(fHandle, "*a") fFile:close(fHandle) return tmp end
end

function parseUsers()
   local table = {n=0}
   local users = f:read("../temp.dat") assert(users, "parseUsers()")
   g.sub(users, "(%S-)|(%C+)|(%d+)%c", function(name, pass, level) tinsert(%table, { sName = name, sPass = pass, iLevel = tonumber(level) }) end)
   return table
end

function updateUsers()
   local tmp = parseUsers()
   foreachi(tmp, function(id, user) %Users[user.sName] = user.iLevel end)
end

function OnTimer()
   local tmp = parseUsers()
   if tmp then foreachi(tmp, function(id, user)
      if not hubUsers[user.sName] then AddRegUser(user.sName, user.sPass, user.iLevel) end end)
   end updateUsers()
end

function Main()
   updateUsers()
   SetTimer(60*100) StartTimer()
end
Title:
Post by: bastya_elvtars on 09 October, 2005, 13:38:09
Please post the original LUA4 script, because this is halfways LUA5 and is screwed up. :(
Title:
Post by: Light on 09 October, 2005, 19:59:25
hmm sorry))




hubUsers = {}

function readfile(fName)
local fHandle = openfile(fName, "r")
if fHandle then local tmp = read(fHandle, "*a") closefile(fHandle) return tmp end
end

function parseUsers()
local table = {n=0}
local users = readfile("../temp.dat") assert(users, "parseUsers()")
gsub(users, "(%S-)|(%C+)|(%d+)%c", function(name, pass, level) tinsert(%table, { sName = name, sPass = pass, iLevel = tonumber(level) }) end)
return table
end

function updateUsers()
local tmp = parseUsers()
foreachi(tmp, function(id, user) %hubUsers[user.sName] = user.iLevel end)
end

function OnTimer()
local tmp = parseUsers()
if tmp then foreachi(tmp, function(id, user)
if not hubUsers[user.sName] then AddRegUser(user.sName, user.sPass, user.iLevel) end end)
end updateUsers()
end

function Main()
updateUsers()
SetTimer(60*100) StartTimer()
end -- tezlo
Title:
Post by: bastya_elvtars on 09 October, 2005, 20:27:19
Not tested.

hubUsers = {}

function readfile(fName)
  local fHandle = io.open(fName, "r")
  if fHandle then local tmp = fHandle:read("*a") fHandle:close() return tmp end
end

function parseUsers()
  local tbl = {n=0}
  local users = readfile("../temp.dat") assert(users, "parseUsers()")
  string.gsub(users, "(%S-)|(%C+)|(%d+)%c",
    function(name, pass, level)
      table.insert(tbl, { sName = name, sPass = pass, iLevel = tonumber(level) })
    end)
  return tbl
end

function updateUsers()
  local tmp = parseUsers()
  table.foreachi(tmp,
  function(id, user)
    hubUsers[user.sName] = user.iLevel
  end)
end

function OnTimer()
  local tmp = parseUsers()
  if tmp then table.foreachi(tmp,
    function(id, user)
      if not hubUsers[user.sName] then
        AddRegUser(user.sName, user.sPass, user.iLevel)
      end
    end)
  end
  updateUsers()
end

function Main()
  updateUsers()
  SetTimer(60*100) StartTimer()
end -- tezlo
Title:
Post by: Light on 11 October, 2005, 09:43:15
big thanks))