You can edit almost every page by Creating an account and confirming your email.

Module:HelloWorld: Difference between revisions

From EverybodyWiki Bios & Wiki
WikiMaster (talk | contribs)
m 1 revision imported
 
WikiMasterBot2 (talk | contribs)
m Add new revision
 
Line 1: Line 1:
my_object = {};    --All lua modules on Wikipedia must begin by defining a variable  
local p = {};    --All lua modules on Wikipedia must begin by defining a variable  
                     --that will hold their externally accessible functions.
                     --that will hold their externally accessible functions.
                     --Such variables can have whatever name you want and may  
                     --Such variables can have whatever name you want and may  
                     --also contain various data as well as functions.
                     --also contain various data as well as functions.


my_object.hello = function( frame )    --Add a function to "my_object".   
p.hello = function( frame )    --Add a function to "my_object".   
                                         --Such functions are callable in Wikipedia
                                         --Such functions are callable in Wikipedia
                                         --via the #invoke command.
                                         --via the #invoke command.
Line 18: Line 18:
end  -- end of the function "hello"
end  -- end of the function "hello"


return my_object   --All modules end by returning the variable containing its
return p   --All modules end by returning the variable containing its
                     --functions to Wikipedia.
                     --functions to Wikipedia.



Latest revision as of 12:08, 14 March 2019

This is a simple example function to show the structure of Lua modules on Wikipedia. Module:Bananas is another version of a "Hello, World!" program.


local p = {};     --All lua modules on Wikipedia must begin by defining a variable 
                    --that will hold their externally accessible functions.
                    --Such variables can have whatever name you want and may 
                    --also contain various data as well as functions.

p.hello = function( frame )     --Add a function to "my_object".  
                                        --Such functions are callable in Wikipedia
                                        --via the #invoke command.
                                        --"frame" will contain the data that Wikipedia
                                        --sends this function when it runs. 
    
    local str = "Hello World!"  --Declare a local variable and set it equal to
                                --"Hello World!".  
    
    return str    --This tells us to quit this function and send the information in
                  --"str" back to Wikipedia.
    
end  -- end of the function "hello"

return p    --All modules end by returning the variable containing its
                    --functions to Wikipedia.

-- Now we can use this module by calling {{#invoke: HelloWorld | hello }}.
-- Note that the first part of the invoke is the name of the Module's wikipage,
-- and the second part is the name of one of the functions attached to the 
-- variable that you returned.

-- The "print" function is not allowed in Wikipedia.  All output is accomplished
-- via strings "returned" to Wikipedia.

This module "HelloWorld" is from Wikipedia if otherwise notified