<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="de">
	<id>https://wiki.onlyfumos.com/w/index.php?action=history&amp;feed=atom&amp;title=Modul%3ACommon</id>
	<title>Modul:Common - Versionsgeschichte</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.onlyfumos.com/w/index.php?action=history&amp;feed=atom&amp;title=Modul%3ACommon"/>
	<link rel="alternate" type="text/html" href="https://wiki.onlyfumos.com/w/index.php?title=Modul:Common&amp;action=history"/>
	<updated>2026-11-04T03:23:42Z</updated>
	<subtitle>Versionsgeschichte dieser Seite in Touhou Wiki</subtitle>
	<generator>MediaWiki 1.46.0</generator>
	<entry>
		<id>https://wiki.onlyfumos.com/w/index.php?title=Modul:Common&amp;diff=11281&amp;oldid=prev</id>
		<title>imported&gt;Satorioshi: Die Seite wurde neu angelegt: „--[[ Library for all the functions that are going to be shared by other scripts. To use all the functions NOT defined as local, add at the beginning of script…“</title>
		<link rel="alternate" type="text/html" href="https://wiki.onlyfumos.com/w/index.php?title=Modul:Common&amp;diff=11281&amp;oldid=prev"/>
		<updated>2016-09-01T19:39:26Z</updated>

		<summary type="html">&lt;p&gt;Die Seite wurde neu angelegt: „--[[ Library for all the functions that are going to be shared by other scripts. To use all the functions NOT defined as local, add at the beginning of script…“&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Neue Seite&lt;/b&gt;&lt;/p&gt;&lt;div&gt;--[[&lt;br /&gt;
Library for all the functions that are going to be shared by other scripts.&lt;br /&gt;
To use all the functions NOT defined as local, add at the beginning of script the following:&lt;br /&gt;
require(&amp;quot;Module:Common&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
The names aren&amp;#039;t being sorted, because this could break the function dependencies.&lt;br /&gt;
--]]&lt;br /&gt;
&lt;br /&gt;
-- create global object &amp;quot;common&amp;quot; for most of exported functions&lt;br /&gt;
local common = {}&lt;br /&gt;
&lt;br /&gt;
-- == constants ==&lt;br /&gt;
common.romanizable = {&amp;#039;zh-hans&amp;#039;, &amp;#039;zh-hant&amp;#039;, &amp;#039;zh-cn&amp;#039;, &amp;#039;zh-tw&amp;#039;, &amp;#039;zh-hk&amp;#039;, &amp;#039;zh-sg&amp;#039;, &amp;#039;zh-mo&amp;#039;, &amp;#039;zh-my&amp;#039;, &amp;#039;ja&amp;#039;, &amp;#039;ko&amp;#039;, &amp;#039;vi&amp;#039;}&lt;br /&gt;
-- Note: There&amp;#039;s a full-width space to space conversion. Don&amp;#039;t remove it!&lt;br /&gt;
common.normalization_table = {[&amp;#039;　&amp;#039;] = &amp;#039; &amp;#039;, [&amp;#039;～&amp;#039;] = &amp;#039;~&amp;#039;, [&amp;#039;！&amp;#039;] = &amp;#039;!&amp;#039;, [&amp;#039;？&amp;#039;] = &amp;#039;?&amp;#039;}&lt;br /&gt;
&lt;br /&gt;
-- == helper functions ==&lt;br /&gt;
-- checks if string is set and if it&amp;#039;s non-empty&lt;br /&gt;
function common.isset(target)&lt;br /&gt;
  return target ~= nil and target ~= &amp;quot;&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[ simulates the (a ? b : c) notation of C/C++ and PHP languages.&lt;br /&gt;
     Similar to {{#if:{{{a|}}}|{{{b|}}}|{{{c|}}}}} from parser functions. ]]&lt;br /&gt;
function common.cv(a, b, c)&lt;br /&gt;
  if a then return b else return c end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--slices a table to return another table containing values within a certain range&lt;br /&gt;
--source: http://snippets.luacode.org/snippets/Table_Slice_116&lt;br /&gt;
function common.sliceTable (values,i1,i2)&lt;br /&gt;
    local res = {}&lt;br /&gt;
    local n = #values&lt;br /&gt;
    -- default values for range&lt;br /&gt;
    i1 = i1 or 1&lt;br /&gt;
    i2 = i2 or n&lt;br /&gt;
    if i2 &amp;lt; 0 then&lt;br /&gt;
        i2 = n + i2 + 1&lt;br /&gt;
    elseif i2 &amp;gt; n then&lt;br /&gt;
        i2 = n&lt;br /&gt;
    end&lt;br /&gt;
    if i1 &amp;lt; 1 or i1 &amp;gt; n then&lt;br /&gt;
        return {}&lt;br /&gt;
    end&lt;br /&gt;
    local k = 1&lt;br /&gt;
    for i = i1,i2 do&lt;br /&gt;
        res[k] = values[i]&lt;br /&gt;
        k = k + 1&lt;br /&gt;
    end&lt;br /&gt;
    return res&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- checks if a given page exists&lt;br /&gt;
function common.exists(page)&lt;br /&gt;
  if not common.isset(page) then return false end&lt;br /&gt;
  return mw.getCurrentFrame():preprocess(&amp;#039;{{#ifexist:&amp;#039; .. page .. &amp;#039;|1|0}}&amp;#039;) == &amp;#039;1&amp;#039;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[ Tries to get contents of a page with given name.&lt;br /&gt;
     If the function fails it returns nil (page doesn&amp;#039;t exist or can&amp;#039;t be loaded)&lt;br /&gt;
     On success it returns the contents of page (it can be be partially preprocessed, so watch out for parser markers). ]]&lt;br /&gt;
function common.getPage(name)&lt;br /&gt;
  if not common.isset(name) then return nil end&lt;br /&gt;
&lt;br /&gt;
  local frame = mw.getCurrentFrame()&lt;br /&gt;
&lt;br /&gt;
  -- do a safe call to catch possible errors, like &amp;quot;template doesn&amp;#039;t exist&amp;quot;&lt;br /&gt;
  local stat,page = pcall(frame.expandTemplate, frame, {title = &amp;#039;:&amp;#039; .. name})&lt;br /&gt;
&lt;br /&gt;
  if not stat then&lt;br /&gt;
    -- TODO: &amp;#039;page&amp;#039; contains the error message. Do some debugging?&lt;br /&gt;
    return nil&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  return page&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function common.stripTags(text)&lt;br /&gt;
  if common.isset(text) then&lt;br /&gt;
    local tmp&lt;br /&gt;
    repeat&lt;br /&gt;
      tmp = text&lt;br /&gt;
      -- a pair of tags, like &amp;lt;td style=&amp;quot;&amp;quot;&amp;gt;...&amp;lt;/td&amp;gt;&lt;br /&gt;
      text = string.gsub(text, &amp;#039;&amp;lt;%s*(%w+).-&amp;gt;(.-)&amp;lt;%s*/%s*%1%s*&amp;gt;&amp;#039;, &amp;#039;%2&amp;#039;)&lt;br /&gt;
      -- closed tag, like &amp;lt;br/&amp;gt;&lt;br /&gt;
      text = string.gsub(text, &amp;#039;&amp;lt;%s*%w+%s*/%s*&amp;gt;&amp;#039;, &amp;#039;&amp;#039;)&lt;br /&gt;
    until tmp == text&lt;br /&gt;
  end&lt;br /&gt;
  return text&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[ Sort table and remove repeating elements.&lt;br /&gt;
     Since tbl is passed as reference, any changes in it will affect the passed table. ]]&lt;br /&gt;
function common.trunkTable(tbl)&lt;br /&gt;
  table.sort(tbl)&lt;br /&gt;
  local last&lt;br /&gt;
  local redo&lt;br /&gt;
  repeat&lt;br /&gt;
    redo = false&lt;br /&gt;
    last = nil&lt;br /&gt;
    for k,v in pairs(tbl) do&lt;br /&gt;
      if v ~= last then&lt;br /&gt;
        last = v&lt;br /&gt;
      else&lt;br /&gt;
        table.remove(tbl, k)&lt;br /&gt;
        redo = true&lt;br /&gt;
        break&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  until not redo&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[ Checks if a given value is among the elements of a table and returns its index.&lt;br /&gt;
      Returns nil if it can&amp;#039;t find it. ]]&lt;br /&gt;
function common.isInTable(tbl, val)&lt;br /&gt;
  for k,v in pairs(tbl) do&lt;br /&gt;
    if v == val then return k end&lt;br /&gt;
  end&lt;br /&gt;
  return nil&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[ Compare &amp;#039;n&amp;#039; elements in two tables, starting from &amp;#039;s1&amp;#039; in first table and &amp;#039;s2&amp;#039; in second table. ]]&lt;br /&gt;
function common.partialTableCompare(t1, t2, s1, s2, n)&lt;br /&gt;
  if n &amp;lt; 1 then return true end -- basically there&amp;#039;s nothing to compare, so no differences were found&lt;br /&gt;
&lt;br /&gt;
  for i = 0,(n-1) do&lt;br /&gt;
    -- Note that nil values are also valid.&lt;br /&gt;
    if t1[s1+i] ~= t2[s2+i] then return false end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  return true&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return common&lt;/div&gt;</summary>
		<author><name>imported&gt;Satorioshi</name></author>
	</entry>
</feed>