Difference between revisions of "Module:Sandbox/Andy M. Wang/Sandbox"

From blackwiki
Jump to navigation Jump to search
blackwiki>Andy M. Wang
(return extra)
blackwiki>Andy M. Wang
(italic title)
Line 1: Line 1:
-- For unit tests, see [[Module:Sandbox/Andy M. Wang/Sandbox/testcases]]
+
-- This module implements {{italic title}}.
 +
 
 
local p = {}
 
local p = {}
  
function p.hello()
+
function p._main(args, frame, title)
return "Hello, world!"
+
args = args or {}
 +
frame = frame or mw.getCurrentFrame()
 +
title = title or mw.title.getCurrentTitle()
 +
local prefix, parentheses = mw.ustring.match(title.text, '^(.+) (%([^%(%)]+%))$')
 +
local result
 +
if prefix and parentheses and args.all ~= 'yes' then
 +
result = string.format("<i>%s</i> %s", prefix, parentheses)
 +
else
 +
result = string.format("<i>%s</i>", title.text)
 +
end
 +
if title.namespace ~= 0 then
 +
result = title.nsText:gsub('_', ' ') .. ':' .. result
 +
end
 +
return frame:callParserFunction('DISPLAYTITLE', result, args[1])
 
end
 
end
  
function p.speed_of_sound(frame)
+
function p.main(frame)
local altitude = tonumber(frame.args[1]) -- args[0] is speed_of_sound
+
local args = require('Module:Arguments').getArgs(frame, {
local mach_table = {                                                      -- a =
+
wrappers = 'Template:Italic title'
799.5, 787.0, 774.2, 761.207051,                                      -- -3 to  0
+
})
748.0, 734.6, 721.0, 707.0, 692.8, 678.3, 663.5, 660.1, 660.1, 660.1,  --  1 to 10
+
return '<noinclude>' .. p._main(args, frame) .. '</noinclude>'
660.1, 660.1, 660.1, 662.0, 664.3, 666.5, 668.9, 671.1, 673.4, 675.6,  -- 11 to 20
 
677.9, 683.7, 689.9, 696.0, 702.1, 708.1, 714.0, 719.9, 725.8, 731.6,  -- 21 to 30
 
737.3, 737.7, 737.7, 736.2, 730.5, 724.6, 718.8, 712.9, 707.0, 701.1,  -- 31 to 40
 
695.0, 688.9, 682.8, 676.6, 670.4, 664.1, 657.8, 652.9, 648.3, 643.7,  -- 41 to 50
 
639.1, 634.4, 629.6, 624.8, 620.0, 615.2, 613.2, 613.2, 613.2, 613.5,  -- 51 to 60
 
}
 
altitude = altitude or 0
 
local a = (altitude < 0) and -altitude or altitude
 
a = math.floor(a / 5000 + 0.5)
 
if altitude < 0 then
 
a = -a
 
end
 
if a < -3 then
 
a = -3
 
elseif a > 60 then
 
a = 60
 
end
 
return mach_table[a + 4] * 0.44704 .. '|' .. a .. '|' .. altitude -- mph converted to m/s
 
 
end
 
end
  
 
return p
 
return p

Revision as of 17:52, 4 June 2016

Template:NOINDEX

Links

  • [[MediaWiki:{{{1}}}]] ([{{fullurl:MediaWiki:{{{1}}}|action=edit}} edit] | [[MediaWiki talk:{{{1}}}|talk]] | [{{fullurl:MediaWiki:{{{1}}}|action=history}} history] | [{{fullurl:Special:Whatlinkshere/MediaWiki:{{{1}}}}} links] | [{{fullurl:MediaWiki:{{{1}}}|action=watch}} watch] | logs)

Usage

  • {{#invoke:Sandbox/Andy M. Wang/Sandbox|functionName}}
  • {{#invoke:Sandbox/Andy M. Wang/Sandbox/sandbox|functionName}}
  • {{#invoke:Sandbox/Andy M. Wang/Sandbox/testcases|run_tests}}

-- This module implements {{italic title}}.

local p = {}

function p._main(args, frame, title)
	args = args or {}
	frame = frame or mw.getCurrentFrame()
	title = title or mw.title.getCurrentTitle()
	local prefix, parentheses = mw.ustring.match(title.text, '^(.+) (%([^%(%)]+%))$')
	local result
	if prefix and parentheses and args.all ~= 'yes' then
		result = string.format("<i>%s</i> %s", prefix, parentheses)
	else
		result = string.format("<i>%s</i>", title.text)
	end
	if title.namespace ~= 0 then
		result = title.nsText:gsub('_', ' ') .. ':' .. result
	end
	return frame:callParserFunction('DISPLAYTITLE', result, args[1])
end

function p.main(frame)
	local args = require('Module:Arguments').getArgs(frame, {
		wrappers = 'Template:Italic title'
	})
	return '<noinclude>' .. p._main(args, frame) .. '</noinclude>'
end

return p