I'm using Lua as a configuration format for a project mine. Let's suppose I have the following contrived example, we'll call conf.lua
:
title = "Lorem Ipsum"
author = "John Doe"
date = "01 January 2000"
Now, trivially, I can of course load this file like so:
dofile("conf.lua")
However, the problem with this is that these definitions are set in the global namespace, which I do not want. Furthermore, it makes it difficult to access the different variables as a whole (e.g loop over the set of configuration variables). One solution would be to rewrite conf.lua
like so:
local conf = {
title = "Lorem Ipsum",
author = "John Doe",
date = "01 January 2000"
}
return conf
and in turn, load conf.lua
with the following code:
local configuration = dofile("conf.lua")
However, this is non-ideal for I think obvious reasons. It requires my users to keep track of commas, to have to write local
, to have to remember to return the table at the end. What would be nice is if there were some way to cause conf.lua
to execute with a custom scope of some sort.