[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Reading & writing an array of numeric data
- From: RLake@...
- Date: Fri, 12 Mar 2004 10:15:03 -0500
> local arrayFile = "Array.txt"
> local array = { 1, 5, 12.3, 0.25, -45.01, 7 }
> local f = io.open(arrayFile, "w")
> f:write("return {\n")
> for i, v in ipairs(array) do
> f:write("[" .. i .. "]=" .. v .. ",")
> -- Add \n if you want the file to be readable
by humans
> end
> f:write("}\n")
> f:close()
even shorter, although it uses more memory:
function dumpArray(file, array)
local f = assert(io.open(file, "w"))
assert(f:write("return {", table.concat(array,
","), "}"))
assert(f:close())
end