Author Topic: Problem with Lua 5.0.2  (Read 1584 times)

0 Members and 1 Guest are viewing this topic.

Offline Tom

  • Junior Member
  • **
  • Posts: 12
  • Karma: +0/-0
Problem with Lua 5.0.2
« 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!!!

PtokaX forum

Problem with Lua 5.0.2
« on: 21 February, 2005, 09:01:56 »

Offline plop

  • Forum God
  • ****
  • Posts: 2 464
  • Karma: +37/-0
(No subject)
« Reply #1 on: 21 February, 2005, 12:51:08 »
give this a try.
Code: [Select]
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
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

PtokaX forum

(No subject)
« Reply #1 on: 21 February, 2005, 12:51:08 »