Lua
配置語法Lapis
的配置模塊提供了對遞歸合併 table
的支持。api
例如,咱們能夠定義一個基本配置,而後覆蓋更多具體的配置聲明中的一些值:app
-- config.lua local config = require("lapis.config") config({"development", "production"}, { host = "example.com", email_enabled = false, postgres = { host = "localhost", port = "5432", database = "my_app" } }) config("production", { email_enabled = true, postgres = { database = "my_app_prod" } })
這將產生如下兩個配置結果(默認值省略):函數
-- "development" { host = "example.com", email_enabled = false, postgres = { host = "localhost", port = "5432", database = "my_app", }, _name = "development" }
-- "production" { host = "example.com", email_enabled = true, postgres = { host = "localhost", port = "5432", database = "my_app_prod" }, _name = "production" }
您能夠在相同的配置名稱上調用 config
函數屢次,每次將傳入的表合併到配置中。post