Module:Sandbox/Ahecht

{{Module rating }}

Module:Sandbox/Ahecht

local p = {}

local dots = ...

local out_mt = {	-- Append to array by calling it
	__call = function (t, v) t[#t+1] = v end,
	__tostring = function(t) return table.concat(t) end
}

function p.main(frame)
	local output = setmetatable({}, out_mt)
	output('frame: ' .. type(frame) .. ' ')
	if type(frame) == 'table' then
		output(mw.dumpObject(frame))
	end
	output('<br />frame:getParent() ' .. type(frame:getParent()) .. ' ')
	if type(frame:getParent()) == 'table' then
		output(mw.dumpObject(frame:getParent()))
	end

	if frame.args['test'] == 0 then
		output('<br />0 the number')
	elseif frame.args['test'] == '0' then
		output('<br />0 the character')
	end
	
	local thisframe = mw.getCurrentFrame()
	if thisframe then
		output("<br />mw.getCurrentFrame():getTitle(): ")
		output(thisframe:getTitle())
		thisframe = thisframe:getParent()
		if thisframe then
			output("<br />mw.getCurrentFrame():getParent():getTitle(): ")
			output(thisframe:getTitle())
			thisframe = thisframe:getParent()
			if thisframe then
				output("<br />mw.getCurrentFrame():getParent():getParent():getTitle(): ")
				output(thisframe:getTitle())
			end
		end
	end
	return output
end

function p.isnumeric(frame)
	local s = frame.args[1] or frame:getParent().args[1]
	local boolean = (frame.args.boolean or frame:getParent().args.boolean) == 'true'
	if type(s) == 'string' and mw.getContentLanguage():parseFormattedNumber( s ) then
		return boolean and 1 or s
	end
	return boolean and 0 or ''
end

local function error(_, key)
	return "Error! Missing function " .. key
end

local metatable = {['__index'] = error}

setmetatable(p, metatable)

function p.dots()
	return dots
end

function p.prefix(frame)
	local args = {}
	for k,v in pairs(frame.args) do
		if k ~= '_prefix' and k ~= '_template' then
			table.insert(args, '| ' .. (frame.args['_prefix'] or '') .. k .. " = " .. v)
		end
	end
	return table.concat(args, '\n')
end

return setmetatable(p, {__index =
	function(_, key)														-- this anonymous function called as function(TABLE, KEY)
		return function (frame) return error (frame, key) end;				-- which in turn returns a function that calls cite() with the KEY name
	end
})

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.