Object Patterns with Tables
Computed Property
Calculate a derived value from object-style fields.
Computed Property
computed_property.lua
local width =
local height = 3
local area = ({width = width, height = height}).width * ({width = width, height = height}).height
local label = "area:" .. area
print("width=" .. width)
print("height=" .. height)
print("label=" .. label)
local width =
local height = 3
local area = ({width = width, height = height}).width * ({width = width, height = height}).height
local label = "area:" .. area
print("width=" .. width)
print("height=" .. height)
print("label=" .. label)
local width =
local height = 3
local area = ({width = width, height = height}).width * ({width = width, height = height}).height
local label = "area:" .. area
print("width=" .. width)
print("height=" .. height)
print("label=" .. label)
computed property
A computed property is not stored directly; it is calculated from other fields.