Building a Config DSL
Create a declarative config language that loads via dofile() in a sandbox.
Goal: Declarative Config
A config DSL lets users express configuration in a readable, declarative style while using Lua's full power (conditionals, loops, functions) behind the scenes.
Config Function Pattern
Expose a config(tbl) function that validates and stores configuration. Call it with a table literal for clean syntax.
local function config(tbl)
-- validate and store
return tbl
end
-- config.lua:
return config {
host = "localhost",
port = 8080,
debug = os.getenv("DEBUG") == "1",
}