Check that a required value is present.

required value Checking both `nil` and an empty string catches two common missing-value cases.

Nil Check

raw
nil_check.lua
Replay: real traced execution (multi-file project)
local raw = "name"
local passed = raw ~= nil and raw ~= ""
local status = "fail"
if passed then
    status = "pass"
end
print("raw=" .. tostring(raw))
print("status=" .. status)
local raw = ""
local passed = raw ~= nil and raw ~= ""
local status = "fail"
if passed then
    status = "pass"
end
print("raw=" .. tostring(raw))
print("status=" .. status)
local raw = nil
local passed = raw ~= nil and raw ~= ""
local status = "fail"
if passed then
    status = "pass"
end
print("raw=" .. tostring(raw))
print("status=" .. status)
  1. raw ← name, passed ← true, status ← fail

    1local raw→ name = "name" --@raw="", nil2local passed→ true = rawname ~= nil and raw ~= ""3local status→ fail = "fail"4if passed then
  2. status ← pass

    3local status = "fail"4if passedtrue then5    status→ pass = "pass"6end
  3. print("raw=" .. tostring(raw))

    6end7print("raw=" .. tostring(rawname))8print("status=" .. statuspass)
    outputraw=name
    status=pass
  1. raw ← (empty), passed ← false, status ← fail

    1local raw→ (empty) = ""2local passed→ false = raw(empty) ~= nil and raw ~= ""3local status→ fail = "fail"4if passed then5    status = "pass"6end7print("raw=" .. tostring(raw(empty)))8print("status=" .. statusfail)
    outputraw=
    status=fail
  1. raw ← nil, passed ← false, status ← fail

    1local raw→ nil = nil2local passed→ false = rawnil ~= nil and raw ~= ""3local status→ fail = "fail"4if passed then5    status = "pass"6end7print("raw=" .. tostring(rawnil))8print("status=" .. statusfail)
    outputraw=nil
    status=fail