Modulo:mmulnam

El Vikivortaro
 MODULO
Memtesto ne disponeblas.

--[===[

MODULE "MMULNAM" (multiple name)

"eo.wiktionary.org/wiki/Modulo:mmulnam" <!--2020-Nov-08-->
"id.wiktionary.org/wiki/Modul:mmulnam"

Purpose: shows multiple names of a language as links to lemma pages

Utilo: montras plurajn nomojn de lingvo kiel ligiloj al kapvortaj pagxoj

Manfaat: menampilkan beberapa ...

Syfte: visar flera ...

Used by templates / Uzata far sxablonoj:
- "mulnam" only

Required submodules / Bezonataj submoduloj:
- none / neniuj

This module can take parameters both those sent to itself
(own frame) and those sent to the caller (caller's frame).

Incoming: - one anonymous obligatory parameter type ("E" or "P" or "A")
          - further 2...10 anonymous parameters (2...48 octet:s each)

Returned: - text with wikicode (to be dropped on a line beginnig with "*")

Special trick: if there is a parameter "caller=true" on the own frame then
               that own frame is discarded in favor of the caller's one.

This module is unbreakable (when called with correct module
name and function name).

Cxi tiu modulo estas nerompebla (kiam vokita kun gxustaj nomo de
modulo kaj nomo de funkcio).

]===]

local mulnam = {}

------------------------------------------------------------------------

---- CONSTANTS ----

------------------------------------------------------------------------

  -- constant strings (generic & misc)

  local constrkros  = '&nbsp;#&nbsp;#&nbsp;'       -- lagom -> huge circumfix
  local constrelabg = '<span class="error"><b>'    -- lagom whining begin
  local constrelaen = '</b></span>'                -- lagom whining end

  -- HTML stuff for our tiny frames

  local constrtabu3  = '<table style="display:inline-block; vertical-align:middle; margin:0.1em; padding:0; border:0.05em solid #000000;"><tr><td>'
  local constrtabu5  = '</td></tr></table>'

  -- uncommentable constant strings EO vs ID

  local contblliteroj = {}
  contblliteroj = {'E','P','A'}                           -- EO (index 1...3)

  local contblpriskribo = {}
  contblpriskribo = {'esperante','propralingve','angle'}  -- EO (index 1...3)

  local constrer0 = "nevalida kvanto da nomoj"            -- EO
  -- local constrer0 = "jumlah nama tidak sah"               -- ID

------------------------------------------------------------------------

---- MAIN EXPORTED FUNCTION ----

------------------------------------------------------------------------

function mulnam.ek (arxframent)

  -- general unknown type

  local vartmp = 0     -- variable without type

  -- special type "args" AKA "arx"

  local arxsomons = 0  -- metaized "args" from our own or caller's "frame"

  -- general "tab"

  local tabarx2t10 = {}

  -- general "str"

  local strtpm        = ""
  local strret        = ""  -- final output string
  local strpriskribo  = ""  -- picked from "contblpriskribo"

  -- general "num"

  local numlong   = 0  -- length
  local numamop   = 0  -- amount of extra parameters (2...10)
  local numindx   = 0

  -- general "boo"

  local boocrap   = false
  local boocryd   = false

  ---- GUARD AGAINST INTERNAL ERROR ----

  -- "contblliteroj" and "contblpriskribo" must be uncommented and assigned

  -- note that reporting of this error may NOT depend of uncommentable strings

  if ((type(contblliteroj[1])~="string") or (type(contblpriskribo[1])~="string")) then
    boocrap = true
  end--if

  ---- WHINE IF YOU MUST ABOUT INTERNAL ERROR ----

  -- note that reporting of this error may NOT depend of uncommentable strings

  if (boocrap) then
    strtpm = 'FATAL in "mmulnam" : internal error'
    strret = constrkros .. constrelabg .. strtpm .. constrelaen .. constrkros
    boocryd = true
  end--if

  ---- GET THE ARX (ONE OF TWO) ----

  if (boocrap==false) then
    arxsomons = arxframent.args -- "args" from our own "frame"
    vartmp = arxsomons ["caller"]
    if (vartmp=="true") then
      arxsomons = arxframent:getParent().args -- "args" from caller's "frame"
    end--if
  end--if

  ---- SEIZE 1 OBLIGATORY ANONYMOUS PARAMETER ----

  if (boocrap==false) then
    strpriskribo = "" -- preassign to empty
    vartmp = arxsomons[1]
    if (type(vartmp)=="string") then
      if (string.len(vartmp)==1) then
        if (vartmp==contblliteroj[1]) then
          strpriskribo = contblpriskribo[1]
        end--if
        if (vartmp==contblliteroj[2]) then
          strpriskribo = contblpriskribo[2]
        end--if
        if (vartmp==contblliteroj[3]) then
          strpriskribo = contblpriskribo[3]
        end--if
      end--if (string.len(vartmp)==1) then
    end--if
    if (strpriskribo=="") then
      boocrap = true -- missing or invalid parameter
    end--if
  end--if

  ---- WHINE IF YOU MUST ----

  if ((boocrap) and (boocryd==false)) then
    strtpm = 'FATAL in "mmulnam" : bad or missing obligatory parameter'
    strret = constrkros .. constrelabg .. strtpm .. constrelaen .. constrkros
    boocryd = true
  end--if

  ---- SEIZE 2...10 EXTRA ANONYMOUS PARAMETERS ----

  if (boocrap==false) then
    numamop = 0 -- here ZERO-based index
    while (true) do
      if (numamop==11) then
        break -- this is baad
      end--if
      vartmp = arxsomons[numamop+2] -- OFF-by-TWO here
      if (type(vartmp)~="string") then
        break -- this is good or baad
      end--if
      strtpm = vartmp
      numlong = (string.len(strtpm))
      if ((numlong<2) or (numlong>48)) then
        boocrap = true -- invalid extra parameter
        break
      end--if
      tabarx2t10[numamop] = strtpm -- ZERO-based
      numamop = numamop + 1
    end--while
    if ((numamop<2) or (numamop>10)) then
      boocrap = true -- invalid amount of extra parameters
    end--if
  end--if

  ---- WHINE IF YOU MUST #0 ----

  if ((boocrap) and (boocryd==false)) then
    strret = constrkros .. constrelabg .. constrer0 .. constrelaen .. constrkros
  end--if

  ---- MAIN LOOP ----

  -- generate the string with 2...10 links

  if (boocrap==false) then
    strret = '<small>(' .. strpriskribo .. ')</small>&nbsp;'
    numindx = 0
    while (true) do
      if (numindx==numamop) then
        break -- done
      end--if
      if (numindx~=0) then
        strret = strret .. ", "
      end--if
      strret = strret .. constrtabu3 .. "[[" .. tabarx2t10[numindx] .. "]]" .. constrtabu5
      numindx = numindx  + 1 -- ZERO-based
    end--while
  end--if

  ---- RETURN THE JUNK STRING ----

  return strret

end--function

  ---- RETURN THE JUNK LUA TABLE ----

return mulnam