Jump to content

Module:User:Mr rnddude/Sandbox

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Mr rnddude (talk | contribs) at 14:22, 17 April 2017 (So, first a simple addition and two simple multiplication functions for some practice). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
-- This is my module sandbox.
-- The below is simplistic practice for
-- working out how to write simpler modules.
-- My first foray into modules was overly
-- complex. Successful, but, complex.

local p = {}

function p.add (frame) -- simple addition
	local num1 = tonumber(frame.args[1])
	local num2 = tonumber(frame.args[2])
	return num1 + num2
end

function p.multiply (frame) -- similarly, simple multiplication
	local num1 = tonumber(frame.args[1])
	local num2 = tonumber(frame.args[2])
	return num1 * num2
end

function p.secondlaw (frame) -- Newton's second law of motion
	local num1 = tonumber(frame.args[1])
	local num2 = tonumber(frame.args[2])
	return 'Force =' .. num1 * num2
end