Practical Scripting Patterns
Config Defaults
Choose a configuration value with a clear fallback.
Config Defaults
config_default.lua
local mode =
local port = 80
if mode == "dev" then
port = 8080
elseif mode == "test" then
port = 9000
end
print("mode=" .. mode)
print("port=" .. port)
local mode =
local port = 80
if mode == "dev" then
port = 8080
elseif mode == "test" then
port = 9000
end
print("mode=" .. mode)
print("port=" .. port)
local mode =
local port = 80
if mode == "dev" then
port = 8080
elseif mode == "test" then
port = 9000
end
print("mode=" .. mode)
print("port=" .. port)
config-default
Small scripts often combine one explicit setting with a safe default. Keeping the selected value in a scalar variable makes the decision easy to inspect.