Lua: how to load a large CSV file into a table and acess it
snippet in lua

Lua: how to load a large CSV file into a table and acess it

user1623

function readwaypoints(filename, numberofwaypoints)
  local file = io.open(filename)
  local waypoints = {}
  for n = 1, numberofwaypoints do
    local x, y, z
    x = file:read('*n'); file:read(1) --<-- added
    y = file:read('*n'); file:read(1) --<-- added
    z = file:read('*n'); file:read(1) --<-- added
    waypoints[#waypoints+1] = {['x'] = x, ['y'] = y, ['z'] = z}
  end
  file:close()
  return waypoints
end

local waypoints = readwaypoints("waypoints.txt", 20)
print(waypoints[2].x == 24.44, waypoints[1].z == 23.47)