Search code examples
filetextlualine

Lua Get values of text file lines


In Lua I need to read the value of these, it's like an ini text file, the names could be on any line.

color=3776EB
vsize=200
hsize=400
vpos=20
hpos=40
tittle=TEST

Solution

  • I would do

    vars = {}
    for line in io.lines("file.txt") do 
      var, val = line:match('^([^=]+)=(.*)')
      vars[var] = val
    end
    

    Then you have vars.color, vars.hpos, etc