Object Patterns with Tables
Default Field
Choose a default when an object-style field is blank.
Default Field
default_field.lua
local explicit =
local fallback = ({theme = "gray"}).theme
local theme = explicit
if theme == nil or theme == "" then
theme = fallback
end
print("theme=" .. theme)
local explicit =
local fallback = ({theme = "gray"}).theme
local theme = explicit
if theme == nil or theme == "" then
theme = fallback
end
print("theme=" .. theme)
local explicit =
local fallback = ({theme = "gray"}).theme
local theme = explicit
if theme == nil or theme == "" then
theme = fallback
end
print("theme=" .. theme)
default field
Object-style records often need defaults for missing or blank fields.