Module:GenUID

From bg3.wiki
Jump to navigation Jump to search

Generates a unique string for every invocation within the scope of a wiki.

The generated string is of the format:

PAGETITLE/COUNTER

Where the page title includes the namespace, and the counter increases for every invocation of this module within that page.

Example use:

Markup Renders as
{{#invoke:GenUID|gen}}
Module:GenUID/0
{{#invoke:GenUID|gen}}
Module:GenUID/1
{{#invoke:GenUID|gen}}
Module:GenUID/2

local p = {}

-- Counter Variable (global per page; make sure it's unlikely to clash)
local cv = "_GenUIDCounter_";

function p.gen(frame)
	local counter = frame:callParserFunction("#var", cv, 0);
	frame:callParserFunction("#vardefine", cv, counter + 1);
	local page = mw.title.getCurrentTitle();
	return page.fullText.."/"..counter;
end

return p