From a367d18b51d38b9cd1b1e2ca1102ed34da0bc479 Mon Sep 17 00:00:00 2001 From: Max Cahill <1bardesign@gmail.com> Date: Tue, 19 May 2020 13:00:23 +1000 Subject: [PATCH] [added] assert:some for nil checks --- assert.lua | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/assert.lua b/assert.lua index c2d06a9..10c1b03 100644 --- a/assert.lua +++ b/assert.lua @@ -26,6 +26,15 @@ local function _extra(msg) return "(note: " .. msg .. ")" end +--assert a value is not nil +function assert:some(v, msg, stack_level) + if v == nil then + error(("assertion failed: value is nil %s"):format( + _extra(msg) + ), 2 + (stack_level or 0)) + end +end + --assert two values are equal function assert:equals(a, b, msg, stack_level) if a ~= b then