Nicht angemeldeter Benutzer - Bearbeiten von Seiten ist nur als angemeldeter Benutzer möglich.

Änderungen

Zur Navigation springen Zur Suche springen
3.052 Bytes hinzugefügt ,  13:06, 14. Dez. 2019
K
13 Versionen importiert: Vorlage:Bibrecord importieren
Zeile 1: Zeile 1: −
--[=[ 2013-05-25
+
--[=[ 2016-05-26
 
Expr
 
Expr
 
* max
 
* max
Zeile 5: Zeile 5:  
* TemplateMax
 
* TemplateMax
 
* TemplateMin
 
* TemplateMin
 +
* booland
 
]=]
 
]=]
   Zeile 17: Zeile 18:  
     ErrorExpr  = "Fehler in mathematischem Ausdruck, Funktion#Parameter"
 
     ErrorExpr  = "Fehler in mathematischem Ausdruck, Funktion#Parameter"
 
}
 
}
        Zeile 45: Zeile 45:  
     end
 
     end
 
     if not r then
 
     if not r then
         r = "(((".. say .. ")))"
+
         r = "(((" .. say .. ")))"
 
     end
 
     end
 
     return r
 
     return r
 
end -- factory()
 
end -- factory()
  −
      
local function eval( source, frame )
 
local function eval( source, frame )
Zeile 59: Zeile 57:  
     return frame:callParserFunction( "#expr", source )
 
     return frame:callParserFunction( "#expr", source )
 
end -- eval()
 
end -- eval()
        Zeile 86: Zeile 83:        +
local function base62( value )
 +
    -- Convert number from and to base62 encoding
 +
    -- Precondition:
 +
    --    value  -- number or string to be converted
 +
    --              number: to base62
 +
    --              string: base62 to number
 +
    --    Lua limitation at 10^53; larger numbers are less precise
 +
    -- Postcondition:
 +
    --    returns string, or number, or false
 +
    local r = false
 +
    local state = type( value )
 +
    if state == "number" then
 +
        local k = math.floor( value )
 +
        if k == value  and  value > 0 then
 +
            local m
 +
            r = ""
 +
            while k > 0 do
 +
                m = k % 62
 +
                k = ( k - m ) / 62
 +
                if m >= 36 then
 +
                    m = m + 61
 +
                elseif m >= 11 then
 +
                    m = m + 55
 +
                else
 +
                    m = m + 48
 +
                end
 +
                r = string.char( m ) .. r
 +
            end
 +
        elseif value == 0 then
 +
            r = "0"
 +
        end
 +
    elseif state == "string" then
 +
        if value:match( "^%w+$" ) then
 +
            local n = #value
 +
            local k = 1
 +
            local c
 +
            r = 0
 +
            for i = n, 1, -1 do
 +
                c = value:byte( i, i )
 +
                if c >= 48  and  c <= 57 then
 +
                    c = c - 48
 +
                elseif c >= 65  and  c <= 90 then
 +
                    c = c - 55
 +
                elseif c >= 97  and  c <= 122 then
 +
                    c = c - 61
 +
                else    -- How comes?
 +
                    r = nil
 +
                    break    -- for i
 +
                end
 +
                r = r + c * k
 +
                k = k * 62
 +
            end -- for i
 +
        end
 +
    end
 +
    return r
 +
end -- base62()
 +
 +
function logicaland(args)
 +
local r = true;
 +
local k, v, s
 +
local b
 +
for k, v in pairs(args) do
 +
s = mw.text.trim(v)
 +
b = (s or '') ~= ''
 +
r = r and b
 +
end
 +
    return r
 +
end
 +
 +
function logicalor(args)
 +
local r = false;
 +
local k, v, s
 +
local b
 +
for k, v in pairs(args) do
 +
s = mw.ustring.lower(mw.text.trim(v) or '');
 +
if s == '' then
 +
b = false;
 +
elseif s=='0' then
 +
b = false;
 +
elseif s=='false' then
 +
b = false;
 +
elseif s=='falsch' then
 +
b = false;
 +
elseif s=='nein' then
 +
b = false;
 +
else
 +
b = true;
 +
end
 +
if b then
 +
r = true;
 +
end
 +
end
 +
    return r
 +
end
    
local function minmax( params, frame, low, lazy  )
 
local function minmax( params, frame, low, lazy  )
Zeile 133: Zeile 224:  
             elseif scope == "number" then
 
             elseif scope == "number" then
 
                 n = v
 
                 n = v
 +
            else
 +
                n = false
 
             end
 
             end
 
             if n then
 
             if n then
Zeile 173: Zeile 266:  
-- Export
 
-- Export
 
local p = {}
 
local p = {}
 +
 +
function p.base62( frame )
 +
    local r
 +
    local s = frame.args[ 1 ]
 +
    if s then
 +
        local s2 = frame.args[ 2 ]
 +
        if s2 then
 +
            s2 = mw.text.trim( s2 )
 +
        end
 +
        if s2 == "D2B" then
 +
            s = tonumber( s )
 +
        else
 +
            s = mw.text.trim( s )
 +
            s2 = false
 +
        end
 +
        r = base62( s )
 +
        if r  and  not s2 then
 +
            r =  string.format( "%17d", r )
 +
        end
 +
    end
 +
    return r or ""
 +
end
    
function p.max( frame )
 
function p.max( frame )
Zeile 190: Zeile 305:  
function p.TemplateMin( frame )
 
function p.TemplateMin( frame )
 
     return p.min( frame:getParent() )
 
     return p.min( frame:getParent() )
 +
end
 +
 +
function p.booland(frame)
 +
local fr=frame:getParent()
 +
return logicaland(fr.args)
 +
end
 +
 +
function p.boolor(frame)
 +
local fr=frame:getParent()
 +
return logicalor(fr.args)
 
end
 
end
    
function p.Expr( f, a )
 
function p.Expr( f, a )
    local frame = mw.getCurrentFrame()
   
     local r = false
 
     local r = false
 
     if f == "min"  or  f == "max" then
 
     if f == "min"  or  f == "max" then
 +
        local frame = mw.getCurrentFrame()
 +
        local low = ( f == "min" )
 
         local lucky
 
         local lucky
        local low = ( f == "min" )
   
         lucky, r = pcall( minmax, a, frame, low, true )
 
         lucky, r = pcall( minmax, a, frame, low, true )
 +
    elseif f == "base62" then
 +
        r = base62( a )
 
     end
 
     end
 
     return r
 
     return r
Cookies helfen uns bei der Bereitstellung von imedwiki. Durch die Nutzung von imedwiki erklärst du dich damit einverstanden, dass wir Cookies speichern.

Navigationsmenü