lua-users home
lua-l archive

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

On 05/11/2016 09:34 AM, Sean Conner wrote:
It was thus said that the Great Thomas Jericke once stated:
On 05/10/2016 08:32 PM, Andrew Starks wrote:
To answer your question: One of Lua's main use cases is as a
configuration language. That is: <yourconfigfile.lua> Window_x = 5
Window_y = 100 a very useful syntax for a configuration file
that you might employ in your application. Adding "global" or "local"
to the front of each declaration would be ugly and detract from this
simplicity. Hopefully, in this context, we can agree that "global by
default" makes some sense. -Andrew
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
   But there's no need for the return ("Why do I need a 'return' in a
configuration file?").
I just wanted to make an example that actually no access of _ENV is needed at all.
Not sure if there is another way to do this without a return.

  A configuration file like:

	name       = "A Blog Grows in Cyberspace"
	basedir    = "$HOME/source/boston/journal"
	webdir     = "$HOME/source/boston/htdocs"
	lockfile   = webdir .. ".modblog.lock"
	url        = "";
	author     = { name = "Joe Blog" , email = "" }
	timezone   = "-8:00"
	adtag      = "programming"
	debug      = false
	conversion = "html"

doesn't have to end up setting a bunch of globals:

	config = {}
	f = loadfile("config.file","t",config)

	print( -- Tadaaaaaah!


I am aware of that. It wasn't my point that this syntax is bad, or doesn't work. My point was that it is possible to have lean syntax of config file without accessing the upvalue _ENV

Of course, you can argue that the additional "return {" and "}" make the code already cluttered
but I allow myself to say that this would be nitpicking.
Thomas (Have you seen XML config files? :-[ )