League of Legends Wiki

Want to contribute to this wiki?
Sign up for an account, and get started!
You can even turn off ads in your preferences.

Come join the LoL Wiki community Discord server!

READ MORE

League of Legends Wiki
No edit summary
No edit summary
Line 8: Line 8:
 
local args; if frame.args[1] then args = frame.args else args = frame:getParent().args end
 
local args; if frame.args[1] then args = frame.args else args = frame:getParent().args end
 
local a = "4 to 5"
 
local a = "4 to 5"
return string.sub(a,1,1)
+
return string.sub(a,1,0)
 
end
 
end
   

Revision as of 22:06, 16 September 2019

Documentation for this module may be created at Module:Ability progression/doc

-- <pre>
local p = {}
local lib       = require('Module:Feature')
local col       = require('Module:color')
local userError = require('Dev:User error')

function p.test(frame)
    local args; if frame.args[1] then args = frame.args else args = frame:getParent().args end
    local a = "4 to 5"
    return string.sub(a,1,0)
end

function p.pp(frame)
    local args; if frame.args[1] then args = frame.args else args = frame:getParent().args end
        
    local temp, a, b, c, start2, end2, i
    local values, values2, values3 = "", "", ""
    local count, countstatic     = 30, 30
    local bot_fill,  top_fill      = 18, 18
    local to, to1                  = 0, 0
    
    local displayformula           = args["formula"]
    local bot_round                = args["round"]   or 2
    local top_round                = args["round1"]
    local bot_key                  = args["key"]     or ""
    local top_key                  = args["key1"]
    local bot_label                = args["label"]
    local top_label                = args["label1"]  or args["type"]
    local bot_orig                 = mw.text.split(args[1] or "", "%;")
    local top_orig                 = mw.text.split(args[2] or "", "%;")
    local _, bot_to_hits           = string.gsub(args[1] or "", "to", "")
    local _, top_to_hits           = string.gsub(args[2] or "", "to", "")
    local _, bot_x_hits            = string.gsub(args[1] or "", "x",  "")
    local _, top_x_hits            = string.gsub(args[2] or "", "x",  "")
    local lastvalue                = ""
	
    i = 1
    if bot_to_hits + bot_x_hits ~= 0 or top_to_hits + top_x_hits ~= 0 then
        while bot_orig[i] ~= nil and bot_orig[i] ~= "" do
            if (string.find(bot_orig[i], "to") ~= nil or string.find(bot_orig[i], "x") ~= nil) and string.find(bot_orig[i], "%<") == nil then
                if string.find(bot_orig[i], "x") == nil then
                    if string.find(bot_orig[i], "by") ~= nil then
                        start, finish, times = bot_orig[i]:match"(.*) *to *([^ ]*) *by *([^ ]*)"
                    else
                        start, finish, times = bot_orig[i]:match"(.*) *to *([^ ]*) *([^ ]*)"
                    end
                    if start ~= nil and finish ~= nil and pcall(expr, start .. "*2") ~= false and pcall(expr, finish .. "*2") ~= false and ((times ~= "" and times ~= nil and pcall(expr, times .. "*2") ~= false) or times == "" or times == nil) then
                        start = tonumber(expr(start))
                        finish = tonumber(expr(finish))
                        if times ~= "" and times ~= nil then
                            times = tonumber(expr(times))
                            if string.find(bot_orig[i], "by") ~= nil then
                                times = rounding((finish-start)/times+1,0)
                            end
                            bot_fill = bot_fill - times
                            if string.find(bot_orig[i], "by") ~= nil and lastvalue == start then
                                bot_fill = bot_fill + 1
                            end
                        else
                            to = 1
                        end
                        lastvalue = finish
                    else
                        bot_fill = bot_fill - 1
                    end
                else
                    useformula, times = bot_orig[i]:match"([^ ]*) *([^ ]*)"
                    if useformula ~= nil and pcall(expr, string.gsub(useformula, "x", "1") .. "*2") ~= false and ((times ~= "" and  times ~= nil and pcall(expr, times .. "*2") ~= false) or times == "" or times == nil) then
                        if times ~= "" and  times ~= nil then
                            times = tonumber(expr(times))  
                            bot_fill = bot_fill - times
                        else
                            to = 1
                        end
                    else
                        bot_fill = bot_fill - 1
                    end
                end
            else
                bot_fill = bot_fill - 1
            end
            i = i + 1
        end
    end
	
	lastvalue = ""
    i = 1
    
    if bot_to_hits + bot_x_hits ~= 0 or top_to_hits + top_x_hits ~= 0 then
        while top_orig[i] ~= nil and top_orig[i] ~= "" do
            if (string.find(top_orig[i], "to") ~= nil or string.find(top_orig[i], "x") ~= nil) and string.find(top_orig[i], "%<") == nil then
                if string.find(top_orig[i], "x") == nil then
                    if string.find(bot_orig[i], "by") ~= nil then
                        start, finish, times = top_orig[i]:match"(.*) *to *([^ ]*) *by *([^ ]*)"
                    else
                        start, finish, times = top_orig[i]:match"(.*) *to *([^ ]*) *([^ ]*)"
                    end
                    if start ~= nil and finish ~= nil and pcall(expr, start .. "*2") ~= false and pcall(expr, finish .. "*2") ~= false and ((times ~= "" and  times ~= nil and pcall(expr, times .. "*2") ~= false) or times == "" or times == nil) then
                        start = tonumber(expr(start))
                        finish = tonumber(expr(finish))
                        if times ~= "" and times ~= nil then
                            times = tonumber(expr(times))
                            if string.find(top_orig[i], "by") ~= nil then
                                times = rounding((finish-start)/times+1,0)
                            end
                            top_fill = top_fill - times
                            if string.find(top_orig[i], "by") ~= nil and lastvalue == start then
                                top_fill = top_fill + 1
                            end
                        else
                            to1 = 1
                        end
                        lastvalue = finish
                    else
                        top_fill = top_fill - 1
                    end
                else
                    useformula, times = top_orig[i]:match"([^ ]*) *([^ ]*)"
                    if useformula ~= nil and pcall(expr, string.gsub(useformula, "x", "1") .. "*2") ~= false and ((times ~= "" and  times ~= nil and pcall(expr, times .. "*2") ~= false) or times == "" or times == nil) then
                        if times ~= "" and times ~= nil then
                            times = tonumber(expr(times))  
                            top_fill = top_fill - times
                        else
                            to1 = 1
                        end
                    else
                        top_fill = top_fill - 1
                    end
                end
            else
                top_fill = top_fill - 1
            end
            i = i + 1
        end
    end
	
	
    if 18 - bot_fill >= 18 - top_fill then
        if to == 0 then
            top_fill = top_fill - bot_fill
        end
    else
        if to1 == 0 then
            bot_fill = bot_fill - top_fill
        end
    end
	
	
    if bot_fill < 0 then
        bot_fill = 0
    end
	
    if top_fill < 0 then
        top_fill = 0
    end
    
    lastvalue = ""
    i = 1
    while bot_orig[i] ~= nil and bot_orig[i] ~= "" do
        if (string.find(bot_orig[i], "to") ~= nil or string.find(bot_orig[i], "x") ~= nil) and string.find(bot_orig[i], "%<") == nil then
            bot_to_hits = 0
            _,bot_to_hits = string.gsub(bot_orig[i],"to","") 
            if string.find(bot_orig[i],"x") == nil and bot_to_hits == 1 then
                if string.find(bot_orig[i], "by") ~= nil then
                    start, finish, times = bot_orig[i]:match"(.*) *to *([^ ]*) *by *([^ ]*)"
                else
                    start, finish, times = bot_orig[i]:match"(.*) *to *([^ ]*) *([^ ]*)"
                end
                if start ~= nil and finish ~= nil and pcall(expr, start .. "*2") ~= false and pcall(expr, finish .. "*2") ~= false and ((times ~= "" and times ~= nil and pcall(expr, times .. "*2") ~= false) or times == "" or times == nil) then
                    start = tonumber(expr(start))
                    finish = tonumber(expr(finish))
                    if displayformula == nil and bot_orig[2] == nil then
                        start2 = start
                        finish2 = finish
                    end
                    if times == "" or  times == nil then
                        times = bot_fill
                        bot_fill = 0
                    else
                        times = tonumber(expr(times))
                        if string.find(bot_orig[i], "by") ~= nil then
                            times = tonumber(rounding((finish-start)/times+1,0))
                        end
                    end
                    if lastvalue == start then
                        x = 2
                        if string.find(bot_orig[i], "by") == nil then
                            times = times + 1
                        end
                    else
                        x = 1
                    end
                    lastvalue = finish
                    count = count - times
                    if count < 0 then
                        return userError("Maximum size exceeded", "LuaError")
                    end
					
					formula = start
                    scale = (finish - start) / (times - 1)
					
                    while x <= times do
                        if x ~= 1 then
                            formula = formula + scale
                        end
                        values3 = rounding(formula, bot_round)
                        if values == "" then
                            values = fd(values3)
                            values2 = values3
                        else
                            values = values .. " / " .. fd(values3)
                            values2 = values2 .. " / " .. values3
                        end
                        x = x + 1
                    end
                else
                    count = count - 1
                    if count < 0 then
                        return userError("Maximum size exceeded", "LuaError")
                    end
                    values3 = bot_orig[i]
                    if values == "" then
                        values = fd(values3)
                        values2 = values3
                    else
                        values = values .. " / " .. fd(values3)
                        values2 = values2 .. " / " .. values3
                    end
                end
            else
                local times
                local doubleto = bot_orig[i]
                if last(bot_orig[i]," ") ~= last(bot_orig[i],"to ") then
                    times = last(bot_orig[i]," ")
                    doubleto = string.sub(doubleto,1,#doubleto-#times)
                end
                
                if bot_to_hits >0 and ((times ~= "" and times ~= nil and pcall(expr, times .. "*2") ~= false) or times == "" or times == nil) then
                    local times2
                    if times == "" or times==nil then
                        times2=bot_fill
                    else
                        times2=tonumber(expr(times))  
                    end
                    doubleto = string_to_formula(doubleto,times2)
                end
                useformula = doubleto
                if useformula ~= nil and pcall(expr, string.gsub(useformula, "x", "1") .. "*2") ~= false and ((times ~= "" and times ~= nil and pcall(expr, times .. "*2") ~= false) or times == "" or times == nil) then
                    if displayformula == nil and bot_orig[2] == nil then
                        useformula2 = useformula
                    end
					if times == "" or times==nil then
                        times=bot_fill
                        bot_fill=0
                    else
                        times=tonumber(expr(times))  
                    end
                    x = 1
                    while x <= times do
                        count = count - 1
                        if count < 0 then
                            return userError("Maximum size exceeded", "LuaError")
                        end
                        formula = string.gsub(useformula, "x", x)
                        values3 = rounding(expr(formula), bot_round)
                        if values == "" then
                            values = fd(values3)
                            values2 = values3
                        else
                            values = values .. " / " .. fd(values3)
                            values2 = values2 .. " / " .. values3
                        end
                        x = x + 1
                    end
                else
                    count = count - 1
                    if count < 0 then
                        return userError("Maximum size exceeded", "LuaError")
                    end
                    values3 = bot_orig[i]
                    if values == "" then
                        values = fd(values3)
                        values2 = values3
                    else
                        values = values .. " / " .. fd(values3)
                        values2 = values2 .. " / " .. values3
                    end
                end
            end
        else
            count = count - 1
            if count < 0 then
                return userError("Maximum size exceeded", "LuaError")
            end
            if pcall(expr, bot_orig[i] .. "*2") ~= false then
                values3 = rounding(expr(bot_orig[i]), bot_round)
            else
                values3 = bot_orig[i]
            end
            if values == "" then
                values = fd(values3)
                values2 = values3
            else
                values = values .. " / " .. fd(values3)
                values2 = values2 .. " / " .. values3
            end
        end
        i = i + 1
    end
    
    local s = ""
    s = s .. '<span class="pp-tooltip2" style="position:relative; border-bottom:1px dotted; cursor:help;'
    
    if args["color"] ~= nil then
        s = s .. " color:" ..col.keyword{args["color"]} ..";"
    end
    s = s .. '"'
    
    if bot_label ~= nil then
        s = s .. ' data-label="' .. mw.ustring.gsub(bot_label, "^.", mw.ustring.upper) .. '"'
    end
    
    if top_label ~= nil then
        s = s .. ' data-label1="' .. mw.ustring.gsub(string.gsub(string.gsub(top_label, "'''", ""), "''", ""), "^.", mw.ustring.upper) .. '"'
    end
    
    if displayformula ~= nil then
        s = s .. ' data-displayformula="' .. displayformula .. '"'
    end
    
    if useformula2 ~= nil then
        s = s .. ' data-useformula="' .. useformula2 .. '"'
    end
    
    if values2 ~= nil then
        s = s .. ' data-values="' .. values2 .. '"'
    end
    
    if args[2] ~= nil then
        s = s .. ' data-values1="' .. args[2] .. '"'
    end
    
    if bot_round ~= 2 then
        s = s .. ' data-round="' .. bot_round .. '"'
    end
    
    if top_round ~= nil then
        s = s .. ' data-round1="' .. top_round .. '"'
    end
    
    if bot_key ~= "" then
        s = s .. ' data-key="' .. bot_key .. '"'
    end
    
    if top_key ~= nil then
        s = s .. ' data-key1="' .. top_key .. '"'
    end
    
    if start2 ~= nil then
        s = s .. ' data-start="' .. start2  .. '"'
        s = s .. ' data-finish="' .. finish2 .. '"'
    end
    
    if top_to_hits + top_x_hits ~= 0 or start2 ~= nil then
        s = s .. ' data-fill1="' .. top_fill .. '"'
    end
    
    s = s .. ">"
    
    if (countstatic - count > 5 and args["changedisplay"] ~= "true") or (countstatic - count <= 5 and args["changedisplay"] == "true") then
        s = s .. fd(string.sub(values2, 1, (string.find(values2, "%/") or 1)  - 2)) .. bot_key .. " &minus; " .. fd(last(values2, "%/")) .. bot_key
    else
        s = s .. values .. bot_key
    end
    
    if args["showtype"] ~= "false" then
        s = s .. " (based on " .. (args["type"] or args["top_label"] or "level") ..")" 
    end
    
    s = s .. "</span>"
     
    return s
end

function p.pptooltip(frame)
    local args; if frame.args[1] then args = frame.args else args = frame:getParent().args end

    local label = args["label"]
    local label1 = args["label1"]
    local round   = args["round"]
    local round1   = args["round1"]
    local key     = args["key"]
    local key1     = args["key1"]
    local displayformula = args["displayformula"]
    local useformula = args["useformula"]
    local fill1    = tonumber(args["fill1"])
    local count1    = 30
    local start    = tonumber(args["start"])
    local finish    = tonumber(args["finish"])
    local scale
    
    if label1 == "" then
        label1 = "Level"
    end
    
    if label == "" then
        label = "Value"
    end
    
    if tonumber(round) == nil then
        round = 2
    end
    
    if round1 == "" then
        round1 = 2
    end
    
    local orig = mw.text.split(args["values"], " %/")
    local orig1 = mw.text.split(args["values1"], "%;")
    
    local s = ""
    
    local i = 1
    local j = 1
    
    local lastvalue = ""
    while (orig1[i]~=nil and orig1[i]~="") or (orig[j]~=nil and orig[j]~="") do
        s= s .. '</th><th style="text-align: center;">'
        if orig1[1]~="" then
            if orig1[i]~=nil and orig1[i]~="" then
                if (string.find(orig1[i],"to")~=nil or string.find(orig1[i],"x")~=nil) and string.find(orig1[i],"%<")==nil then
                    local top_to_hits = 0
                    local _,top_to_hits = string.gsub(orig1[i],"to","")
                    if string.find(orig1[i],"x")==nil and top_to_hits == 1 then
                        if string.find(orig1[i], "by") ~= nil then
                            start1, finish1, times1 = orig1[i]:match"(.*) *to *([^ ]*) *by *([^ ]*)"
                        else
                            start1,finish1,times1 = orig1[i]:match"(.*) *to *([^ ]*) *([^ ]*)"
                        end
                        if start1~=nil and finish1~=nil and pcall(expr,start1.."*2")~=false and pcall(expr,finish1.."*2")~=false and ((times1 ~= "" and times1 ~= nil and pcall(expr, times1 .. "*2") ~= false) or times1 == "" or times1 == nil) then
                            start1=tonumber(expr(start1))
                            finish1=tonumber(expr(finish1))
                            if times1 == "" or times1==nil then
                                times1=fill1
                                fill1=0
                            else
                                times1=tonumber(expr(times1))
                                if string.find(orig1[i], "by") ~= nil then
                                    times1 = tonumber(rounding((finish1-start1)/times1+1,0))
                                end
                            end
                            if displayformula=="" and orig1[2]==nil then
                                start3=start1
                                finish3=finish1
                                times3=times1
                            end
                            if lastvalue == start1 then
                                x1 = 2
                                formula1 = start1
                                if string.find(orig1[i], "by") == nil then
                                    times1 = times1 + 1
                                end
                            else
                                x1 = 1
                            end
                            
                            while x1<=times1 do
                                count1=count1-1
                                if count1<0 then
                                    return userError("Maximum size exceeded", "LuaError")
                                end
                                if x1==1 then
                                    formula1=start1
                                else
                                    formula1=formula1+(finish1-start1)/(times1-1)
                                    if lastvalue == start1 and x1 == 2 then
                                    else
                                        s = s .. '</th><th style="text-align: center;">'
                                        j=j+1
                                    end
                                end
                                s = s .. fd(rounding(formula1,round1))..key1
                                x1=x1+1
                            end
                            
                            lastvalue = finish1
                        else
                            count1=count1-1
                            if count1<0 then
                                return userError("Maximum size exceeded", "LuaError")
                            end
                            s = s .. fd(orig1[i])
                        end
                    else
                        local times
                        local doubleto = orig1[i]
                        
                        if last(orig1[i]," ") ~= last(orig1[i],"to ") then
                            times1 = last(orig1[i]," ")
                            doubleto = string.sub(doubleto,1,#doubleto-#times1)
                        end
                        
                        if top_to_hits >0 and ((times1 ~= "" and times1 ~= nil and pcall(expr, times1 .. "*2") ~= false) or times1 == "" or times1 == nil) then
                            local times2
                            if times1 == "" or times1==nil then
                                times2=fill1
                            else
                                times2=tonumber(expr(times1))  
                            end
                            doubleto = string_to_formula(doubleto,times2)
                        end
                        useformula1 = doubleto
                        if useformula1~=nil and pcall(expr,string.gsub(useformula1,"x","1").."*2")~=false and ((times1 ~= "" and times1 ~= nil and pcall(expr, times1 .. "*2") ~= false) or times1 == "" or times1 == nil) then
                            if times1 == "" or times1==nil then
                                times1=fill1
                                fill1=0
                            else
                                times1=tonumber(expr(times1))  
                            end
                            x1=1
                            while x1<=times1 do
                                count1=count1-1
                                if count1<0 then
                                    return userError("Maximum size exceeded", "LuaError")
                                end
                                formula1=string.gsub(useformula1,"x",x1)
                                if x1 ~= 1 then
                                    s = s .. '</th><th style="text-align: center;">'
                                    j=j+1
                                end
                                s = s .. fd(rounding(expr(formula1),round1))..key1
                                x1=x1+1
                            end
                        else
                            count1=count1-1
                            if count1<0 then
                                return userError("Maximum size exceeded", "LuaError")
                            end
                            s = s .. fd(orig1[i])
                        end
                    end
                else
                    count1=count1-1
                    if count1<0 then
                        return userError("Maximum size exceeded", "LuaError")
                    end
                    if pcall(expr, orig1[i] .. "*2") ~= false then
                        s = s .. fd(rounding(expr(orig1[i]),round1))..key1
                    else
                        s = s .. fd(orig1[i])
                    end
                end
            end
        else
            s = s .. j
        end
        i=i+1
        j=j+1
    end
    s = s .. '</th></tr>'
    s = s .. '<tr><th style="text-align: center;">' .. label .. '</th>'
    
    i = 1
    while orig[i] ~= nil and orig[i] ~= "" do
        s = s .. '<td>'
        s = s .. fd(orig[i])
        if pcall(expr, orig[i] .. "*2") ~= false then
            s = s .. key
        end
        s = s .. '</td>'
        i = i + 1
    end
    
    s = s .. '</tr></table>'

    local formula = ""
    
    if displayformula ~= "" then
        formula = formula .. "'''Formula:''' " .. displayformula
    else
        if orig1[1] ~= "" then
            if start ~= nil and start3 ~= nil then
                scale = (finish-start) / (times3 - 1)
                scale1 = (finish3-start3) / (times3 - 1)
                formula = formula .. "'''Formula:''' "
                if start ~= 0 then
                    formula = formula .. rounding(start , round + 1) .. key
                    if scale >= 0 then
                        formula = formula .. "+"
                    end
                end
                if label1 == "Level" then
                    formula = formula .. rounding(scale, round + 1) .. key .. " every "
                    if math.abs(scale1) ~= 1 then
                        formula = formula .. rounding(scale1, round1 + 1)
                    end
                    formula = formula .. key1 .. " x"
                    if scale1 > 1 then
                        formula = formula .. "s"
                    end
                    if start3 ~= 0 and start3 ~= 1 then
                        formula = formula .. " starting from x " .. rounding(start3 , round1 + 1) .. key1 .. " and"
                    else
                        formula = formula .. ", "
                    end
                    formula = formula .. " capped at x " .. rounding(finish3 , round1 + 1) .. key1
                else
                    formula = formula .. rounding(scale, round + 1) .. key .. " every " .. rounding(scale1, round1 + 1) .. key1 .. " x "
                    if start3 ~= 0 and start3 ~= 1 then
                        formula = formula .. " starting from " .. rounding(start3 , round1 + 1) .. key1 .. " x and"
                    else
                        formula = formula .. ", "
                    end
                    formula = formula .. " capped at " .. rounding(finish3 , round1 + 1) .. key1 .. " x"
                end
            end
        else
            if start ~= nil then
                formula = formula .. "'''Formula:''' "
                scale = (finish-start) / (fill1 - 1)
                if tonumber(tostring(start)) == tonumber(tostring(scale)) then
                    formula = formula .. rounding(start , round + 1) .. key .. "&#42;x"
                else
                    formula = formula .. rounding(start-scale , round + 1) .. key
                    if scale >=0 then
                        formula = formula .. "+"
                        if scale == 1 then
                            formula = formula .. "x"
                        else
                            formula = formula .. rounding(scale , round + 1) .. key .. "&#42;x"
                        end
                    else
                        if scale == -1 then
                            formula = formula .. "-x"
                        else
                            formula = formula .. rounding(scale , round + 1) .. key .. "&#42;x"
                        end
                    end
                end
            end
            if useformula ~= "" then
                formula = formula .. "'''Formula:''' " .. useformula
            end
        end
    end
    
    if displayformula == "" then
        formula = string.gsub(string.gsub(string.gsub(string.gsub(string.gsub(string.gsub(formula,"%/"," &divide; "),"%*","&#42;"),"&#42;"," &times; "),"%+"," + "),"%-"," &minus; "),"x",label1)
    else
        formula = string.gsub(string.gsub(string.gsub(string.gsub(string.gsub(formula,"%/","&divide;"),"%*","&#42;"),"&#42;","&times;"),"%+","+"),"%-","&minus;")
    end
    
    formula = fdmulti(formula)
    local s2 = '<div class="blue-tooltip" style="padding: 10px;">' .. formula
    s2 = s2 .. '<table class="wikitable" style="text-align: center; table-layout: fixed; margin: 0;">'
    s2 = s2 .. '<tr><th style="text-align: center;">' .. label1
    
    return s2 .. s .. "</div>"
end

function p.ap(frame)
    local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
    local values=""
    local orig=args
    local count=6
    local fill
    local formula
    if args["skill"]=="R" then
        fill=3
    else
        fill=5
    end
    i=1
    local temp,a,b,c
    local round=args["round"] or nil
    while orig[i]~=nil and orig[i]~="" do
        if (string.find(orig[i],"to")~=nil or string.find(orig[i],"x")~=nil) and string.find(orig[i],"%<")==nil then
            if string.find(orig[i],"to") ~= nil then
                start=string.sub(orig[i],1,string.find(orig[i],"to")-1)
            end
            if string.find(orig[i],"x")==nil and pcall(expr,start.."*2")~=false then
                finish,times=orig[i]:match".* *to *([^ ]*) *([^ ]*)"
                if finish~=nil and pcall(expr,finish.."*2")~=false and ((times ~= "" and times ~= nil and pcall(expr, times .. "*2") ~= false) or times == "" or times == nil) then
                    start=tonumber(expr(start))
                    finish=tonumber(expr(finish))
                    if times == "" or times==nil then
                        times=fill
                        fill=0
                    else
                        times=tonumber(expr(times))  
                    end
                    count=count-times
                    if count<0 then
                        return userError("Maximum size exceeded", "LuaError")
                    end
                    x=1
                    while x<=times do
                        if x==1 then
                            formula = start
                            scale = (finish - start) / (times - 1)
                        else
                            formula = formula + scale
                        end
                        if values=="" then
                            values=fd(rounding(formula,round))
                        else
                            values=values.." / "..fd(rounding(formula,round))
                        end
                        x=x+1
                    end
                else
                    count=count-1
                    if count<0 then
                        return userError("Maximum size exceeded", "LuaError")
                    end
                    if values=="" then
                        values=fd(rounding(orig[i],round))
                    else
                        values=values.." / "..fd(rounding(orig[i],round))
                    end
                end
            else
                local times
                local doubleto = orig[i]
                if last(orig[i]," ") ~= last(orig[i],"to ") then
                    times = last(orig[i]," ")
                    doubleto = string.sub(doubleto,1,#doubleto-#times)
                end
                local _, occurences = string.gsub(orig[i], "to", "")
                if occurences >0 and ((times ~= "" and times ~= nil and pcall(expr, times .. "*2") ~= false) or times == "" or times == nil) then
                    local times2
                    if times == "" or times==nil then
                        times2=fill
                    else
                        times2=tonumber(expr(times))  
                    end
                    doubleto = string_to_formula(doubleto,times2)
                end
                useformula = doubleto
                if useformula~=nil and pcall(expr,string.gsub(useformula,"x","1").."*2")~=false and ((times ~= "" and times ~= nil and pcall(expr, times .. "*2") ~= false) or times == "" or times == nil) then
                    if times == "" or times==nil then
                        times=fill
                        fill=0
                    else
                        times=tonumber(expr(times))  
                    end
                    x=1
                    while x<=times do
                        count=count-1
                        if count<0 then
                            return userError("Maximum size exceeded", "LuaError")
                        end
                        formula=string.gsub(useformula,"x",x)
                        if values=="" then
                            values=fd(rounding(expr(formula),round))
                        else
                            values=values.." / "..fd(rounding(expr(formula),round))
                        end
                        x=x+1
                    end
                else
                    count=count-1
                    if count<0 then
                        return userError("Maximum size exceeded", "LuaError")
                    end
                    if values=="" then
                        values=fd(rounding(orig[i],round))
                    else
                        values=values.." / "..fd(rounding(orig[i],round))
                    end
                end
            end
        else
            count=count-1
            if count<0 then
                return userError("Maximum size exceeded", "LuaError")
            end
            if values=="" then
                values=fd(rounding(orig[i],round))
            else
                values=values.." / "..fd(rounding(orig[i],round))
            end
        end
        i=i+1
    end
    return values
end

function string_to_formula(args,times)
    local val = args
    while string.find(val, "to") ~= nil do
        local to = mw.text.split(val, "to")
        local _, occurences1 = string.gsub(to[1], "%(", "")
        local _, occurences2 = string.gsub(to[2], "%)", "")
        local para1 = mw.text.split(to[1], "%(")
        local para2 = mw.text.split(to[2], "%)")
        local start,finish="",""
        local times2
        local occurences3=0
        local j = occurences1 + 1 
        while j >= 2 do
            if j == occurences1+1 then
                start=para1[j]
            else
                start = "(" .. para1[j] .. start
            end
            _, times2 = string.gsub(para1[j], "%)", "")
            occurences3 = occurences3 + times2
            if occurences1 + 2 - j > occurences3 then
                break
            end
            j = j - 1
        end
        if pcall(expr, start .. "*2") == false then
            return args
        end
        occurences3=0
        j = 1
        while j <= occurences2 do
            if j == 1 then
                finish = para2[j]
            else
                finish = finish .. para2[j] .. ")"
            end
            _, times2 = string.gsub(para2[j], "%(", "")
            occurences3 = occurences3 + times2
            if j > occurences3 then
                break
            end
            j = j + 1
        end
        if pcall(expr, finish .. "*2") == false then
            return args
        end
        start = string.gsub(start,"([%-%+%*%/%^%(%)])","%%%1")
        finish = string.gsub(finish,"([%-%+%*%/%^%(%)])","%%%1")
        val = string.gsub(val, start .. "to" .. finish, "(" .. start .. ")" .. "+(" .. "(" .. finish .. ")" .. "-" .. "(" .. start .. ")" .. ")/(" .. times .. "-1)*(x-1)")
    end
    return val
end    
    
function expr(val)
    if string.find(val,"[0-9]")==nil then
        return val
    end
    local val=string.gsub(string.gsub(string.gsub(string.gsub(val," ",""),"([%/%*%+%-%^])"," %1 "),"([^%d%(%)]) %- ","%1-"),"([^%d%(%)]) %+ ","%1+")
    local i=1
    local j=1
    local a,b,switcher,switcher2,switcher3,temp
    while i>0 do
        while j>0 do
            temp=val
            if string.find(val,"%)")~=nil then
                switchertemp=mw.text.split( val, "%)")
                temp=last(switchertemp[1],"%(")
            end
            if string.find(temp," %^ ")~=nil then
                a=mw.text.split(temp," %^ ")
                b=mw.text.split(a[2]," ")
                switcher=last( a[1]," ")
                switcher2=b[1]
                switcher3=switcher^switcher2
                if string.find(switcher2,"%-")~=nil then 
                    switcher2="%-"..switcher2*(-1)
                end
                val=string.gsub(val,switcher.." %^ "..switcher2,switcher3)
                break
            end
            if string.find(temp," %/ ")~=nil then
                a=mw.text.split(temp," %/ ")
                b=mw.text.split(a[2]," ")
                switcher=last( a[1]," ")
                switcher2=b[1]
                switcher3=switcher/switcher2
                if string.find(switcher2,"%-")~=nil then 
                    switcher2="%-"..switcher2*(-1)
                end
                val=string.gsub(val,switcher.." %/ "..switcher2,switcher3)
                break
            end
            if string.find(temp," %* ")~=nil then
                a=mw.text.split( temp," %* ")
                b=mw.text.split(a[2]," ")
                switcher=last( a[1]," ")
                switcher2=b[1]
                switcher3=switcher*switcher2
                if string.find(switcher2,"%-")~=nil then 
                    switcher2="%-"..switcher2*(-1)
                end
                val=string.gsub(val,switcher.." %* "..switcher2,switcher3)
                break
            end
           if string.find(temp," %- ")~=nil then
                a=mw.text.split( temp," %- ")
                b=mw.text.split(a[2]," ")
                switcher=last( a[1]," ")
                switcher2=b[1]
                if switcher=="" then
                    if string.find(switcher2,"%-")~=nil then 
                        switcher2="%-"..switcher2*(-1)
                    end
                    val=string.gsub(val," %- "..switcher2,"%-"..switcher2)
                    break  
                else
                    switcher3=switcher-switcher2
                    if string.find(switcher2,"%-")~=nil then 
                        switcher2="%-"..switcher2*(-1)
                    end
                    val=string.gsub(val,switcher.." %- "..switcher2,switcher3)
                    break
                end
            end
            if string.find(temp," %+ ")~=nil then
                a=mw.text.split( temp," %+ ")
                b=mw.text.split(a[2]," ")
                switcher=last( a[1]," ")
                switcher2=b[1]
                if switcher=="" then
                    if string.find(switcher2,"%-")~=nil then 
                        switcher2="%-"..switcher2*(-1)
                    end
                    val=string.gsub(val," %+ "..switcher2,switcher2)
                    break  
                else
                    switcher3=switcher+switcher2
                    if string.find(switcher2,"%-")~=nil then 
                        switcher2="%-"..switcher2*(-1)
                    end
                    val=string.gsub(val,switcher.." %+ "..switcher2,switcher3)
                    break
                end
            end
            if string.find(val,"%)")~=nil and string.find(val,"%(")~=nil then
                if string.find(temp,"%-")~=nil then 
                    temp="%-"..temp*(-1)
                end
                val=string.gsub(val,"%("..temp.."%)",temp)
                break
            else
                i=0
            end
            break
        end
    end
    return temp
end

function last(val,sign)
    local a=mw.text.split(val,sign)
    local j=1
    while j>0 do
        if a[j] ~=nil then
            j=j+1
        else
        break
        end
    end
    return a[j-1]
end

function fd(val)
    if string.find(val,"[0-9]") == nil or string.find(val,"%.") == nil then
        return val
    end
    local a,b,c
    if string.find(val,"span") ~= nil then
        a,b,c = val:match"([^.]*).(.*)</span>(.*)"
        if string.find(val,"span")<=string.find(val,"%.") then
            return a .. ".<small>" .. b .. "</small></span>" .. c
        else
            return a .. ".<small>" .. b .. "</span></small>" .. c
        end
    else
        a,b,c = val:match"([^.]*).([0-9]*)(.*)"
        return a .. ".<small>" .. b .. "</small>" .. c
    end
end

function fdmulti(val)
    if string.find(val,"[0-9]") == nil or string.find(val,"%.") == nil then
        return val
    end
    
    local val    = mw.text.split(val,"%.")
    local values = val[1]
    local i      = 2
    local b,c
    
    while val[i] ~= nil do
        if string.find(val[i],"span") ~= nil then
            b,c    = val[i]:match"(.*)</span>(.*)"
            if string.find(tostring(b),"[0-9]")==nil then
                values=values.."."..val[i]
            else
                if string.find(val[i],"span")<=string.find(val[i],"%.") then
                    values = values .. ".<small>" .. b .. "</small></span>" .. c
                else
                    values = values .. ".<small>" .. b .. "</span></small>" .. c
                end
            end
        else
            b,c    = val[i]:match"([0-9]*)(.*)"
            if string.find(tostring(b),"[0-9]")==nil then
                values=values.."."..val[i]
            else
                values = values .. ".<small>" .. b .. "</small>" .. c
            end
        end
        i = i + 1
    end
    
    return values
end

function rounding(val, decimals)
    local round
    local val = tostring(val)
    if decimals == nil or string.find(val,"[0-9]") == nil or string.find(val,"<span") ~= nil or string.find(val,"%.") == nil then
        return val
    end
    local a,b,c,d
        a,b,c,d = val:match"([^0-9]*)([0-9]*).([0-9]*)(.*)"
    val=tonumber(b.."."..c)
    if decimals == "abs" then
        round = math.abs(val)
    end
    if decimals == "floor" then
        round = math.floor(val)
    end
    if decimals == "ceil" then
        round = math.ceil(val)
    end
    if decimals == "trunc" then
        round = string.sub(val,1,(string.find(val,"%.") or 0) - 1)
    end
    if round == nil then
        local mult = 10^(decimals)
        round = math.floor(val * mult + 0.5) / mult
    end
    return a..round..d
end

return p

-- </pre>
--[[Category:Lua]]