• Welcome to the Kancolle Wiki!
  • If you have any questions regarding site content, account registration, etc., please visit the KanColle Wiki Discord

Changes

Jump to navigation Jump to search
no edit summary
Line 2: Line 2:  
local Utils = {}
 
local Utils = {}
   −
function Utils.method(frame)
+
-- * Collection functions.
local m = require("Module:" .. frame.args[1])
  −
local f = frame.args[2]
  −
local args = {}
  −
for k, v in ipairs(frame.args) do
  −
if type(k) == "number" and k >= 3 and type(v) == "string" then
  −
table.insert(args, v)
  −
end
  −
end
  −
return m[f](m, unpack(args))
  −
end
      
function Utils.find(tbl, v_, k_)
 
function Utils.find(tbl, v_, k_)
Line 52: Line 42:  
     end
 
     end
 
end
 
end
 +
 +
-- * Calling arbitrary Lua functions using #invoke.
 +
 +
-- Used to call Formatting:tooltip in Template:Tooltip, mainly because Lua code properly escapes characters,
 +
-- so that span's title attribute always works.
 +
function Utils.method(frame)
 +
local m = require("Module:" .. frame.args[1])
 +
local f = frame.args[2]
 +
local args = {}
 +
for k, v in ipairs(frame.args) do
 +
if type(k) == "number" and k >= 3 and type(v) == "string" then
 +
table.insert(args, v)
 +
end
 +
end
 +
return m[f](m, unpack(args))
 +
end
 +
 +
-- * Frame functions.
    
local getArgs = require("Module:GetArgs")
 
local getArgs = require("Module:GetArgs")
    +
-- Unused.
 
function Utils.getContext(frame)
 
function Utils.getContext(frame)
 
     local frame1 = frame:getParent()
 
     local frame1 = frame:getParent()
Line 69: Line 78:  
end
 
end
   −
function Utils.test_context(frame)
+
-- getParent -> getArgs
     local context = Utils.getContext(frame)
+
function Utils.getParentArgs(frame)
     return "arg = " .. (context.args.arg or "?") .. " @ " .. (context.pagename or "?")
+
     local frame1 = frame:getParent()
 +
    if frame1 then
 +
        return getArgs{ frame = frame1 }
 +
     else
 +
        return nil
 +
    end
 +
end
 +
 
 +
-- getArgs + getParent -> getArgs, "implicit" args can be defined in the template (e.g. pagename={{PAGENAME}})
 +
-- "explicit" args are user defined.
 +
function Utils.getTemplateArgs(frame)
 +
    local frame1 = frame:getParent()
 +
    if frame1 then
 +
        return { implicit = getArgs{ frame = frame }, explicit = getArgs{ frame = frame1 } }
 +
    else
 +
        return { implicit = getArgs{ frame = frame }, explicit = {} }
 +
    end
 
end
 
end
    
return Utils
 
return Utils
cssedit, gkautomate
7,064

edits

Navigation menu