lua-users home
lua-l archive

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


On Wed, May 11, 2016 at 5:26 AM, Thomas Jericke <tjericke@indel.ch> wrote:
> On 05/11/2016 11:08 AM, Jonathan Goble wrote:
>>
>> On Wed, May 11, 2016 at 2:26 AM, Thomas Jericke <tjericke@indel.ch> wrote:
>>>
>>> I don't think it's a bad idea to structure your configuration parameters.
>>> And once you do that you don't have that many globals in configuration
>>> files
>>> either:
>>>
>>> return {
>>>      Window = {
>>>          x = 5
>>>          y = 100
>>>      }
>>> }
>>> end
>>
>>
>> Another argument against this style: you forgot the mandatory field
>> separator comma after "x = 5". :-)
>>
> Right, but there you have another nice Lua feature
>
> return {
>     Window = {
>         x = 5,
>         y = 100,
>     }
> }
> end
>
>
> ;-)

Indeed; that's a feature that I love about Lua and have made plenty of
use of when writing a function to serialize a table to a string.

However, for a manually edited configuration file, it's very, very
easy to forget the comma as you did here, and as I've done more times
than I can count, and the result is not pretty. If I have to have a
manually edited file containing tables, such as a rockspec, I prefer
this style:

tablename = {}
tablename.key1 = "value 1"
tablename.key2 = true
(etc.)

This is easier to maintain with no worry about forgetting a field
separator, since there aren't any.