模組:Infobox element isotopes/sandbox
外观
![]() | 这是Module:Infobox element isotopes(差异)的沙盒。 |
local p = {}
local other_wiki_link_module = require('Module:Ilh')
function p.main(frame)
if not getArgs then
getArgs = require('Module:Arguments').getArgs
end
args = getArgs(frame, {parentFirst=true})
return p._gen_table(arg)
end
function p.gen_table(frame)
-- For calling from #invoke.
local pframe = frame:getParent()
args = {}
for k, v in pairs( frame.args ) do
args[k] = v;
end
return p._gen_table(args)
end
function p._gen_table(args)
local body = ''
decay_list = p.get_decay_list(args)
iso_link = "化學元素"
iso_symbol = "X"
iso_mass = ''
iso_na = ''
iso_halflife = ' -'--
count = 0
for _ in pairs(decay_list) do count = count + 1 end
if args['mn'] ~= nil then
iso_mass = args['mn']
end
if args['sym'] ~= nil then
iso_symbol = args['sym']
end
if args['link'] ~= nil then
iso_link = args['link']
end
if args['na'] ~= nil then
iso_na = args['na']
end
if args['halflife'] ~= nil then
iso_halflife = args['halflife']
end
if args['hl'] ~= nil then
iso_halflife = args['hl']
end
iso_link_data = "[[" .. iso_link .. "|<sup>" .. iso_mass .. "</sup>" .. iso_symbol .."]]"
if args['tsl'] ~= nil and args['lang'] ~= nil and args['link'] ~= nil then
--construct ilh args
ilh_args = {}
ilh_args['lang'] = args['lang']
ilh_args['lang-code'] = args['lang']
ilh_args[1] = args['link']
ilh_args[2] = args['tsl']
ilh_args['d'] = "<sup>" .. iso_mass .. "</sup>" .. iso_symbol
iso_link_data = other_wiki_link_module.main(ilh_args)
end
checkna = mw.ustring.find(iso_na, "%%$", 1, false)
if checkna == nil then checkna = 0 end
rowspan = 1
if count > 1 then rowspan = count end
body = body .. "\n|-\n! rowspan=\"" .. rowspan .. "\" style=\"text-align:right; vertical-align:middle;\" | " .. iso_link_data
body = body .. "\n| rowspan=\"" .. rowspan .. "\" style=\""
if checkna > 0 then
body = body .. "text-align:right"
else
body = body .. "text-align:center"
end
body = body .. "; vertical-align:middle;\" | " .. iso_na
body = body .. "\n| rowspan=\"" .. rowspan .. "\" style=\"text-align:right; vertical-align:middle;\" | " .. iso_halflife
if count <= 0 then
body = body .. "\n| colspan=\"3\" style=\"text-align:left;\" | \"[[觀測上穩定的同位素|觀測上穩定]]"
else
i = 1
for decay_id, decay_value in pairs(decay_list) do
if decay_value.mode == nil then decay_value.mode = ' -' end
body = body .. "\n| |" .. decay_value.mode .. "\n| style=\"text-align:right;\" | "
mass = ''
if decay_value.mass ~= nil then
mass = decay_value.mass
end
symbol = 'X'
if decay_value.symbol ~= nil then
symbol = decay_value.symbol
end
if decay_value.link ~= nil then
if decay_value.otherwiki ~= nil and decay_value.lang_code ~= nil then
--construct ilh args
ilh_args = {}
ilh_args['lang'] = decay_value.lang_code
ilh_args['lang-code'] = decay_value.lang_code
ilh_args[1] = decay_value.link
ilh_args[2] = decay_value.otherwiki
ilh_args['d'] = "<sup>" .. mass .. "</sup>" .. symbol
body = body .. other_wiki_link_module.main(ilh_args)
else
body = body .. "[[" .. decay_value.link .. "|<sup>" .. mass .. "</sup>" .. symbol .."]]"
end
else
body = body .. "<sup>" .. mass .. "</sup>" .. symbol
end
body = body .. "\n|-"
i = i + 1
end
end
return body
end
function p.get_decay_list(args)
decay_list = {}
for arg_name, arg_value in pairs(args) do
if arg_value ~= '' then
match_dm = mw.ustring.match(arg_name, "dm%d+")
match_energy = mw.ustring.match(arg_name, "de%d+")
match_halflife = mw.ustring.match(arg_name, "halflife%d+")
match_halflife2 = mw.ustring.match(arg_name, "hl%d+")
match_link = mw.ustring.match(arg_name, "link%d+")
match_link_otherwiki = mw.ustring.match(arg_name, "tsl%d+")
match_link_otherwiki_id = mw.ustring.match(arg_name, "lang%d+")
match_link_product_symbol = mw.ustring.match(arg_name, "ps%d+")
match_link_product_mass = mw.ustring.match(arg_name, "pn%d+")
if match_dm ~= nil then
decay_id = mw.ustring.sub(arg_name, 3, -1)
if decay_list[decay_id] == nil then decay_list[decay_id] = { check = decay_id } end
decay_list[decay_id].mode = arg_value
elseif match_energy ~= nil then
decay_id = mw.ustring.sub(arg_name, 3, -1)
if decay_list[decay_id] == nil then decay_list[decay_id] = { check = decay_id } end
decay_list[decay_id].energy = arg_value
elseif match_halflife ~= nil then
decay_id = mw.ustring.sub(arg_name, 9, -1)
if decay_list[decay_id] == nil then decay_list[decay_id] = { check = decay_id } end
decay_list[decay_id].halflife = arg_value
elseif match_halflife2 ~= nil then
decay_id = mw.ustring.sub(arg_name, 3, -1)
if decay_list[decay_id] == nil then decay_list[decay_id] = { check = decay_id } end
decay_list[decay_id].halflife = arg_value
elseif match_link ~= nil then
decay_id = mw.ustring.sub(arg_name, 5, -1)
if decay_list[decay_id] == nil then decay_list[decay_id] = { check = decay_id } end
decay_list[decay_id].link = arg_value
elseif match_link_otherwiki_id ~= nil then
decay_id = mw.ustring.sub(arg_name, 5, -1)
if decay_list[decay_id] == nil then decay_list[decay_id] = { check = decay_id } end
decay_list[decay_id].lang_code = arg_value
elseif match_link_otherwiki ~= nil then
decay_id = mw.ustring.sub(arg_name, 4, -1)
if decay_list[decay_id] == nil then decay_list[decay_id] = { check = decay_id } end
decay_list[decay_id].otherwiki = arg_value
elseif match_link_product_symbol~= nil then
decay_id = mw.ustring.sub(arg_name, 3, -1)
if decay_list[decay_id] == nil then decay_list[decay_id] = { check = decay_id } end
decay_list[decay_id].symbol = arg_value
elseif match_link_product_mass~= nil then
decay_id = mw.ustring.sub(arg_name, 3, -1)
if decay_list[decay_id] == nil then decay_list[decay_id] = { check = decay_id } end
decay_list[decay_id].mass = arg_value
end
end
end
return decay_list
end
return p