此处公告通常对读者进行申明或对该WIKI某些规则进行公告,请在确认后修改本通告。本WIKI编辑权限开放,欢迎收藏起来防止迷路,也希望有爱的小伙伴和我们一起编辑哟~

全站通知:

模块:Voice actor

来自尘白禁区WIKI_BWIKI_哔哩哔哩
跳到导航 跳到搜索

此模块的文档可以在模块:Voice actor/doc创建

------
-- Module:Voice actor
------
local p = {}
local getArgs = require('Module:Arguments').getArgs

-- String.split(string, key)
function split(s, k)
  local rt = {}
  string.gsub(
    s,
    '[^' .. k .. ']+',
    function(w)
      table.insert(rt, w)
    end
  )
  return rt
end

-- String.trim(string)
function trim(s)
  return (s:gsub('^%s*(.-)%s*$', '%1'))
end

-- Make link for voice actor
function makeLink(actorName, displayName)
  local text = ''
  actorName = trim(actorName)
  displayName = trim(displayName) or actorName
  text = text .. '[[Category:配音演员:' .. actorName .. ']]'
  text = text .. '[[:Category:配音演员:' .. actorName .. '|' .. displayName .. ']]'
  return text
end

-- Main function
function p.main(frame)
  local args = getArgs(frame)

  -- Nil
  if args[1] == nil then
    return '[[:Category:配音演员|配音演员]]'
  end

  -- Create empty variable
  local text = {}

  -- Get all actors
  local allActors = split(args[1], ',')

  -- Loop
  for _, actor in pairs(allActors) do
    local parts = split(actor, '|')
    local actorName = parts[1]
    local displayName = parts[2] or actorName
    table.insert(text, makeLink(actorName, displayName))
  end

  -- Concat the table
  text = table.concat(text, '<br>')

  return text
end

-- end
return p