bartbes wrote:Haven't tested it, but this should work.
You forgot the "then" after the first if- fork but other than that it runs perfectly fine.
It's a pretty clear example but I'd like to add 2 questions, I've browsed the lua tutorial wiki as well pil to some extent but haven't found what I wanted to know.
So basically if I want to write a "clean" config file there are two problems, with clean config files I mean something like this:
Code: Select all
[sectionheader]
setting1= 800
setting2 = 600
setting3= true
[sectionheader2]
anothersetting= 12
Ok so the first question: Is there a easy way to "break up" the strings to use them in tonumber() , basically something like
Code: Select all
tonumber(breakup("setting1= 800"))
would return 800, --meaning the breakup() would only return the numerals out of the string
of course the string "setting1= 800" would be supplied by f:lines() in the real code.
The second question: In such a config file there would be lines that can/should be ignored by the read function (sectionheaders, empty lines), of course you could simply write a function that checks if a line starts with "[" or an empty space, but there should be a simpler way like telling f:lines() wich line to read, right?
Edit: Now that I think about it I'd like to add another thing, is there something similiar to tonumbers() for booleans? converting the strings "true" and "false"?
If not it's not a big deal, just use 0 /1 in the config and when the var from the conf == 0 , set the var to false.