lua-users home
lua-l archive

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

> What I would like to do is find if certain parameters are defined for
> different subsets.  I am able to find my line range by locating the
> subset title and then the next blank line following it.  I then want
> to find my matching parameter that falls inside that range.  The way I
> would like to do this is with a function like so
> FindLineInFile_Range(filename,desired_line,start_of_range,end_of_range)
>         -- code here....
>         if line_found then
>              return line_number
>         else
>              return nil
>          end
> end
> The problem that I am running into is that the only file offset I have
> encountered is a character offset via file:seek("set", charOffset).
> Is there an easy way to offset directly to the lines I desire?

Can't you just dispense with the line numbers and file offsets altogether?

For each subset, create a table S with keys being the parameters and 
values being the data. Then, for the whole config file, create a table T 
with keys being the subset name and values being the relevant S table 
above. See the code on p.49 of the Lua 5.0 Ref Man, which converts a 
string of "param1=val1 param2=val2..." into a table.

You can use file:read("*a") to suck the whole config file into a string.