Overwatch Wiki
Explore
Main Page
Discuss
All Pages
Interactive Maps
navigation
Main page
Recent changes
Random page
Useful pages
Comics
Heroes
Maps
Roles
Skins
Competitive
Teams
Tournaments
Community
Join Us!
Community portal
Admin noticeboard
Wiki rules
More
Portals
Official Website
Latest Announcements
Official Twitter
Reddit Page
Gamepedia
Gamepedia support
Report a bad ad
Help Wiki
Contact us
Related Wikis
Warcraft
StarCraft
Diablo
Hearthstone
Heroes of the Storm
FANDOM
Fan Central
BETA
Games
Anime
Movies
TV
Video
Wikis
Explore Wikis
Community Central
Start a Wiki
Don't have an account?
Register
Sign In
Sign In
Register
Overwatch Wiki
2,109
pages
Explore
Main Page
Discuss
All Pages
Interactive Maps
navigation
Main page
Recent changes
Random page
Useful pages
Comics
Heroes
Maps
Roles
Skins
Competitive
Teams
Tournaments
Community
Join Us!
Community portal
Admin noticeboard
Wiki rules
More
Portals
Official Website
Latest Announcements
Official Twitter
Reddit Page
Gamepedia
Gamepedia support
Report a bad ad
Help Wiki
Contact us
Related Wikis
Warcraft
StarCraft
Diablo
Hearthstone
Heroes of the Storm
Editing
Module:Arguments/doc
(section)
Back to page
Edit source
View history
Talk (0)
Edit Page
Module:Arguments/doc
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Custom formatting of arguments === Sometimes you want to remove some blank arguments but not others, or perhaps you might want to put all of the positional arguments in lower case. To do things like this you can use the <code>valueFunc</code> option. The input to this option must be a function that takes two parameters, <code>key</code> and <code>value</code>, and returns a single value. This value is what you will get when you access the field <code>key</code> in the <code>args</code> table. Example 1: this function preserves whitespace for the first positional argument, but trims all other arguments and removes all other blank arguments. <source lang="lua"> local args = getArgs(frame, { valueFunc = function (key, value) if key == 1 then return value elseif value then value = mw.text.trim(value) if value ~= '' then return value end end return nil end }) </source> Example 2: this function removes blank arguments and converts all arguments to lower case, but doesn't trim whitespace from positional parameters. <source lang="lua"> local args = getArgs(frame, { valueFunc = function (key, value) if not value then return nil end value = mw.ustring.lower(value) if mw.ustring.find(value, '%S') then return value end return nil end }) </source> Note: the above functions will fail if passed input that is not of type <code>string</code> or <code>nil</code>. This might be the case if you use the <code>getArgs</code> function in the main function of your module, and that function is called by another Lua module. In this case, you will need to check the type of your input. This is not a problem if you are using a function specially for arguments from #invoke (i.e. you have <code>p.main</code> and <code>p._main</code> functions, or something similar). '''Examples 1 and 2 with type checking''' Example 1: <source lang="lua"> local args = getArgs(frame, { valueFunc = function (key, value) if key == 1 then return value elseif type(value) == 'string' then value = mw.text.trim(value) if value ~= '' then return value else return nil end else return value end end }) </source> Example 2: <source lang="lua"> local args = getArgs(frame, { valueFunc = function (key, value) if type(value) == 'string' then value = mw.ustring.lower(value) if mw.ustring.find(value, '%S') then return value else return nil end else return value end end }) </source> Also, please note that the <code>valueFunc</code> function is called more or less every time an argument is requested from the <code>args</code> table, so if you care about performance you should make sure you aren't doing anything inefficient with your code.
Summary:
Please note that all contributions to the Overwatch Wiki are considered to be released under the CC BY-NC-SA
Cancel
Editing help
(opens in new window)
Follow on IG
TikTok
Join Fan Lab