Module:Sond-roots: Difference between revisions
From Allocosm
|  (Created page with "export = {}  require("Module:sond-roots/data")  function export.replace(str1, str2, oper)  	 	local rules = {} 	local output = "" 	local orig_oper = opers[oper] 	local orig_rules = orig_oper[1] 	local default = orig_oper[2]  	for k,v in pairs(orig_rules) do 		rules[k] = string.gsub(v,"[12]",{["1"] = str1, ["2"] = str2}) 	end 	default = string.gsub(default,"[12]",{["1"] = str1, ["2"] = str2})  	output = rules[str1..str2] or default  	return output  end           return ex...") | No edit summary | ||
| Line 4: | Line 4: | ||
| function export.replace(str1, str2, oper)   | function export.replace(str1, str2, oper)   | ||
| 	str1 = str1 or '' | |||
| 	str2 = str2 or '' | |||
| 	local rules = {} | 	local rules = {} | ||
| Line 14: | Line 16: | ||
| 		rules[k] = string.gsub(v,"[12]",{["1"] = str1, ["2"] = str2}) | 		rules[k] = string.gsub(v,"[12]",{["1"] = str1, ["2"] = str2}) | ||
| 	end | 	end | ||
| 	default = string.gsub(default,"[12]",{["1"] = str1, ["2"] = str2}) | |||
| 	if type(default) == 'string' then  | |||
| 		default = string.gsub(default,"[12]",{["1"] = str1, ["2"] = str2}) | |||
| 	elseif type(default) == 'function' then | |||
| 		default = default(str1,str2) | |||
| 	end | |||
| 	output = rules[str1..str2] or default | 	output = rules[str1..str2] or default | ||
Revision as of 11:10, 17 March 2024
Documentation for this module may be created at Module:Sond-roots/doc
export = {}
require("Module:sond-roots/data")
function export.replace(str1, str2, oper) 
	str1 = str1 or ''
	str2 = str2 or ''
	
	local rules = {}
	local output = ""
	local orig_oper = opers[oper]
	local orig_rules = orig_oper[1]
	local default = orig_oper[2]
	for k,v in pairs(orig_rules) do
		rules[k] = string.gsub(v,"[12]",{["1"] = str1, ["2"] = str2})
	end
	
	if type(default) == 'string' then 
		default = string.gsub(default,"[12]",{["1"] = str1, ["2"] = str2})
	elseif type(default) == 'function' then
		default = default(str1,str2)
	end
	output = rules[str1..str2] or default
	return output
end
return export
