Calculate a derived value from object-style fields.

computed property A computed property is not stored directly; it is calculated from other fields.

Computed Property

width
computed_property.lua
Replay: real traced execution (multi-file project)
local width = 4
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 = 2
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 = 6
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)
  1. width ← 4, height ← 3, area ← 12, label ← area:12

    1local width→ 4 = 4 --@width=2, 62local height→ 3 = 33local area→ 12 = ({width = width, height = height}).width4 * ({width = width, height = height}).height34local label→ area:12 = "area:" .. area125print("width=" .. width4)6print("height=" .. height3)7print("label=" .. labelarea:12)
    outputwidth=4
    height=3
    label=area:12
  1. width ← 2, height ← 3, area ← 6, label ← area:6

    1local width→ 2 = 22local height→ 3 = 33local area→ 6 = ({width = width, height = height}).width2 * ({width = width, height = height}).height34local label→ area:6 = "area:" .. area65print("width=" .. width2)6print("height=" .. height3)7print("label=" .. labelarea:6)
    outputwidth=2
    height=3
    label=area:6
  1. width ← 6, height ← 3, area ← 18, label ← area:18

    1local width→ 6 = 62local height→ 3 = 33local area→ 18 = ({width = width, height = height}).width6 * ({width = width, height = height}).height34local label→ area:18 = "area:" .. area185print("width=" .. width6)6print("height=" .. height3)7print("label=" .. labelarea:18)
    outputwidth=6
    height=3
    label=area:18