모듈:Inherit
보이기
이 모듈은 다른 문서에 끼워넣는 틀 문서 등에서 사용합니다. 위키텍스트 코드 조각에서 nowiki를 해제하고 상위 스코프에서 주어진 인자, 즉 이 모듈을 사용하는 틀이 호출될 때 함께 주어진 인자를 코드 조각의 인자로 주입합니다. 일반적인 경우에는 사용할 필요가 없지만 모듈:Curry를 사용할 때 함께 사용하는 용도입니다.
예시[원본 편집]
code_blocks 코드
{{모듈:Inherit/설명문서/예시|World}}
code
description 결과
Hello, World!
| 위 설명은 모듈:Inherit/설명문서의 내용을 가져와 보여주고 있습니다. (편집 | 역사) 이 모듈에 대한 수정 연습과 시험은 연습장 (만들기 | 미러)과 시험장 (만들기)에서 할 수 있습니다. 분류는 /설명문서에 넣어주세요. 이 모듈에 딸린 문서. |
local p = {}
local tf = require('모듈:TemplateFunction')
function argsExpression(args)
local exps = {}
for key, value in pairs(args) do
key = tonumber(key) or key
if tonumber(key) and key <= #args then
table.insert(exps, value)
else
table.insert(exps, key .. '=' .. value)
end
end
return table.concat(exps, '|')
end
function base(create, frame)
local args = {}
local comsumed = tonumber(frame.args[2]) or 0
local i = 1
for key, value in pairs(frame:getParent().args) do
if tonumber(key) == i then
key = tonumber(key) - comsumed
i = i + 1
if not tonumber(key) or key > 0 then
args[key] = value
end
end
end
args['...'] = argsExpression(args)
return create(frame.args[1]):parse(args)
end
function p.parent(frame)
return base(tf.create, frame)
end
function p.template(frame)
return base(tf.load, frame)
end
p['function'] = function(frame)
return base(tf.import, frame)
end
return p