Module:CallAssert/doc
< Module:CallAssert
Jump to navigation
Jump to search
Revision as of 10:14, 20 August 2018 by blackwiki>Petr Matas (Creating Module:CallAssert/doc)
This is the documentation page for Module:CallAssert
| This module is rated as alpha. It is ready for third-party input, and may be used on a few pages to see if problems arise, but should be watched. Suggestions for new features or changes in their input and output mechanisms are welcome. |
This metamodule provides function callAssert, which simplifies error checking, similarly to the built-in function assert. Unlike assert however, 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 thrown if the check fails.
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'.