InformationEdit

Uses Module:Arguments and Module:Yesno.

UsageEdit

{{#invoke:Sandbox|function_name|args}}

, where function_name is "f" followed by a natural number (N) and args is a pipe-separated list of arguments.

N = 1Edit

Gets the length, in characters, of the first argument.

N = 2Edit

Counts its arguments.

N = 3Edit

Performs the operation specified by the first argument in the remaining arguments.

Available operations: "+", "-", "*", "/", "%", "!" (boolean NOT).



--[[This is a test created by Luis150902]]

local test = {}
local getArgs = require("Module:Arguments").getArgs
local yesno = require("Module:Yesno")

function test.f1(frame)
	local args = getArgs(frame)
	return mw.ustring.len(args["1"])
end

function test.f2(frame)
	local args = getArgs(frame)
	local i = 0
	for j in args do
		i = i + 1
	end
	return i
end

function test.f3(frame)
	local args = getArgs(frame)
	local op = args["1"]
	if (op == nil) or (op == "{{{1}}}") or (op == "") then
	  op = args["s"]
	  if (op == nil) or (op == "{{{1}}}") or (op == "") then
	    return 0
	  end
	end
	if (op == "+") then
		return test._f3_0(args)
	end
	if (op == "-") then
		return test._f3_1(args)
	end
	if (op == "*") then
		return test._f3_2(args)
	end
	if (op == "/") then
		return test._f3_3(args)
	end
	if (op == "%") then
		return test._f3_4(args)
	end
	if (op == "!") then
		return test._f3_5(args)
	end
end

function test._f3_0(args)
	local a = args["2"]
	if (a == nil) or (a == "{{{2}}}") or (a == "") then
		a = args["a"]
		if (a == nil) or (a == "{{{2}}}") or (a == "") then
			return 0
		end
	end
    local b = args["3"]
    if (b == nil) or (b == "{{{3}}}") or (b == "") then
    	a = args["b"]
    	if (b == nil) or (b == "{{{3}}}") or (b == "") then
    		return 0
    	end
    end
    return a + b
end

function test._f3_1(args)
	local a = args["2"]
	if (a == nil) or (a == "{{{2}}}") or (a == "") then
		a = args["a"]
		if (a == nil) or (a == "{{{2}}}") or (a == "") then
			return 0
		end
	end
    local b = args["3"]
    if (b == nil) or (b == "{{{3}}}") or (b == "") then
    	a = args["b"]
    	if (b == nil) or (b == "{{{3}}}") or (b == "") then
    		return 0
    	end
    end
    return a - b
end

function test._f3_2(args)
	local a = args["2"]
	if (a == nil) or (a == "{{{2}}}") or (a == "") then
		a = args["a"]
		if (a == nil) or (a == "{{{2}}}") or (a == "") then
			return 0
		end
	end
    local b = args["3"]
    if (b == nil) or (b == "{{{3}}}") or (b == "") then
    	a = args["b"]
    	if (b == nil) or (b == "{{{3}}}") or (b == "") then
    		return 0
    	end
	end
    return a * b
end

function test._f3_3(args)
	local a = args["2"]
	if (a == nil) or (a == "{{{2}}}") or (a == "") then
		a = args["a"]
		if (a == nil) or (a == "{{{2}}}") or (a == "") then
			return 0
		end
	end
    local b = args["3"]
    if (b == nil) or (b == "{{{3}}}") or (b == "") then
    	a = args["b"]
    	if (b == nil) or (b == "{{{3}}}") or (b == "") then
    		return 0
    	end
	end
	return a / b
end

function test._f3_4(args)
	local a = args["2"]
	if (a == nil) or (a == "{{{2}}}") or (a == "") then
		a = args["a"]
		if (a == nil) or (a == "{{{2}}}") or (a == "") then
			return 0
		end
	end
    local b = args["3"]
    if (b == nil) or (b == "{{{3}}}") or (b == "") then
    	a = args["b"]
    	if (b == nil) or (b == "{{{3}}}") or (b == "") then
    		return 0
    	end
    end
	return a % b
end

function test._f3_5(args)
	local a = args["2"]
	if (a == nil) or (a == "{{{2}}}") or (a == "") then
		a = args["a"]
		if (a == nil) or (a == "{{{2}}}") or (a == "") then
			return 0
		end
	end
    local result = yesno(a)
    if result then
        return "false"
    else
    	return "true"
    end
end

return test