Editing
Module:For loop
Jump to navigation
Jump to search
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!
Advanced
Special characters
Help
Heading
Level 2
Level 3
Level 4
Level 5
Format
Insert
Latin
Latin extended
IPA
Symbols
Greek
Greek extended
Cyrillic
Arabic
Arabic extended
Hebrew
Bangla
Tamil
Telugu
Sinhala
Devanagari
Gujarati
Thai
Lao
Khmer
Canadian Aboriginal
Runes
ร
รก
ร
ร
ร
รข
ร
รค
ร
รฃ
ว
ว
ฤ
ฤ
ฤ
ฤ
ฤ
ฤ
ร
รฅ
ฤ
ฤ
ฤ
ฤ
ร
รง
ฤ
ฤ
ฤ
ฤ
ฤ
ฤ
ฤ
ฤ
ร
รฉ
ร
รจ
ร
รช
ร
รซ
ฤ
ฤ
ฤ
ฤ
ฤ
ฤ
ฤ
ฤ
ฤ
ฤ
ฤ
ฤ
ฤข
ฤฃ
ฤ
ฤ
ฤ
ฤก
ฤค
ฤฅ
ฤฆ
ฤง
ร
รญ
ร
รฌ
ร
รฎ
ร
รฏ
ฤจ
ฤฉ
ว
ว
ฤช
ฤซ
ฤฌ
ฤญ
ฤฐ
ฤฑ
ฤฎ
ฤฏ
ฤด
ฤต
ฤถ
ฤท
ฤน
ฤบ
ฤป
ฤผ
ฤฝ
ฤพ
ล
ล
ล
ล
ร
รฑ
ล
ล
ล
ล
ร
รณ
ร
รฒ
ร
รด
ร
รถ
ร
รต
ว
ว
ล
ล
ล
ล
วช
วซ
ล
ล
ล
ล
ล
ล
ล
ล
ล
ล
ล
ล
ล
ล
ล
ลก
ศ
ศ
ศ
ศ
ลค
ลฅ
ร
รบ
ร
รน
ร
รป
ร
รผ
ลจ
ลฉ
ลฎ
ลฏ
ว
ว
ลช
ลซ
ว
ว
ว
ว
ลฌ
ลญ
ลฒ
ลณ
ลฐ
ลฑ
ลด
ลต
ร
รฝ
ลถ
ลท
ลธ
รฟ
ศฒ
ศณ
ลน
ลบ
ลฝ
ลพ
ลป
ลผ
ร
รฆ
วข
วฃ
ร
รธ
ล
ล
ร
ร
รฐ
ร
รพ
ฦ
ษ
Formatting
Links
Headings
Lists
Files
References
Discussion
Description
What you type
What you get
Italic
''Italic text''
Italic text
Bold
'''Bold text'''
Bold text
Bold & italic
'''''Bold & italic text'''''
Bold & italic text
-- This module implements {{for loop}}. local getArgs = require('Module:Arguments').getArgs local yesno = require('Module:Yesno') local p = {} function p.main(frame) local args = getArgs(frame, { trim = false, removeBlanks = false }) return p._main(args) end function p._main(args) local template = args['call'] or 'void' local calltemplates = yesno(args.substall or "", true) or not mw.isSubsting() local variableParam = args.pv variableParam = tonumber(variableParam) or variableParam or 1 -- fix for positional parameters local variableValPrefix = args.prefix or '' local variableValPostfix = args.postfix or '' local sep = args[1] or '' local constantArgs = p.getConstants(args) local variableVals = p.getVariableVals(args) local result = '' local addSeparator = false; for _, v in ipairs(variableVals) do v = mw.text.trim(v) if #v > 0 or not yesno(args.skipBlanks) then if addSeparator then result = result .. sep end addSeparator = true; local targs = constantArgs targs[variableParam] = variableValPrefix .. v .. variableValPostfix if calltemplates then local output = p.callTemplate(template, targs) if #mw.text.trim(output) == 0 then addSeparator = false end result = result .. output else local makeTemplate = require('Module:Template invocation').invocation result = result .. makeTemplate(template, targs) end end end return result end function p.getConstants(args) local constantArgNums = p.getArgNums(args, 'pc', 'n') local constantArgs = {} for _, num in ipairs(constantArgNums) do local keyArg = 'pc' .. tostring(num) .. 'n' local valArg = 'pc' .. tostring(num) .. 'v' local key = args[keyArg] key = tonumber(key) or key local value = args[valArg] constantArgs[key] = value end return constantArgs end function p.getVariableVals(args) local variableVals = {} if args.start or args.stop or args.by then if args[2] then error("Both start/stop/by and numbered parameters specified") end local start = tonumber(args.start or 1) local stop = tonumber(args.stop or 1) local by = tonumber(args.by or 1) for i = start, stop, by do variableVals [#variableVals + 1] = i end else for i, v in ipairs(args) do if i ~= 1 then variableVals[i - 1] = v end end end return variableVals end function p.getArgNums(args, prefix, suffix) -- Returns a table containing the numbers of the arguments that exist -- for the specified prefix and suffix. local nums = {} local pattern = '^' .. prefix .. '([1-9]%d*)' .. suffix .. '$' for k, _ in pairs(args) do local num = tostring(k):match(pattern) if num then nums[#nums + 1] = tonumber(num) end end table.sort(nums) return nums end function p.callTemplate(template, targs) return mw.getCurrentFrame():expandTemplate{title = template, args = targs} end return p
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
-- This module implements {{for loop}}.
local
getArgs
=
require
(
'Module:Arguments'
)
.
getArgs
local
yesno
=
require
(
'Module:Yesno'
)
local
p
=
{
}
function
p
.
main
(
frame
)
local
args
=
getArgs
(
frame
,
{
trim
=
false
,
removeBlanks
=
false
})
return
p
.
_main
(
args
)
end
function
p
.
_main
(
args
)
local
template
=
args
[
'call'
]
or
'void'
local
calltemplates
=
yesno
(
args
.
substall
or
""
,
true
)
or
not
mw
.
isSubsting
(
)
local
variableParam
=
args
.
pv
variableParam
=
tonumber
(
variableParam
)
or
variableParam
or
1
-- fix for positional parameters
local
variableValPrefix
=
args
.
prefix
or
''
ืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืืื
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0
0
0
1:0
Edit summary
(Briefly describe your changes)
Please note that all contributions to Chabadpedia are considered to be released under the GNU Free Documentation License 1.3 or later (see
Chabadpedia:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Debug console
* The module exports are available as the variable "p", including unsaved modifications. * Precede a line with "=" to evaluate it as an expression or use print(). Use mw.logObject() for tables. * Use mw.log() and mw.logObject() in module code to send messages to this console.
Module:For loop/doc
(
edit
)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Module
Discussion
English
Views
Read
Edit source
View history
More
Navigation
Main page
Recent changes
Random page
Tools
What links here
Related changes
Special pages
Page information