Difference between revisions of "Module:Sandbox/Erutuon/random"

From blackwiki
Jump to navigation Jump to search
blackwiki>Erutuon
(figured out getCurrentFrame and getParent)
blackwiki>Erutuon
(either current or parent frame)
Line 18: Line 18:
  
 
function p.namespace(frame)
 
function p.namespace(frame)
return frame:getParent():getTitle()
+
return frame:getParent():getTitle() .. " " .. mw.title.getCurrentTitle().fullText
 
end
 
end
  
Line 38: Line 38:
  
 
function p.args(frame)
 
function p.args(frame)
 +
local currentargs = mw.getCurrentFrame().args
 
local args = mw.getCurrentFrame():getParent().args
 
local args = mw.getCurrentFrame():getParent().args
return args[1]..args[2]..args[3]
+
local out = (args[1] and args[2] and args[3]) and args[1]..args[2]..args[3] or (currentargs[1] and currentargs[2] and currentargs[3]) and currentargs[1]..currentargs[2]..currentargs[3]
 +
return out
 
end
 
end
  
 
return p
 
return p

Revision as of 21:09, 12 October 2016

Test

  • Script error: The function "show" does not exist.



require("Module:No globals")

local p = {}

function p.test(frame)
	local word = frame.args[1] == "print" and "Printing is allowed"
	return word
end

function p.currentFrame(frame)
	local currentFrame = mw.getCurrentFrame(frame)
	local frameTable = {}
	for k, v in pairs(currentFrame) do
		frameTable[k] = v
	end
	return frameTable and table.concat(frameTable, ", ") or "nil"
end

function p.namespace(frame)
	return frame:getParent():getTitle() .. " " .. mw.title.getCurrentTitle().fullText
end

function p.parameterContent(frame)
	local parameter = frame.args[1]
	return parameter == "" and "Parameter is empty." or parameter == nil and "Parameter is nil." or "Parameter contains <code>" .. parameter .. "</code>."
end

function p.gmatch(frame)
	local parameter = frame.args[1]
	local array = {}
	local n = 0
	for number in string.gmatch(parameter, "%d+") do
		n = n + 1
		array[n] = number or "blah"
	end
	return n .. " " .. array[n] .. " " .. table.concat(array, ", ")
end

function p.args(frame)
	local currentargs = mw.getCurrentFrame().args
	local args = mw.getCurrentFrame():getParent().args
	local out = (args[1] and args[2] and args[3]) and args[1]..args[2]..args[3] or (currentargs[1] and currentargs[2] and currentargs[3]) and currentargs[1]..currentargs[2]..currentargs[3]
	return out
end

return p