lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


OMG that's funny. No wonder I couldn't find anything on google!

On Tue, Sep 27, 2016 at 10:51 PM, Sean Conner <sean@conman.org> wrote:
> It was thus said that the Great Russell Haley once stated:
>> Hi there,
>>
>> I'm trying to read and write to a conf file (i.e. each line is an
>> item, and key/value pair is separated by '='). I found that penlight
>> has an excellent parser, but it seems a little heavy importing that
>> whole thing  to parse character separated lines.
>
>   [ snip ]
>
>> I'm not familiar enough with line matching patterns or lpeg to be
>> effective (seriously. every time I've tried to 'fix' a reg-ex in C# I wind
>> up breaking it beyond repair). While these are both things I desperately
>> want to learn, I'm trying to get a working prototype of my software
>> together and stopping to learn lpeg is not where I want to be at this
>> time(but I promise to do it!).
>
>   I'll spare you the "you should learn regex/lpeg" line as it appears you
> already know it.
>
>> Any feedback would be dandy.
>
>   You already have a parser available to you---Lua.  If the config file is
> just what you said:
>
>         a=series
>         of=key
>         value=pairs
>
> A small change:
>
>         a='series'
>         of='key'
>         value='pairs'
>         and_a_number=3
>
> and that can be read in as:
>
>         CONF = {} -- your data will end up here
>         f = loadfile("my-configfile.txt","t",CONF)
>         f()
>
>         print(CONF.a,CONF.and_a_number)
>
>   I use Lua as a configuration file at work and there have been no issue
> with that.
>
>   -spc
>
>