https://heroes.thelazy.net//index.php?title=Module:Keywords&feed=atom&action=historyModule:Keywords - Revision history2024-03-29T05:06:59ZRevision history for this page on the wikiMediaWiki 1.40.1https://heroes.thelazy.net//index.php?title=Module:Keywords&diff=65871&oldid=prevImahero at 21:44, 2 December 20232023-12-02T21:44:57Z<p></p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 21:44, 2 December 2023</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l3">Line 3:</td>
<td colspan="2" class="diff-lineno">Line 3:</td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> --Such variables can have whatever name you want and may </div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> --Such variables can have whatever name you want and may </div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> --also contain various data as well as functions.</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> --also contain various data as well as functions.</div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">p.get = function(frame)</ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"> return 'gotcha'</ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">end</ins></div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>p.hello = function( frame ) --Add a function to "p". </div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>p.hello = function( frame ) --Add a function to "p". </div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> --Such functions are callable in Wikipedia</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> --Such functions are callable in Wikipedia</div></td></tr>
</table>Imaherohttps://heroes.thelazy.net//index.php?title=Module:Keywords&diff=65848&oldid=prevImahero: Created page with "local p = {}; --All Lua modules on Wikipedia must begin by defining a variable --that will hold their externally accessible functions...."2023-12-02T20:43:39Z<p>Created page with "local p = {}; --All Lua modules on Wikipedia must begin by defining a variable --that will hold their externally accessible functions...."</p>
<p><b>New page</b></p><div>local p = {}; --All Lua modules on Wikipedia must begin by defining a variable <br />
--that will hold their externally accessible functions.<br />
--Such variables can have whatever name you want and may <br />
--also contain various data as well as functions.<br />
p.hello = function( frame ) --Add a function to "p". <br />
--Such functions are callable in Wikipedia<br />
--via the #invoke command.<br />
--"frame" will contain the data that Wikipedia<br />
--sends this function when it runs. <br />
-- 'Hello' is a name of your choice. The same name needs to be referred to when the module is used.<br />
<br />
local str = "Hello World!" --Declare a local variable and set it equal to<br />
--"Hello World!". <br />
<br />
return str --This tells us to quit this function and send the information in<br />
--"str" back to Wikipedia.<br />
<br />
end -- end of the function "hello"<br />
function p.hello_to(frame) -- Add another function<br />
local name = frame.args[1] -- To access arguments passed to a module, use `frame.args`<br />
-- `frame.args[1]` refers to the first unnamed parameter<br />
-- given to the module<br />
return "Hello, " .. name .. "!" -- `..` concatenates strings. This will return a customized<br />
-- greeting depending on the name given, such as "Hello, Fred!"<br />
end<br />
function p.count_fruit(frame)<br />
<br />
local num_bananas = tonumber(frame.args.bananas) or 0 -- Named arguments ({{#invoke:Example|count_fruit|foo=bar}})<br />
local num_apples = tonumber(frame.args.apples) or 0 -- are likewise accessed by indexing `frame.args` by name (`frame.args["bananas"]`,<br />
-- or equivalently `frame.args.bananas`.<br />
<br />
local conj_bananas = num_bananas == 1 and 'banana' or 'bananas'<br />
local conj_apples = num_apples == 1 and 'apple' or 'apples'<br />
-- Ternary operators assign values based on a condition in a compact way.<br />
-- Here, `conj_bananas` gets `'banana'` if `num_bananas` is 1, else `'bananas'`.<br />
-- Similarly, `conj_apples` gets `'apple'` if `num_apples` is 1, else `'apples'`.<br />
<br />
return 'I have ' .. num_bananas .. ' ' .. conj_bananas .. ' and ' .. num_apples .. ' ' .. conj_apples <br />
-- Like above, concatenate a bunch of strings together to produce<br />
-- a sentence based on the arguments given.<br />
end<br />
<br />
local function lucky(a, b) -- One can define custom functions for use. Here we define a function 'lucky' that has two inputs a and b. The names are of your choice.<br />
if b == 'yeah' then -- Condition: if b is the string 'yeah'. Strings require quotes. Remember to include 'then'.<br />
return a .. ' is my lucky number.' -- Outputs 'a is my lucky number.' if the above condition is met. The string concatenation operator is denoted by 2 dots.<br />
else -- If no conditions are met, i.e. if b is anything else, output specified on the next line. 'else' should not have 'then'.<br />
return a -- Simply output a.<br />
end -- The 'if' section should end with 'end'.<br />
end -- As should 'function'.<br />
<br />
function p.Name2(frame)<br />
-- The next five lines are mostly for convenience only and can be used as is for your module. The output conditions start on line 50.<br />
local pf = frame:getParent().args -- This line allows template parameters to be used in this code easily. The equal sign is used to define variables. 'pf' can be replaced with a word of your choice.<br />
local f = frame.args -- This line allows parameters from {{#invoke:}} to be used easily. 'f' can be replaced with a word of your choice.<br />
local M = f[1] or pf[1] -- f[1] and pf[1], which we just defined, refer to the first parameter. This line shortens them as 'M' for convenience. You could use the original variable names.<br />
local m = f[2] or pf[2] -- Second shortened as 'm'.<br />
local l = f.lucky or pf.lucky -- A named parameter 'lucky' is shortend as l. Note that the syntax is different from unnamed parameters.<br />
if m == nil then -- If the second parameter is not used.<br />
return 'Potato' -- Outputs the string 'Potato' if the first condition is met.<br />
elseif M > m then -- If the first condition is not met, this line tests a second condition: if M is greater than m.<br />
return lucky(M - m, l) -- If the condition is met, the difference is calculated and passed to the self defined function along with l. The output depends on whether l is set to 'yeah'.<br />
else<br />
return 'Vegetable!'<br />
end<br />
end<br />
<br />
return p --All modules end by returning the variable containing their functions to Wikipedia.<br />
-- Now we can use this module by calling {{#invoke: Example | hello }},<br />
-- {{#invoke: Example | hello_to | foo }}, or {{#invoke:Example|count_fruit|bananas=5|apples=6}}<br />
-- Note that the first part of the invoke is the name of the Module's wikipage,<br />
-- and the second part is the name of one of the functions attached to the <br />
-- variable that you returned.<br />
<br />
-- The "print" function is not allowed in Wikipedia. All output is accomplished<br />
-- via strings "returned" to Wikipedia.</div>Imahero