Permanently protected module
From Wikipedia, the free encyclopedia


local p = {}



--[[

Helper function that populates the argument list given that user may need to use a mix of

named and unnamed parameters.  This is relevant because named parameters are not

identical to unnamed parameters due to string trimming, and when dealing with strings

we sometimes want to either preserve or remove that whitespace depending on the application.

]]

function p.getParameters( frame_args, arg_list )

    local new_args = {};

    local index = 1;

    local value;

    

    for i,arg in ipairs( arg_list ) do

        value = frame_argsarg

        if value == nil then

            value = frame_argsindex];

            index = index + 1;

        end

        new_argsarg = value;

    end

    

    return new_args;

end        



--[[

Helper Function to interpret boolean strings

]]

function p.getBoolean( boolean_str )

    local boolean_value;

    

    if type( boolean_str ) == 'string' then

        boolean_str = boolean_str:lower();

        if boolean_str == 'false' or boolean_str == 'no' or boolean_str == '0' 

                or boolean_str == '' then

            boolean_value = false;

        else

            boolean_value = true;

        end    

    elseif type( boolean_str ) == 'boolean' then

        boolean_value = boolean_str;

    else

        error( 'No boolean value found' );

    end    

    return boolean_value

end



function p.defined(frame)

	local arg = mw.text.trim(frame.args1])

	--if arg == tostring(tonumber(arg)) then -- undesired result for '-0'

	--	arg = tonumber(arg)

	--end

	--if mw.ustring.find(arg, '^%s*-?[1-9][0-9]*%s*$') ~= nil or arg == '0' then

	--	arg = tonumber(arg)

	--end

	if mw.ustring.find(arg, '^-?[1-9][0-9]*$') ~= nil then

		arg = tonumber(arg)

	elseif arg == '0' then

		arg = 0

	end

	return frame:getParent().argsarg ~= nil

end



return p
Permanently protected module
From Wikipedia, the free encyclopedia


local p = {}



--[[

Helper function that populates the argument list given that user may need to use a mix of

named and unnamed parameters.  This is relevant because named parameters are not

identical to unnamed parameters due to string trimming, and when dealing with strings

we sometimes want to either preserve or remove that whitespace depending on the application.

]]

function p.getParameters( frame_args, arg_list )

    local new_args = {};

    local index = 1;

    local value;

    

    for i,arg in ipairs( arg_list ) do

        value = frame_argsarg

        if value == nil then

            value = frame_argsindex];

            index = index + 1;

        end

        new_argsarg = value;

    end

    

    return new_args;

end        



--[[

Helper Function to interpret boolean strings

]]

function p.getBoolean( boolean_str )

    local boolean_value;

    

    if type( boolean_str ) == 'string' then

        boolean_str = boolean_str:lower();

        if boolean_str == 'false' or boolean_str == 'no' or boolean_str == '0' 

                or boolean_str == '' then

            boolean_value = false;

        else

            boolean_value = true;

        end    

    elseif type( boolean_str ) == 'boolean' then

        boolean_value = boolean_str;

    else

        error( 'No boolean value found' );

    end    

    return boolean_value

end



function p.defined(frame)

	local arg = mw.text.trim(frame.args1])

	--if arg == tostring(tonumber(arg)) then -- undesired result for '-0'

	--	arg = tonumber(arg)

	--end

	--if mw.ustring.find(arg, '^%s*-?[1-9][0-9]*%s*$') ~= nil or arg == '0' then

	--	arg = tonumber(arg)

	--end

	if mw.ustring.find(arg, '^-?[1-9][0-9]*$') ~= nil then

		arg = tonumber(arg)

	elseif arg == '0' then

		arg = 0

	end

	return frame:getParent().argsarg ~= nil

end



return p

Videos

Youtube | Vimeo | Bing

Websites

Google | Yahoo | Bing

Encyclopedia

Google | Yahoo | Bing

Facebook