Module:Sond-roots: Difference between revisions
From Allocosm
| No edit summary | No edit summary | ||
| Line 3: | Line 3: | ||
| require("Module:sond-roots/data") | require("Module:sond-roots/data") | ||
| function export.replace(str1, str2 | function export.replace(oper, str1, str2)   | ||
| 	str1 = str1 or '' | 	str1 = str1 or '' | ||
| 	str2 = str2 or '' | 	str2 = str2 or '' | ||
Latest revision as of 13:55, 17 March 2024
Documentation for this module may be created at Module:Sond-roots/doc
export = {}
require("Module:sond-roots/data")
function export.replace(oper, str1, str2) 
	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[string.gsub(k,"[12]",{["1"] = str1, ["2"] = str2})] = 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
