<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://horizonffxi.wiki/w/index.php?action=history&amp;feed=atom&amp;title=Module%3AEntrypoint</id>
	<title>Module:Entrypoint - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://horizonffxi.wiki/w/index.php?action=history&amp;feed=atom&amp;title=Module%3AEntrypoint"/>
	<link rel="alternate" type="text/html" href="https://horizonffxi.wiki/w/index.php?title=Module:Entrypoint&amp;action=history"/>
	<updated>2026-04-05T11:56:56Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.10</generator>
	<entry>
		<id>https://horizonffxi.wiki/w/index.php?title=Module:Entrypoint&amp;diff=10211&amp;oldid=prev</id>
		<title>Hugin: Created page with &quot;--- Entrypoint templating wrapper for Scribunto packages. --  The module generates an entrypoint function that can execute Scribunto --  package calls in the template context. This allows a package to support --  both direct and template invocations. --   --  @script             entrypoint --  @release            stable --  @author             8nml --  @param              {table} package Scribunto package. --  @error[85]          {string} &#039;you must specify...&quot;</title>
		<link rel="alternate" type="text/html" href="https://horizonffxi.wiki/w/index.php?title=Module:Entrypoint&amp;diff=10211&amp;oldid=prev"/>
		<updated>2023-05-30T19:06:01Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;--- Entrypoint templating wrapper for Scribunto packages. --  The module generates an entrypoint function that can execute Scribunto --  package calls in the template context. This allows a package to support --  both direct and template invocations. --   --  @script             entrypoint --  @release            stable --  @author             &lt;a href=&quot;/w/index.php?title=User:8nml&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;User:8nml (page does not exist)&quot;&gt;8nml&lt;/a&gt; --  @param              {table} package Scribunto package. --  @error[85]          {string} &amp;#039;you must specify...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;--- Entrypoint templating wrapper for Scribunto packages.&lt;br /&gt;
