lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Gergo Szakal wrote:
Today I was playing with this code and noticed that running this with the lua5.1 commandline under windows makes lua.exe do a RAM usage spike and then freeze. When I open the file in "a+" mode and write the stuff into it one by one it Just Works (tm), so it seems obvious that the problem lies behind adding the stuff to an array. What might be the problem?

-------------- code follows --------------

tbl={["os"]=1,["math"]=1,["string"]=1,["table"]=1,["debug"]=1,["coroutine"]=1,["_G"]=1}
arr={}

local f=io.open("_G.txt","w")
for W,V in pairs(_G) do
  if type (V)~="table" then
    table.insert(arr, W)
  elseif not tbl[W] then
    for W1,V1 in pairs(V) do
      table.insert(arr, W.."."..W1)
    end
  end
end
f:write(table.concat(arr,"\n"))
f:close()

-------------- code end --------------

TIA for answers.

arr is global, and you keep on adding keys to it.

So when you get around to arr in the outer loop, the inner loop never finishes.

Try

  local arr ...