Module:CallAssert/doc: Difference between revisions
From Kenshi Wiki
More actions
No edit summary |
No edit summary |
||
Line 13: | Line 13: | ||
}}</includeonly> | }}</includeonly> | ||
<noinclude> | <noinclude> | ||
[[Category:Module documents]] | |||
[[Category:Module documentation pages]] | [[Category:Module documentation pages]] | ||
</noinclude> | </noinclude> |
Revision as of 01:22, 6 March 2025
This is a documentation subpage for Module:CallAssert. It may contain usage information, categories and other content that is not part of the original module page. |
This metamodule provides function callAssert, which simplifies error checking by throwing an error if a given function returns nil or false. This is similar to the built-in function assert, but unlike it, callAssert itself calls the function, whose return value is to be checked. This allows it to include the function name and argument values in the error message.
Usage
local callAssert = require('Module:CallAssert') local result1, result2, etc = callAssert(func, 'funcName', ...)
callAssert
calls func(...)
and checks if the first returned value evaluates to true. If it does, then it returns all the returned values. If not, it throws an error with a message in the form 'funcName(argument_values) failed'
.