跳转到内容

模組:Chemicals

被永久保护的模块
维基百科,自由的百科全书

这是本页的一个历史版本,由A2569875留言 | 贡献2015年9月12日 (六) 08:18 (修正筆誤)编辑。这可能和当前版本存在着巨大的差异。

local p = {}
local origArgs
local error = require( 'Module:Error' )
local element= require( 'Module:Element' )

function p.formula(frame)
	-- For calling from #invoke.
	local pframe = frame:getParent()
	local args = pframe.args
	return p._formula(args)
end

function p.reaction(frame)
	-- For calling from #invoke.
	local pframe = frame:getParent()
	local args = pframe.args
	return p._reaction(args)
end

function p._formula(args)
	local body = ''
	if (args['link'] and args['link']  ~= '') then link = args['link'] end
	last=''
	for v, x in ipairs(args) do 
		number=tonumber(x)
		lastn=tonumber(last)
		if(number)then
			if((not (lastn)) and last ~= '')then
				if(link and link ~= '')then 
					body = body .. element._element_symbol({last,x})
				else
					body = body .. element._elementlink({last,x})
				end
			else if(body == '' and last == '')then
				body = x .. body 
			else if (lastn)then
				if(number==1)then
					body = body .. '<sup>+</sup>'
				else if(number==-1)then
					body = body .. '<sup>-</sup>'
				else if(number>0)then
					body = body .. '<sup>'.. number ..'+</sup>'
				else if(number<0)then
					body = body .. '<sup>'.. -number ..'-</sup>'
				end end end end
			end end end
		else
			if ((not (lastn)) and last ~= '') then
				if(link and link ~= '')then 
					body = body .. element._element_symbol({last})
				else
					body = body .. element._elementlink({last})
				end
			end
		end
		last=x
	end
	lastn=tonumber(last)
	if ((not (lastn)) and last ~= '') then
		if(link and link ~= '')then 
			body = body .. element._element_symbol({last})
		else
			body = body .. element._elementlink({last})
		end
	end
	if(link and link ~= '')then
		body = '[[' .. link .. '|' .. body ..']]'
	end
	return body
end

function p._reaction(args)
	local body = ''
	last=''
	for v, x in ipairs(args) do 
		number=tonumber(x)
		lastn=tonumber(last)
		if(number)then
			if((not (lastn)) and last ~= '')then
				if (last == '+') then
					body = body .. ' + '
				else if (last == 'eq' or last == '→') then
					body = body .. ' → '
				else if (last == 'eqm') then
					body = body .. ' [[File:Equilibrium.svg|15px|化学平衡符号]] '
				else
					body = body .. element._elementlink({last,x})
				end end end
			else if(body == '' and last == '')then
				body = x .. body 
			else if (lastn)then
				if(number==1)then
					body = body .. '<sup>+</sup>'
				else if(number==-1)then
					body = body .. '<sup>-</sup>'
				else if(number>0)then
					body = body .. '<sup>'.. number ..'+</sup>'
				else if(number<0)then
					body = body .. '<sup>'.. -number ..'-</sup>'
				end end end end
			end end end
		else
			if ((not (lastn)) and last ~= '') then
				if (last == '+') then
					body = body .. ' + '
				else if (last == 'eq' or last == '→') then
					body = body .. ' → '
				else if (last == 'eqm') then
					body = body .. ' [[File:Equilibrium.svg|15px|化学平衡符号]] '
				else
					body = body .. element._elementlink({last})
				end end end
			end
		end
		last=x
	end
	lastn=tonumber(last)
	if ((not (lastn)) and last ~= '') then
		if (last == '+') then
			body = body .. ' + '
		else if (last == 'eq' or last == '→') then
			body = body .. ' → '
		else if (last == 'eqm') then
			body = body .. ' [[File:Equilibrium.svg|15px|化学平衡符号]] '
		else
			body = body .. element._elementlink({last})
		end end end
	end
	return body
end

--本模塊的沙盒(測試)函數
function p.sandbox(frame)
	-- For calling from #invoke.
	local pframe = frame:getParent()
	local args = pframe.args
	return p._reaction(args)
end
function p._sandbox(args)
	return element_data[p.getListID(args[1])].name 
end
return p