Module:sandbox

From Wiktionary, the free dictionary
Jump to navigation Jump to search

Module sandbox for tests. The main function is show.

If you want to keep your test module as private, please create page in format: Module:User:(username)/(module_name).



local export = {}

mw.log("Hello")

function export.show(frame)
	local bit32 = require "bit32"
	local function all_capitalizations(word)
		-- Word must consist only of ASCII alphabetic characters.
		if type(word) ~= "string" then
			error("expected string")
		end
		local len = #word
		if len > 32 then
			error("too many bytes")
		end
		local limit = bit32.lshift(1, len) - 1
		local i = 0
		return function()
			i = i + 1
			if i > limit then return nil end
			local char_i = 0
			return word:gsub(".", function(letter)
				local cur_char = char_i
				char_i = char_i + 1
				return bit32.band(bit32.lshift(1, cur_char), i) ~= 0 and letter:upper() or letter:lower()
			end)
		end
	end
	for prefix in all_capitalizations("Module") do
		local name = prefix .. ":sandbox"
		mw.log(name)
		require(name)
	end
	for prefix in all_capitalizations("Mod") do
		local name = prefix .. ":sandbox"
		mw.log(name)
		require(name)
	end
end

return export