Module:Singleton

--| Module:  Singleton (v1.1.1) --- A module that may only be invoked once per page --- before returning nil or postconditions. --by "The JoTS"

-- Note: This module relies on undefined or otherwise unexpected behavior -- to function. It may break at any time.

local p = {}

-- REFACTOR THESE VARS AT RISK OF BREAKING MODULE local _,invoke = pcall(require, "module:singleton/invoke") local call_wrap = function invoke.call end p.nothing = function end

--% For usage directly in pages (e.g. templates or articles.) --@ frame (mw frame) Scribunto frame. --: (string) Returns the first frame arg on first invoke, returns second arg (or nullstr) after p.main = function(frame) return frame:preprocess(       pcall(call_wrap)            and frame.args[1]            or  frame.args[2]            or  ''    ) end

--% For usage in other modules --@ (tuple) Values to be returned on first invoke --: (tuple or nil) Returns tuple on first invoke, nil on other invokes p.meta_before = function(...) if pcall(call_wrap) then return ... end end

--% For usage in other modules --@ (tuple) Values to be returned for invokes after the initial invoke --: (tuple or nil) Returns tuple for invokes after the first, nil on initial invoke p.meta_after = function(...) if not pcall(call_wrap) then return ... end end

return p