--  The module generates an entrypoint function that can execute Scribunto&lt;br /&gt;
--  package calls in the template context. This allows a package to support&lt;br /&gt;
--  both direct and template invocations.&lt;br /&gt;
--  &lt;br /&gt;
--  @script             entrypoint&lt;br /&gt;
--  @release            stable&lt;br /&gt;
--  @author             [[User:8nml|8nml]]&lt;br /&gt;
--  @param              {table} package Scribunto package.&lt;br /&gt;
--  @error[85]          {string} &amp;#039;you must specify a function to call&amp;#039;&lt;br /&gt;
--  @error[91]          {string} &amp;#039;the function you specified did not exist&amp;#039;&lt;br /&gt;
--  @error[opt,95]      {string} &amp;#039;$2 is not a function&amp;#039;&lt;br /&gt;
--  @return             {function} Template entrypoint - @{main}.&lt;br /&gt;
--  @note               Parent frames are not available in Entrypoint&amp;#039;s&lt;br /&gt;
--                      `frame`. This is because recursive (grandparent)&lt;br /&gt;
--                      frame access is impossible in legacy Scribunto&lt;br /&gt;
--                      due to [[mw:Manual:Parser#Empty-argument expansion&lt;br /&gt;
--                      cache|empty-argument expansion cache]] limitations.&lt;br /&gt;
--  @note               As Entrypoint enables template access rather than&lt;br /&gt;
--                      a new extension hook, it does not work with named&lt;br /&gt;
--                      numeric parameters such as `1=` or `2=`. This may&lt;br /&gt;
--                      result in unexpected behaviour such as Entrypoint&lt;br /&gt;
--                      and module errors.&lt;br /&gt;
&lt;br /&gt;
--- Stateless, sequential Lua iterator.&lt;br /&gt;
--  @function           inext&lt;br /&gt;
--  @param              {table} t Invariant state to loop over.&lt;br /&gt;
--  @param              {number} i Control variable (current index).&lt;br /&gt;
--  @return[opt]        {number} Next index.&lt;br /&gt;
--  @return[opt]        {number|string|table|boolean} Next value.&lt;br /&gt;
--  @see                [[github:lua/lua/blob/v5.1.1/lbaselib.c#L247]]&lt;br /&gt;
local inext = select(1, ipairs{})&lt;br /&gt;
&lt;br /&gt;
--- Check for MediaWiki version 1.25.&lt;br /&gt;
--  The concurrent Scribunto release adds a type check for package functions.&lt;br /&gt;
--  @variable           {boolean} func_check&lt;br /&gt;
--  @see                [[mw:MediaWiki 1.24/wmf7#Scribunto]]&lt;br /&gt;
local func_check = tonumber(mw.site.currentVersion:match(&amp;#039;^%d+.%d+&amp;#039;)) &amp;gt;= 1.25&lt;br /&gt;
&lt;br /&gt;
--- MediaWiki error message getter.&lt;br /&gt;
--  Mimics Scribunto error formatting for script errors. &lt;br /&gt;
--  @function           msg&lt;br /&gt;
--  @param              {string} key MediaWiki i18n message key.&lt;br /&gt;
--  @param[opt]         {string} fn_name Name of package function.&lt;br /&gt;
--  @return             {string} Formatted lowercase message.&lt;br /&gt;
--  @local&lt;br /&gt;
local function msg(key, fn_name)&lt;br /&gt;
    return select(1, mw.message.new(key)&lt;br /&gt;
        :plain()&lt;br /&gt;
        :match(&amp;#039;:%s*(.-)[.۔。෴։።]?$&amp;#039;)&lt;br /&gt;
        :gsub(&amp;#039;^.&amp;#039;, mw.ustring.lower)&lt;br /&gt;
        :gsub(&amp;#039;$2&amp;#039;, fn_name or &amp;#039;$2&amp;#039;)&lt;br /&gt;
    )&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--- Template entrypoint function generated by this module.&lt;br /&gt;
--  @function           main&lt;br /&gt;
--  @param              {Frame} frame Scribunto frame in module context.&lt;br /&gt;
--  @return             {string} Module output in template context.&lt;br /&gt;
return function(package) return function(f)&lt;br /&gt;
    local frame = f:getParent()&lt;br /&gt;
&lt;br /&gt;
    local args_mt = {}&lt;br /&gt;
    local arg_cache = {}&lt;br /&gt;
&lt;br /&gt;
    args_mt.__pairs = function()&lt;br /&gt;
        return next, arg_cache, nil&lt;br /&gt;
    end&lt;br /&gt;
    args_mt.__ipairs = function()&lt;br /&gt;
        return inext, arg_cache, 0&lt;br /&gt;
    end&lt;br /&gt;
    args_mt.__index = function(t, k)&lt;br /&gt;
        return arg_cache[k]&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    for key, val in pairs(frame.args) do&lt;br /&gt;
        arg_cache[key] = val&lt;br /&gt;
    end&lt;br /&gt;
    local fn_name = table.remove(arg_cache, 1)&lt;br /&gt;
&lt;br /&gt;
    f.args = setmetatable({}, args_mt)&lt;br /&gt;
    frame.args = setmetatable({}, args_mt)&lt;br /&gt;
&lt;br /&gt;
    if not fn_name then&lt;br /&gt;
        error(msg(&amp;#039;scribunto-common-nofunction&amp;#039;))&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    fn_name = mw.text.trim(fn_name)&lt;br /&gt;
&lt;br /&gt;
    if not package[fn_name] then&lt;br /&gt;
        error(msg(&amp;#039;scribunto-common-nosuchfunction&amp;#039;, fn_name))&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if func_check and type(package[fn_name]) ~= &amp;#039;function&amp;#039; then&lt;br /&gt;
        error(msg(&amp;#039;scribunto-common-notafunction&amp;#039;, fn_name))&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    return package[fn_name](frame)&lt;br /&gt;
end end&lt;/div&gt;</summary>
		<author><name>Hugin</name></author>
	</entry>
</feed>