[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Question on reading config files
- From: Paul K <paulclinger@...>
- Date: Sun, 15 Jul 2012 22:33:00 -0700
HI Meino,
> for key, value in ipairs{...} do
> -- something meaningful here
> end
You should be using pairs instead of ipairs and you probably get
exactly what you are looking for: 'key' will get values 'first' and
'second' (with 'value' being the corresponding table value), which you
can then handle in your script any way you want.
Paul.
On Sun, Jul 15, 2012 at 8:40 PM, <meino.cramer@gmx.de> wrote:
> Hi,
>
> Currently I am programming a piece of code what will become a reader
> and handler for config files. The starting point was an example code
> from "Programming in Lua". The final code should read a config file
> with different profiles to setup and handle serial ports so this is
> only an example.
>
> My config file has this layout currently:
>
> profile{
> first={
> author="Donald E. Knuth",
> title= "Literate Programming",
> press= "CSLI",
> year= 1992
> },
> second={
> author= "Jon Bentley",
> title= "More Programming Pearls",
> press= "Addison-Wesley",
> year= 1990
> }
> }
>
> where "first" and "second" are names of different profiles, which the
> user is allowed to name as s/he wants.
>
> A sketch of a snippet of code which reads the config file looks like
> this:
>
>
>
> #! /usr/bin/lua
> local count = 0
> function profile (...)
>
> for key, value in ipairs{...} do
> -- something meaningful here
> end
>
> end
>
> function main()
> dofile("data")
> end
>
> main()
>
> My question is: Is it possible to determine the names of the profiles
> (in my example "first" and "second") from inside the code without
> further input from the user land?
>
> Thank you very much in advance for any help!
>
> Best regards,
> mcc
>
>
>
>