მოდული:თარგი:ბაზის გაცვლა

მასალა ვიკიპედიიდან — თავისუფალი ენციკლოპედია

შეგიძლიათ შექმნათ დოკუმენტაცია ამ მოდულისათვის: მოდული:თარგი:ბაზის გაცვლა/ინფო

local function trim(text)
	while mw.ustring.sub(text,1,1) == " " do
		text=  mw.ustring.sub(text,2,-1);
	end
	while mw.ustring.sub(text,-1,-1) == " " do
		text=  mw.ustring.sub(text,1,-2);
	end
	return text;
end

local p = {}
	function p.Execute(frame)
		local zahl = tonumber(trim(frame.args[1] or "0"));
		local basis = tonumber(trim(frame.args[2] or "0"));
		local groups = frame.args['g']  or "";
		local data = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
		local temp = 0;
		local out = '';
		local z = ''
		local rest;
		local rev;
		local length;
		local pos;
		zahl  = math.floor( 0.5 + zahl);
		basis = math.floor( 0.5 + basis);
		if zahl < 0 or basis < 2 or basis > 36 then
			return '<span class="error">&lt;ERR!&gt;</span>';
		end
		temp = zahl
		if (temp == 0) then
			return '0';
		end
		while (temp > 0) do
			rest = temp % basis;
			z = mw.ustring.sub(data,rest+1,rest+1);
			out = z  .. out;
			temp = math.floor( 0.5 + (temp - rest) / basis);
		end
		if groups ~= "" then
			rev = string.reverse(out) .. '    ';
			length = string.len(rev);
			temp = "";
			for pos = 4, length, 4  do
				temp = temp .. string.sub(rev, pos-3 ,pos) .. ' ';
			end
			out = string.reverse(temp);
			out = trim(out);
		end
		return out;
	end

	function p.Morse(frame) -- Exttramodul lohnt nicht
		local zahl = frame.args['z'] or '0';
		local out = "";
		if tonumber(zahl) then
			out = zahl;
		else
			out = "???"
		end
		out = string.gsub(out,'0','–&nbsp;–&nbsp;–&nbsp;–&nbsp;–&nbsp; ');
		out = string.gsub(out,'1','·&nbsp;–&nbsp;–&nbsp;–&nbsp;–&nbsp; ');
		out = string.gsub(out,'2','·&nbsp;·&nbsp;–&nbsp;–&nbsp;–&nbsp; ');
		out = string.gsub(out,'3','·&nbsp;·&nbsp;·&nbsp;–&nbsp;–&nbsp; ');
		out = string.gsub(out,'4','·&nbsp;·&nbsp;·&nbsp;·&nbsp;–&nbsp; ');
		out = string.gsub(out,'5','·&nbsp;·&nbsp;·&nbsp;·&nbsp;·&nbsp; ');
		out = string.gsub(out,'6','–&nbsp;·&nbsp;·&nbsp;·&nbsp;·&nbsp; ');
		out = string.gsub(out,'7','–&nbsp;–&nbsp;·&nbsp;·&nbsp;·&nbsp; ');
		out = string.gsub(out,'8','–&nbsp;–&nbsp;–&nbsp;·&nbsp;·&nbsp; ');
		out = string.gsub(out,'9','–&nbsp;–&nbsp;–&nbsp;–&nbsp;·&nbsp; ');
		out = trim(out);
		return out;
	end

return p;