Module:Protect/doc: Difference between revisions

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|aprotected}}
{{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 = '''protect(''func'', ''errFormat'', ''options'')'''
</syntaxhighlight>
 
=== Arguments ===
 
Line 26:
 
== Example ==
<syntaxhighlight lang="lua">
local protect = require('Module:Protect')
 
local protectp = require('Module:Protect'){}
 
function p.main(frame)
local p = {}
if not frame.args[1] then
error('missing argument')
function p.main(frame)
end
if not frame.args[1] then
return frame.args[1]
error('missing argument')
end
 
return frame.args[1]
p.main = '''protect'''(p.main)
end
p.main = '''protect'''(p.main)
return p
 
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]]
[[Category:Lua metamodules]]
}}</includeonly>