PtokaX forum

Development Section => Your Developing Problems => Topic started by: Tom on 21 February, 2005, 09:01:56

Title: Problem with Lua 5.0.2
Post by: Tom on 21 February, 2005, 09:01:56
Hi ppl,

can somebody help me please.

I need convert this script, but that don't convert with plop's convertor, PLS help me!

This is part of the script, which I need convert in LUA 5.0.2:

    arrRR = {}
    fRR = "reqreg.dat"

    function Main()
    frmHub:RegBot(sBot)
    LoadFromFile(fRR)
    end

    function OnExit()
    SaveToFile(fRR,arrRR,"arrRR")
    end

    function SaveToFile(file , table , tablename)
    writeto(file)
    write(Serialize(table, tablename))
    writeto()
    end

    function LoadFromFile(file)
    if (readfrom(file) ~= nil) then
    readfrom(file)
    dostring(read("*all"))
    readfrom()

PLS, help me with convert, it is very important!

    Thank you in advance!!!
Title:
Post by: plop on 21 February, 2005, 12:51:08
give this a try.
arrRR = {}
fRR = "reqreg.dat"

function Main()
   frmHub:RegBot(sBot)
   dofile(fRR)
end

function OnExit()
   SaveToFile(fRR,arrRR,"arrRR")
end

function SaveToFile(file , tTable , tablename)
   fFile = io.open(file, "w")
   fFile:write(Serialize(tTable, tablename))
   fFile:close()
end

function LoadFromFile(file)
   local fFile = io.open(file)
   if fFile then
dofile(file)
fFile:close()
   end
end

function Serialize(tTable,sTableName,hFile,sTab)
   sTab = sTab or "";
   fFile:write(hFile,sTab..sTableName.." = {\n");
   for key,value in tTable do
local sKey = (type(key) == "string") and os.format("[%q]",key) or os.format("[%d]",key);
if(type(value) == "table") then
  Serialize(value,sKey,hFile,sTab.."\t");
else
  local sValue = (type(value) == "string") and os.format("%q",value) or os.tostring(value);
  fFile:write(hFile,sTab.."\t"..sKey.." = "..sValue);
end
fFile:write(hFile,",\n");
   end
   fFile:write(hFile,sTab.."}");
end

plop