lua-users home
lua-l archive

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


2014-08-11 14:37 GMT+02:00 Axel Kittenberger <axkibe@gmail.com>:

> if you have a project that has config files that are supposed to be "Lua"

I've played with your idea of functions with table-valued arguments,
to make a sort of DSL, but even that is asking too much from a user.

I now do it this way:

~~~~
local loadfile = loadfile
local params = {}
do
   local ok, msg = loadfile("config.lua","t",params)
   if ok then ok, msg = pcall(ok) end
   -- check `params` and extract what you can use
end
~~~~

Thus "config.lua" is just like an interactive environment
except that the user has no libraries whatsoever. It typically
looks like this:

    year = 2014
    host = "SAF"
    paper = "A1,C3,G5; G1,N3,C5"