FANDOM


(Created page with "-- Table constructor local p = {} function p.construct(frame) local res = {} local pos = 1 sep = "|-" end return p --Category:Modules")
 
Line 3: Line 3:
 
local p = {}
 
local p = {}
   
function p.construct(frame)
+
local function rowPositions(wikitable)
local res = {}
+
local positions = {}
local pos = 1
+
local index = 1
sep = "|-"
+
  +
for pos = 1, string.len(wikitable) - 1 do
  +
if string.sub(wikitable, pos, pos + 1) == "|-" then
  +
positions[index] = pos
  +
index = index + 1
  +
end
  +
end
  +
  +
positions[index] = string.len(wikitable) - 1
  +
  +
return positions
  +
end
  +
  +
function p.partial(frame)
  +
local wikitable = frame.args[1]
  +
local rows = table.getn(rowPositions(wikitable)) - 1
  +
local firstRow = math.max(frame.args[2], 1) or 1
  +
local lastRow = math.min(frame.args[3], rows) or rows
  +
local header = string.sub(wikitable, 1, rowPositions[1] - 1)
  +
local body = string.sub(
  +
wikitable, rowPositions[firstRow], rowPositions[lastRow + 1]
  +
)
  +
return header .. body .. "}"
 
end
 
end
   

Revision as of 23:34, February 8, 2020

-- Table constructor
 
local p = {}
 
local function rowPositions(wikitable)
    local positions = {}
    local index = 1
 
    for pos = 1, string.len(wikitable) - 1 do
        if string.sub(wikitable, pos, pos + 1) == "|-" then
            positions[index] = pos
            index = index + 1
        end
    end
 
    positions[index] = string.len(wikitable) - 1
 
    return positions
end
 
function p.partial(frame)
    local wikitable = frame.args[1]
    local rows = table.getn(rowPositions(wikitable)) - 1
    local firstRow = math.max(frame.args[2], 1) or 1
    local lastRow = math.min(frame.args[3], rows) or rows
    local header = string.sub(wikitable, 1, rowPositions[1] - 1)
    local body = string.sub(
        wikitable, rowPositions[firstRow], rowPositions[lastRow + 1]
        )
    return header .. body .. "}"
end
 
return p
 
--[[Category:Modules]]
Community content is available under CC-BY-SA unless otherwise noted.