lua-users home
lua-l archive

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


On 08/09/2014 01:54 PM, Axel Kittenberger wrote:
I'm in fact using Lua as configuration language. Having config files set
global varialbles proofed to be a bad idea, since there is not spell
checking and cause lots of issue reports filled in, because people
misspelled one key and then complain that the application didn't
complain at all and silently ignored the setting. Been there, done that.

 From this experience I advice to have config files look more like this,
which I'm doing now:

set {
   window_height = 800,
   user_name = "Sally"
}

This way previously exported set function can thus check if the keys are
typed correctly and understood by the main program and copies them to to
hidden settings table.

Alternatively one could change the metatable of _G but that might have
unwanted consequences / incompatibilities.


This looks very weird. Why not just set a table as the configuration's environment, and then validate that table? This is the natural way (globals go to the "configuration" table). No _G manipulation, tidy configuration files, data validation and isolation.

Jorge