모듈:Pipeline: 두 판 사이의 차이

리버티게임, 모두가 만들어가는 자유로운 게임
편집 요약 없음
편집 요약 없음
13번째 줄: 13번째 줄:
and tf.load(source):parse(passed)
and tf.load(source):parse(passed)
or tf.create(source):parse(passed)
or tf.create(source):parse(passed)
passed = mw.text.jsonDecode(returned:match('<includeonly ' .. passSuffixPattern .. '>(.-)</includeonly' .. passSuffixPattern.. '>'))
passed = returned:match('<includeonly ' .. passSuffixPattern .. '>(.-)</includeonly' .. passSuffixPattern.. '>')
passed = passed and mw.text.jsonDecode(passed)
returned = returned:gsub('<includeonly ' .. passSuffixPattern .. '>.-</includeonly ' .. passSuffixPattern .. '>', '')
returned = returned:gsub('<includeonly ' .. passSuffixPattern .. '>.-</includeonly ' .. passSuffixPattern .. '>', '')
end
end

2023년 11월 25일 (토) 23:09 판


모듈 설명문서[보기] [편집] [역사] [새로 고침]

이전 값에 종속되는 여러 틀을 연속적으로 실행합니다. 이를 통해 복잡한 로직을 함수형으로 구현하거나 중첩된 틀을 가독성 좋게 바꿀 수 있습니다.

사용법

code_blocks 코드
{{#invoke:Pipeline|pipe |{{#invoke:pipeline|pass|9|a=10}}11 |<nowiki>{{#expr:{{{1}}}+{{{a}}}+{{RETURNED}}}}</nowiki> }}
code
낙서장에서 확인
description 결과
수식 오류: 알 수 없는 "[" 구두점 문자입니다.

이전에 실행된 함수의 값을 RETURNED 상수를 통해 통째로 다음 함수에 넘겨줍니다. pass 함수를 활용하여 여러 값을 넘겨줄 수 있습니다.


local p = {}
local tf = require('모듈:TemplateFunction')
local passSuffix = 'pipe-passed-data'
local passSuffixPattern = 'pipe%-passed%-data'

function p.pipe(frame)
	local returned = nil
	local passed = nil
	
	for _, source in ipairs(frame.args) do
		local title = mw.title.new(source, 'Template')
		returned = title and title.exists
			and tf.load(source):parse(passed)
			or tf.create(source):parse(passed)
		passed = returned:match('<includeonly ' .. passSuffixPattern .. '>(.-)</includeonly' .. passSuffixPattern.. '>')
		passed = passed and mw.text.jsonDecode(passed)
		returned = returned:gsub('<includeonly ' .. passSuffixPattern .. '>.-</includeonly ' .. passSuffixPattern .. '>', '')
	end
	
	return returned
end

function p.pass(frame)
	return '<includeonly ' .. passSuffix .. '>'
		.. mw.text.jsonEncode(frame.args)
		.. '</includeonly ' .. passSuffix .. '>'
end

return p