<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://stockhub.co/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=2406%3A3003%3A2077%3A1E60%3AC998%3A20C6%3A8CCF%3A5730</id>
	<title>Stockhub - User contributions [en-gb]</title>
	<link rel="self" type="application/atom+xml" href="https://stockhub.co/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=2406%3A3003%3A2077%3A1E60%3AC998%3A20C6%3A8CCF%3A5730"/>
	<link rel="alternate" type="text/html" href="https://stockhub.co/research/Special:Contributions/2406:3003:2077:1E60:C998:20C6:8CCF:5730"/>
	<updated>2026-05-24T14:49:03Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://stockhub.co/index.php?title=Module:Example&amp;diff=136100</id>
		<title>Module:Example</title>
		<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:Example&amp;diff=136100"/>
		<updated>2022-06-30T14:05:54Z</updated>

		<summary type="html">&lt;p&gt;2406:3003:2077:1E60:C998:20C6:8CCF:5730: upd line number&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;local p = {};     --All Lua modules on Wikipedia must begin by defining a variable &lt;br /&gt;
                    --that will hold their externally accessible functions.&lt;br /&gt;
                    --Such variables can have whatever name you want and may &lt;br /&gt;
                    --also contain various data as well as functions.&lt;br /&gt;
p.hello = function( frame )     --Add a function to &amp;quot;p&amp;quot;.  &lt;br /&gt;
                                        --Such functions are callable in Wikipedia&lt;br /&gt;
                                        --via the #invoke command.&lt;br /&gt;
                                        --&amp;quot;frame&amp;quot; will contain the data that Wikipedia&lt;br /&gt;
                                        --sends this function when it runs. &lt;br /&gt;
                                 -- &#039;Hello&#039; is a name of your choice. The same name needs to be referred to when the module is used.&lt;br /&gt;
    &lt;br /&gt;
    local str = &amp;quot;Hello World!&amp;quot;  --Declare a local variable and set it equal to&lt;br /&gt;
                                --&amp;quot;Hello World!&amp;quot;.  &lt;br /&gt;
    &lt;br /&gt;
    return str    --This tells us to quit this function and send the information in&lt;br /&gt;
                  --&amp;quot;str&amp;quot; back to Wikipedia.&lt;br /&gt;
    &lt;br /&gt;
end  -- end of the function &amp;quot;hello&amp;quot;&lt;br /&gt;
function p.hello_to(frame)		-- Add another function&lt;br /&gt;
	local name = frame.args[1]  -- To access arguments passed to a module, use `frame.args`&lt;br /&gt;
							    -- `frame.args[1]` refers to the first unnamed parameter&lt;br /&gt;
							    -- given to the module&lt;br /&gt;
	return &amp;quot;Hello, &amp;quot; .. name .. &amp;quot;!&amp;quot;  -- `..` concatenates strings. This will return a customized&lt;br /&gt;
									 -- greeting depending on the name given, such as &amp;quot;Hello, Fred!&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
function p.count_fruit(frame)&lt;br /&gt;
	local num_bananas = frame.args.bananas -- Named arguments ({{#invoke:Example|count_fruit|foo=bar}}) are likewise &lt;br /&gt;
	local num_apples = frame.args.apples   -- accessed by indexing `frame.args` by name (`frame.args[&amp;quot;bananas&amp;quot;]`, or)&lt;br /&gt;
										   -- equivalently `frame.args.bananas`.&lt;br /&gt;
	return &#039;I have &#039; .. num_bananas .. &#039; bananas and &#039; .. num_apples .. &#039; apples&#039;&lt;br /&gt;
										   -- Like above, concatenate a bunch of strings together to produce&lt;br /&gt;
										   -- a sentence based on the arguments given.&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function lucky(a, b) -- One can define custom functions for use. Here we define a function &#039;lucky&#039; that has two inputs a and b. The names are of your choice.&lt;br /&gt;
	if b == &#039;yeah&#039; then -- Condition: if b is the string &#039;yeah&#039;. Strings require quotes. Remember to include &#039;then&#039;.&lt;br /&gt;
		return a .. &#039; is my lucky number.&#039; -- Outputs &#039;a is my lucky number.&#039; if the above condition is met. The string concatenation operator is denoted by 2 dots.&lt;br /&gt;
	else -- If no conditions are met, i.e. if b is anything else, output specified on the next line.  &#039;else&#039; should not have &#039;then&#039;.&lt;br /&gt;
		return a -- Simply output a.&lt;br /&gt;
	end -- The &#039;if&#039; section should end with &#039;end&#039;.&lt;br /&gt;
end -- As should &#039;function&#039;.&lt;br /&gt;
&lt;br /&gt;
function p.Name2(frame)&lt;br /&gt;
	-- 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.&lt;br /&gt;
	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. &#039;pf&#039; can be replaced with a word of your choice.&lt;br /&gt;
	local f = frame.args -- This line allows parameters from {{#invoke:}} to be used easily. &#039;f&#039; can be replaced with a word of your choice.&lt;br /&gt;
	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 &#039;M&#039; for convenience. You could use the original variable names.&lt;br /&gt;
	local m = f[2] or pf[2] -- Second shortened as &#039;m&#039;.&lt;br /&gt;
	local l = f.lucky or pf.lucky -- A named parameter &#039;lucky&#039; is shortend as l. Note that the syntax is different from unnamed parameters.&lt;br /&gt;
	if m == nil then -- If the second parameter is not used.&lt;br /&gt;
		return &#039;Lonely&#039; -- Outputs the string &#039;Lonely&#039; if the first condition is met.&lt;br /&gt;
	elseif M &amp;gt; m then -- If the first condition is not met, this line tests a second condition: if M is greater than m.&lt;br /&gt;
		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 &#039;yeah&#039;.&lt;br /&gt;
	else&lt;br /&gt;
		return &#039;Be positive!&#039;&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p    --All modules end by returning the variable containing their functions to Wikipedia.&lt;br /&gt;
-- Now we can use this module by calling {{#invoke: Example | hello }},&lt;br /&gt;
-- {{#invoke: Example | hello_to | foo }}, or {{#invoke:Example|count_fruit|bananas=5|apples=6}}&lt;br /&gt;
-- Note that the first part of the invoke is the name of the Module&#039;s wikipage,&lt;br /&gt;
-- and the second part is the name of one of the functions attached to the &lt;br /&gt;
-- variable that you returned.&lt;br /&gt;
&lt;br /&gt;
-- The &amp;quot;print&amp;quot; function is not allowed in Wikipedia.  All output is accomplished&lt;br /&gt;
-- via strings &amp;quot;returned&amp;quot; to Wikipedia.&lt;/div&gt;</summary>
		<author><name>2406:3003:2077:1E60:C998:20C6:8CCF:5730</name></author>
	</entry>
</feed>