본문으로 이동
  • 토론란발전소에서 진행되는 토의에 많은 참여 바랍니다.
  • 2024년 2월 16일부로 TemplateSandbox 확장 기능을 설치하였습니다. 문제가 발생하면 오락실로 제보 바랍니다.

모듈:LCGI

리버티게임, 모두가 만들어가는 자유로운 게임
Hsl0 (토론 | 기여)님의 2024년 2월 12일 (월) 12:41 판
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

이 모듈에 대한 설명문서는 모듈:LCGI/설명문서에서 만들 수 있습니다

local p = {}
local tf = require('모듈:TemplateFunction')
local mergerule = {
	inject = assign,
	forward = assign,
	private = push
}

function push(target, ...)
	for newtbl in ipairs(...) do
		if newtbl then
			for value in ipairs(newtbl) do
				table.insert(target, value)
			end
		end
	end
	return target
end

function assign(target, ...)
	for newtbl in ipairs(...) do
		if newtbl then
			for key, value in pairs(newtbl) do
				target[key] = value
			end
		end
	end
	return target
end

function p.scope(frame)
	local source = frame.args[1]
	local rawconfig = mw.text.jsonDecode('[' .. frame.args[2]:sub(1, -2) .. ']')
	local config = {}
	local rendered = ''
	
	for _, payload in ipairs(rawconfig) do
		local key = table.remove(payload, 1)
		if config[key] == nil then
			config[key] = {}
		end
		mergerule[key](config[key], payload[1])
	end
	
	rendered = tf.create(source):curry(config.inject)
	
	if config.private then
		rendered = rendered:finalize(config.private).source
	else
		rendered = rendered:forward(config.forward).source
	end
	
	return mw.html.create('span')
		:attr('data-raw', source)
		:attr('data-config', mw.jsonEncode(config))
		:wikitext(rendered)
		:done()
end

return p