Pick behavior from an action name the way a method dispatcher would.

method dispatch Object methods often select behavior from an action name and the object's current fields.

Method Dispatch

action
method_dispatch.lua
Replay: real traced execution (multi-file project)
local action = "open"
local label = "unknown"
if action == "open" then
    label = "opening"
end
if action == "close" then
    label = "closing"
end
if action == "pause" then
    label = "paused"
end
local message = ({action = action, label = label}).action .. ":" .. ({action = action, label = label}).label
print("action=" .. action)
print("message=" .. message)
local action = "close"
local label = "unknown"
if action == "open" then
    label = "opening"
end
if action == "close" then
    label = "closing"
end
if action == "pause" then
    label = "paused"
end
local message = ({action = action, label = label}).action .. ":" .. ({action = action, label = label}).label
print("action=" .. action)
print("message=" .. message)
local action = "pause"
local label = "unknown"
if action == "open" then
    label = "opening"
end
if action == "close" then
    label = "closing"
end
if action == "pause" then
    label = "paused"
end
local message = ({action = action, label = label}).action .. ":" .. ({action = action, label = label}).label
print("action=" .. action)
print("message=" .. message)
  1. action ← open, label ← unknown

    1local action→ open = "open" --@action="close", "pause"2local label→ unknown = "unknown"3if action == "open" then
  2. label ← opening

    2local label = "unknown"3if actionopen == "open" then4    label→ opening = "opening"5end
  3. message ← open:opening

    11end12local message→ open:opening = ({action = action, label = label}).actionopen .. ":" .. ({action = action, label = label}).labelopening13print("action=" .. actionopen)14print("message=" .. messageopen:opening)
    outputaction=open
    message=open:opening
  1. action ← close, label ← unknown

    1local action→ close = "close"2local label→ unknown = "unknown"3if action == "open" then
  2. label ← closing

    5end6if actionclose == "close" then7    label→ closing = "closing"8end
  3. message ← close:closing

    11end12local message→ close:closing = ({action = action, label = label}).actionclose .. ":" .. ({action = action, label = label}).labelclosing13print("action=" .. actionclose)14print("message=" .. messageclose:closing)
    outputaction=close
    message=close:closing
  1. action ← pause, label ← unknown

    1local action→ pause = "pause"2local label→ unknown = "unknown"3if action == "open" then
  2. label ← paused

    8end9if actionpause == "pause" then10    label→ paused = "paused"11end
  3. message ← pause:paused

    11end12local message→ pause:paused = ({action = action, label = label}).actionpause .. ":" .. ({action = action, label = label}).labelpaused13print("action=" .. actionpause)14print("message=" .. messagepause:paused)
    outputaction=pause
    message=pause:paused