Module:Scribunto demo

From Notaclue Wiki

-- Example scribunto module
-- This shown a series of increasing complex uses for scribunto modules
-- The functions are all stored in a single object, `p` (for package) that is
-- returned by this file

local p = {}

-- Basic example: printing hello world
-- Usage: {{#invoke:Scribunto demo|hello}}
function p.hello( frame )
    return "Hello, world!"
end

-- Example: printing hello using given frame argument
-- Usage: {{#invoke:Scribunto demo|helloTo|John}}
function p.helloTo( frame )
	-- Argument indices START AT 1
	local name = frame.args[1]
	if name == nil then
		return "Hello to no one in particular..."
	end
	return "Hello, " .. name .. "!"
end

-- Example: printing hello using given PARENt frame argument
-- Usage: with a template `Template:Scribunto demo wrapper` defined as
--   `{{#invoke:Scribunto demo|helloTemplate}}`
-- call the template `{{Scribunto demo wrapper|John}}`
function p.helloTemplate( frame )
	-- Argument indices START AT 1
	local name = frame:getParent().args[1]
	if name == nil then
		return "Hello [through template] to no one in particular..."
	end
	return "Hello  [through template], " .. name .. "!"
end

return p
Cookies help us deliver our services. By using our services, you agree to our use of cookies.