Jump to content

Module:Warning: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Created page with 'local wrapper = '%s' -- wikitext formatting return function (message) mw.addWarning(wrapper:format(message)) end'
 
Formatted warning text and implemented level parameter
Line 1: Line 1:
local libraryUtil = require('libraryUtil')
local wrapper = '%s' -- wikitext formatting


local wrapper = "%s" -- wikitext formatting
return function (message)
local msg_loc = "Lua warning in %s at line %d: %s"
local msg = "Lua warning: %s"

return function (message, level)
libraryUtil.checkType('warn', 2, level, 'number', true)
level = level or 1
if level > 0 then
local location = debug.traceback('', level+1)
location = mw.text.split(location, ':%s')
if location[2] then
location = mw.text.split(location[2], ':%f[%d]')
message = msg_loc:format(location[1], location[2], message)
else
message = msg:format(message)
end
else
message = msg:format(message)
end
mw.addWarning(wrapper:format(message))
mw.addWarning(wrapper:format(message))
end
end

Revision as of 23:23, 18 July 2021

local libraryUtil = require('libraryUtil')

local wrapper = "%s" -- wikitext formatting
local msg_loc = "Lua warning in %s at line %d: %s"
local msg = "Lua warning: %s"

return function (message, level)
	libraryUtil.checkType('warn', 2, level, 'number', true)
	level = level or 1
	if level > 0 then
		local location = debug.traceback('', level+1)
		location = mw.text.split(location, ':%s')
		if location[2] then
			location = mw.text.split(location[2], ':%f[%d]')
			message = msg_loc:format(location[1], location[2], message)
		else
			message = msg:format(message)
		end
	else
		message = msg:format(message)
	end
	mw.addWarning(wrapper:format(message))
end