Content deleted Content added
Add category |
Rv; this is the English Wikipedia, not the Turkish Wikipedia |
||
(6 intermediate revisions by 4 users not shown) | |||
Line 1:
{{Module rating|
{{used in system}}
This [[Help:Lua metamodules|metamodule]] simplifies error handling in other modules. It transforms a function, which may throw an error, into a function, which returns a specified error message in that case.
== Usage ==
<syntaxhighlight lang="lua">
local protect = require('Module:Protect')
local protectedFunc =
</syntaxhighlight>
=== Arguments ===
Line 26:
== Example ==
<syntaxhighlight lang="lua">
local protect = require('Module:Protect')
▲ function p.main(frame)
▲ if not frame.args[1] then
▲ error('missing argument')
▲ return frame.args[1]
▲ end
▲ p.main = '''protect'''(p.main)
return p▼
</syntaxhighlight>
Invoking the main function without arguments will output: <strong class="error">Error: missing argument</strong>
<includeonly>{{#ifeq:{{SUBPAGENAME}}|sandbox | |
[[Category:Error-handling modules]]
}}</includeonly>
|