Try
local f = io.open("grid.txt")
assert(f, "unable to open the file")
local arr = {}
for l in f:lines() do
local row = {}
for snum in l:gmatch("(%d+)") do
table.insert(row, tonumber(snum))
end
table.insert(arr, row)
end
for i=1,#arr do
for j=1,#arr[i] do
print( string.format("arr[%d][%d] = %d", i, j, arr[i][j]))
end
end