Module:ugly hacks

Hello, you have come here looking for the meaning of the word Module:ugly hacks. In DICTIOUS you will not only get to know all the dictionary meanings for the word Module:ugly hacks, but we will also tell you about its etymology, its characteristics and you will know how to say Module:ugly hacks in singular and plural. Everything you need to know about the word Module:ugly hacks you have here. The definition of the word Module:ugly hacks will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofModule:ugly hacks, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.

This module provides templates with functions which cannot be accessed any other way. When a function is not used, it should be removed.

Avoid using this module. If you find yourself writing a template which needs it, consider re-writing the template in Lua.

This module tracks templates in which its functions are used, using the tracking template mechanism; the tracking templates' names are of the form Wiktionary:tracking/ugly hacks/function_name and Wiktionary:tracking/ugly hacks/function_name/from template_name. To prevent it from becoming ineffective, wrappers around functions in this module should not be created; the {{#invoke:}} should be put directly where it is needed.

To further discourage their use, functions in this module are intentionally undocumented. To discover their usage purpose and syntax, please refer to mw:Extension:Scribunto/Lua reference manual.

Questions about this module and its possible replacements may be raised at Wiktionary:Grease pit.


local m_str_utils = require("Module:string utilities")

local gsplit = m_str_utils.gsplit
local ufind = m_str_utils.find
local ugsub = m_str_utils.gsub
local umatch = m_str_utils.match
local usub = m_str_utils.sub

local export = {}

function export.explode(frame)
	local wanted_index = tonumber(frame.args)
 
	local count = 1
	for item in gsplit(frame.args, frame.args, true) do
		if count == wanted_index then
			return item
		end
		count = count + 1	
	end
	
	return ""
end

function export.substr(frame)
	return usub(frame.args or "", tonumber(frame.args) or 1, tonumber(frame.args) or -1)
end

function export.find(frame)
	return ufind(frame.args or "", frame.args or "", 1, true) or ""
end

function export.find_pattern(frame)
	return ufind(frame.args or "", frame.args or "", 1, false) or ""
end

function export.replace(frame)
	return (ugsub(frame.args or "", frame.args or "", frame.args or ""))
end

function export.match(frame)
	return (umatch(frame.args or "", frame.args or ""))
end

function export.is_valid_page_name(frame)
	return mw.title.new(frame.args) and "valid" or ""
end

return setmetatable({ }, {
	__index = function(self, key)
		local m_debug = require('Module:debug')
		local frame = mw.getCurrentFrame()
		local pframe = frame:getParent()
		local tname = pframe and pframe:getTitle()

		m_debug.track('ugly hacks/' .. key)
		if pframe then
			m_debug.track('ugly hacks/' .. key .. '/from ' .. tname)
		else
			mw.log(debug.traceback('ugly hacks: parent frame not available'))
		end
		return export	
	end
})