Update: I know you said you wanted to avoid CSV, but it is pretty simple and easy to read so…
If you don’t use commas in your data, you could just:
-
Use Excel or another editor to edit and store data.
-
Export to CSV.
-
Write a small importer to read csv and convert to table.
Using SSK 2 step 3 would look like this:
local function getTable( filename, baseFolder, firstRowAsFieldNames ) local csvData = io.readFileTable( filename, baseFolder ) -- for i = 1, #csvData do csvData[i] = string.trim(csvData[i]) end -- local t = {} -- -- First row of data is 'field names' for subsequent row's data if( firstRowAsFieldNames ) then local fieldNames = string.split(csvData[1],",") for i = 2, #csvData do local tmp = string.split(csvData[i],",") local tmp2 = {} for j = 1, #fieldNames do tmp2[fieldNames[j]] = tmp[j] end t[#t+1] = tmp2 end else for i = 1, #csvData do t[#t+1] = string.split(csvData[i],",") end end return t end local t = getTable( "testData.csv", system.ResourceDirectory, true ) table.print\_r(t) local t = getTable( "testData.csv", system.ResourceDirectory, false ) table.print\_r(t)
For the attached csv file:
name,age,health Bill,20,100 Bob,50,80 Sue,27,95
The output of the code would look like this…
first print_r
10:20:05.848 table: 05AD5210 { 10:20:05.848 [1] =\> table: 05AD5210 10:20:05.848 { 10:20:05.848 [health] =\> "100" 10:20:05.848 [age] =\> "20" 10:20:05.848 [name] =\> "Bill" 10:20:05.848 } 10:20:05.848 [2] =\> table: 05AD5210 10:20:05.848 { 10:20:05.848 [health] =\> "80" 10:20:05.848 [age] =\> "50" 10:20:05.848 [name] =\> "Bob" 10:20:05.848 } 10:20:05.848 [3] =\> table: 05AD5210 10:20:05.848 { 10:20:05.848 [health] =\> "95" 10:20:05.848 [age] =\> "27" 10:20:05.848 [name] =\> "Sue" 10:20:05.848 } 10:20:05.848 }
second print_r
10:20:05.848 table: 05AD5800 { 10:20:05.848 [1] =\> table: 05AD5800 10:20:05.848 { 10:20:05.848 [1] =\> "name" 10:20:05.848 [2] =\> "age" 10:20:05.848 [3] =\> "health" 10:20:05.848 } 10:20:05.848 [2] =\> table: 05AD5800 10:20:05.848 { 10:20:05.848 [1] =\> "Bill" 10:20:05.848 [2] =\> "20" 10:20:05.848 [3] =\> "100" 10:20:05.848 } 10:20:05.848 [3] =\> table: 05AD5800 10:20:05.848 { 10:20:05.848 [1] =\> "Bob" 10:20:05.848 [2] =\> "50" 10:20:05.848 [3] =\> "80" 10:20:05.848 } 10:20:05.848 [4] =\> table: 05AD5800 10:20:05.848 { 10:20:05.848 [1] =\> "Sue" 10:20:05.848 [2] =\> "27" 10:20:05.848 [3] =\> "95" 10:20:05.848 } 10:20:05.848 }