Choose a configuration value with a clear fallback.

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.

Config Defaults

mode
config_default.lua
Replay: real traced execution (multi-file project)
local mode = "prod"
local port = 80

if mode == "dev" then
  port = 8080
elseif mode == "test" then
  port = 9000
end

print("mode=" .. mode)
print("port=" .. port)
local mode = "dev"
local port = 80

if mode == "dev" then
  port = 8080
elseif mode == "test" then
  port = 9000
end

print("mode=" .. mode)
print("port=" .. port)
local mode = "test"
local port = 80

if mode == "dev" then
  port = 8080
elseif mode == "test" then
  port = 9000
end

print("mode=" .. mode)
print("port=" .. port)
  1. mode ← prod, port ← 80

    1local mode→ prod = "prod" --@mode="dev", "test"2local port→ 80 = 8034if mode == "dev" then5  port = 80806elseif mode == "test" then7  port = 90008end910print("mode=" .. modeprod)11print("port=" .. port80)
    outputmode=prod
    port=80
  1. mode ← dev, port ← 80

    1local mode→ dev = "dev"2local port→ 80 = 80
  2. port ← 8080

    4if modedev == "dev" then5  port→ 8080 = 80806elseif mode == "test" then
  3. print("mode=" .. mode)

    10print("mode=" .. modedev)11print("port=" .. port8080)
    outputmode=dev
    port=8080
  1. mode ← test, port ← 80

    1local mode→ test = "test"2local port→ 80 = 80
  2. port ← 9000

    5  port = 80806elseif modetest == "test" then7  port→ 9000 = 90008end
  3. print("mode=" .. mode)

    10print("mode=" .. modetest)11print("port=" .. port9000)
    outputmode=test
    port=9000