Module:Sandbox

From Nookipedia, the Animal Crossing wiki
Revision as of 12:13, July 6, 2022 by PanchamBro (talk | contribs)

Module documentation (view)


Usage

This is the general sandbox page to test out Lua modules. The module should not be implemented in a template.


local p = {}

local function getArgs(frame)
    local args = {}
    for key, value in pairs(frame:getParent().args) do
        args[key] = value
    end
    for key, value in pairs(frame.args) do
        args[key] = value
    end
    return args
end

function p.main(frame)
    local args      = getArgs(frame)
    local num1      = args[1] or args.num1 or ''
    local num2      = args[2] or args.num2 or ''
    local num3      = args[3] or args.num3 or ''
    return p.calc(num1, num2, num3)
end

function p.calc(num1, num2, num3)
	local finalNum
	local a = tonumber(num1)
	local b = tonumber(num2)
	local c = tonumber(num3)
	finalNum = a + b + c
	return finalNum
end

return p