• 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 21: Line 21:  
local target = nil
 
local target = nil
 
local equipment = nil
 
local equipment = nil
local filterArgs = {}
  −
local sorted = false
   
local sequence = nil
 
local sequence = nil
 
local sequence_length = nil
 
local sequence_length = nil
 
local sequence_position = nil
 
local sequence_position = nil
local env = {}
+
-- local sorted = false
 +
-- local env = {}
    
local enumerating_functions = {
 
local enumerating_functions = {
Line 382: Line 381:  
local function interpret(args_)
 
local function interpret(args_)
 
args = args_
 
args = args_
 +
local filterArgs = {}
 
     for _, arg in ipairs(args) do
 
     for _, arg in ipairs(args) do
 
     local prefix = string.sub(arg, 1, 1)
 
     local prefix = string.sub(arg, 1, 1)
 
     if prefix == "~" then
 
     if prefix == "~" then
     local kv = mw.text.split(string.sub(arg, 2), "%s*~%s*")
+
    -- ~x.y.z~a.b.c means obj.x.y.z == a or obj.x.y.z == b or obj.x.y.z == c
     local xs = mw.text.split(kv[2], "%s*,%s*")
+
    -- obj.x.y.z can be obj:x():y():z(), etc.
     table.insert(filterArgs, {kv[1], xs})
+
     local ksvs = mw.text.split(string.sub(arg, 2), "%s*~%s*")
 +
     local ks = mw.text.split(ksvs[1], "%s*%.%s*")
 +
    local vs = mw.text.split(ksvs[2], "%s*,%s*")
 +
     table.insert(filterArgs, {ks, vs})
 
     end
 
     end
 
     end
 
     end
Line 407: Line 410:  
        if #filterArgs > 0 then
 
        if #filterArgs > 0 then
 
    local test = true
 
    local test = true
for _, kv in ipairs(filterArgs) do
+
for _, ksvs in ipairs(filterArgs) do
 
local test2 = false
 
local test2 = false
for _, e2 in ipairs(kv[2]) do
+
 
if tostring(ship[kv[1]](ship)) == e2 then
+
local obj = ship
 +
for _, k in ipairs(ksvs[1]) do
 +
local g = obj[k]
 +
if type(g) == 'function' then
 +
obj = g(obj)
 +
elseif type(g) == 'table' then
 +
obj = g
 +
else
 +
obj = g
 +
break
 +
end
 +
end
 +
local v1 = tostring(obj)
 +
 
 +
for _, v2 in ipairs(ksvs[2]) do
 +
if v1 == v2 then
 
test2 = true
 
test2 = true
 
break
 
break
 
end
 
end
 
end
 
end
 +
 
if not test2 then
 
if not test2 then
 
test = false
 
test = false
Line 466: Line 485:  
     until not sequence_length or sequence_position > sequence_length
 
     until not sequence_length or sequence_position > sequence_length
 
     return table.concat(values, args.concat or (args.format == "table" and "" or ", "))
 
     return table.concat(values, args.concat or (args.format == "table" and "" or ", "))
 +
end
 +
 +
local function test()
 +
mw.log(interpret({"@base_names", "~is_battleship~true", "?link", sort = "type,id"}))
 +
mw.log(interpret({"@base_names", "~class.name~Kagerou Class", "?link", sort = "type,id"}))
 
end
 
end
    
return {
 
return {
 
format = function(frame) return interpret(U.getTemplateArgs(frame).explicit) end,
 
format = function(frame) return interpret(U.getTemplateArgs(frame).explicit) end,
test = function() mw.log(interpret({"@base_names", "~is_battleship~true", "?link", sort = "type,id"})) end,
+
test = test,
 
}
 
}
cssedit, gkautomate
7,064

edits

Navigation menu