diff options
author | mitchell <70453897+orbitalquark@users.noreply.github.com> | 2021-04-11 09:34:17 -0400 |
---|---|---|
committer | mitchell <70453897+orbitalquark@users.noreply.github.com> | 2021-04-11 09:34:17 -0400 |
commit | de3a745e1af2e441de868c2aa4849102d376acb5 (patch) | |
tree | c2d7767600dc519b2613ddecaf7e53fb5e8867a2 /core/assert.lua | |
parent | 03fab17277fee7387fd93a9c2774b1ebf3f80fe4 (diff) |
Initial pass reformatting all code.
Use clang-format, LuaFormatter, and 100 character limit on lines.
Diffstat (limited to 'core/assert.lua')
-rw-r--r-- | core/assert.lua | 48 |
1 files changed, 19 insertions, 29 deletions
diff --git a/core/assert.lua b/core/assert.lua index c0e7f44c..95b53628 100644 --- a/core/assert.lua +++ b/core/assert.lua @@ -6,35 +6,30 @@ module('assert')]] --- --- Asserts that value *v* is not `false` or `nil` and returns *v*, or calls --- `error()` with *message* as the error message, defaulting to "assertion --- failed!". If *message* is a format string, the remaining arguments are passed --- to `string.format()` and the resulting string becomes the error message. +-- Asserts that value *v* is not `false` or `nil` and returns *v*, or calls `error()` with +-- *message* as the error message, defaulting to "assertion failed!". +-- If *message* is a format string, the remaining arguments are passed to `string.format()` +-- and the resulting string becomes the error message. -- @param v Value to assert. --- @param message Optional error message to show on error. The default value is --- "assertion failed!". --- @param ... If *message* is a format string, these arguments are passed to --- `string.format()`. +-- @param message Optional error message to show on error. The default value is "assertion failed!". +-- @param ... If *message* is a format string, these arguments are passed to `string.format()`. -- @name _G.assert function assert(v, message, ...) if v then return v end - if type(message) == 'string' and message:find('%%') then - message = string.format(message, ...) - end + if type(message) == 'string' and message:find('%%') then message = string.format(message, ...) end error(message or 'assertion failed!', 2) end --- --- Asserts that value *v* has type string *expected_type* and returns *v*, or --- calls `error()` with an error message that implicates function argument --- number *narg*. --- This is intended to be used with API function arguments so users receive more --- helpful error messages. +-- Asserts that value *v* has type string *expected_type* and returns *v*, or calls `error()` +-- with an error message that implicates function argument number *narg*. +-- This is intended to be used with API function arguments so users receive more helpful error +-- messages. -- @param v Value to assert the type of. --- @param expected_type String type to assert. It may be a non-letter-delimited --- list of type options. --- @param narg The positional argument number *v* is associated with. This is --- not required to be a number. +-- @param expected_type String type to assert. It may be a non-letter-delimited list of type +-- options. +-- @param narg The positional argument number *v* is associated with. This is not required to +-- be a number. -- @usage assert_type(filename, 'string/nil', 1) -- @usage assert_type(option.setting, 'number', 'setting') -- implicates key -- @name _G.assert_type @@ -42,18 +37,13 @@ function assert_type(v, expected_type, narg) if type(v) == expected_type then return v end -- Note: do not use assert for performance reasons. if type(expected_type) ~= 'string' then - error(string.format( - "bad argument #2 to '%s' (string expected, got %s)", + error(string.format("bad argument #2 to '%s' (string expected, got %s)", debug.getinfo(1, 'n').name, type(expected_type)), 2) elseif narg == nil then - error(string.format( - "bad argument #3 to '%s' (value expected, got %s)", + error(string.format("bad argument #3 to '%s' (value expected, got %s)", debug.getinfo(1, 'n').name, type(narg)), 2) end - for type_option in expected_type:gmatch('%a+') do - if type(v) == type_option then return v end - end - error(string.format( - "bad argument #%s to '%s' (%s expected, got %s)", narg, + for type_option in expected_type:gmatch('%a+') do if type(v) == type_option then return v end end + error(string.format("bad argument #%s to '%s' (%s expected, got %s)", narg, debug.getinfo(2, 'n').name or '?', expected_type, type(v)), 3) end |