New projects ready to use LUA development, static data is generally stored in the CSV, so the reference online a lot of information to write a CSV file to read the small code, because just touch lua, so just realize the function, and then optimize.
Reference xv_ly15 and the function of the stupid wood to configure their own project requirements implementation
function split (str, reps) Local resultstrslist = {}; String.gsub (str, ' [^ ': Reps..]
+ ', function (w) table.insert (Resultstrslist, W) end);
return resultstrslist;
End--row by row fetch data local function getrowcontent (file) local content;
Local check = False local count = 0 while true does local t = File:read () if not T and then if Count = = 0 Then check = True End Break End If not content then con Tent = T Else content = content: T end Local i = 1 while true does local index = String.find (t, "\" ", I) if not index then B
Reak End i = index + 1 count = count + 1 End If count% 2 = = 0 Then
Check = True break end End If not check then assert (1~=1) end --Returns a row of data with a blank space, and a method that is not understood, and then modifies the return content and (string.gsub (content, "", "")) End FunCtion Loadcsvfile (FilePath)--read file Local alls = {} local file = Io.open (FilePath, "R") while True
Local line = getrowcontent (file) if is not, and break end Table.insert (alls, line) end
--[[is saved from line 2nd (the first row is the title, the next line is the content) is saved with a two-dimensional array: arr[id][property title string]] [Local titles = Split (Alls[1], ",") Local ID = 1
Local Arrs = {} for i = 2, #alls, 1 Do--one row, the contents of each column, the first bit ID local content = Split (Alls[i], ",")
id = tonumber (content[1])--Save the ID so that traversal is used, the original traversal can be performed using in pairs, so this does not require--table.insert (Arrs, i-1, ID) Arrs[id] = {}--with the title as the index, save the contents of each column, the value of the time to take: arrs[1]. Title for j = 1, #titles, 1 do arrs[id][titles[j]] = Content[j] end end return arrs en
D