모듈:Br separated entries

198.188.4.4 (토론)님의 2017년 10월 12일 (목) 10:27 판 (새 문서: local p = {} local function _main( args ) local sep = '<br />' local lastsep local t = {} for i, v in ipairs( args ) do table.insert( t, v ) if mw.ust...)
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

local p = {}

local function _main( args ) local sep = '
'local lastseplocal t = {}for i, v in ipairs( args ) dotable.insert( t, v )if mw.ustring.match( v, '%S' ) thentable.insert( t, sep )lastsep = #t end endif lastsep thentable.remove( t, lastsep ) endreturn table.concat( t ) end

function p.main( frame ) local origArgsif frame == mw.getCurrentFrame() then-- We're being called via #invoke. If the invoking template passed any arguments,-- use them. Otherwise, use the arguments that were passed into the template.origArgs = frame:getParent().argsfor k, v in pairs( frame.args ) doorigArgs = frame.argsbreak end else -- We're being called from another module or from the debug console, so assume-- the arguments are passed in directly.origArgs = frame end-- Use integer args only, and allow for explicit positional arguments-- that are specified out of order, e.g. 틀:Br separated entries.-- After processing, the args can be accessed accurately from ipairs.local args = {}for k, v in pairs( origArgs ) doif type( k ) == 'number' and k >= 1 and math.floor( k ) == k thentable.insert( args, k ) end endtable.sort( args )for i,v in ipairs( args ) doargs[ i ] = origArgs[ v ] endreturn _main( args ) end

return p