Module:Example: Difference between revisions

m
→‎top: clean up, replaced: Wikipedia → Bharatpedia (7)
>Pppery
(Dummy edit to correct attribution: Author of previous edit is User:Szqecs)
 
m (→‎top: clean up, replaced: Wikipedia → Bharatpedia (7))
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
local p = {};    --All lua modules on Wikipedia must begin by defining a variable  
local p = {};    --All lua modules on Bharatpedia 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.
p.hello = function( frame )    --Add a function to "p".   
p.hello = function( frame )    --Add a function to "p".   
                                         --Such functions are callable in Wikipedia
                                         --Such functions are callable in Bharatpedia
                                         --via the #invoke command.
                                         --via the #invoke command.
                                         --"frame" will contain the data that Wikipedia
                                         --"frame" will contain the data that Bharatpedia
                                         --sends this function when it runs.  
                                         --sends this function when it runs.  
                                 -- 'Hello' is a name of your choice. The same name needs to be referred to when the module is used.
                                 -- 'Hello' is a name of your choice. The same name needs to be referred to when the module is used.
Line 14: Line 14:
      
      
     return str    --This tells us to quit this function and send the information in
     return str    --This tells us to quit this function and send the information in
                   --"str" back to Wikipedia.
                   --"str" back to Bharatpedia.
      
      
end  -- end of the function "hello"
end  -- end of the function "hello"
Line 57: Line 57:
end
end


return p    --All modules end by returning the variable containing their functions to Wikipedia.
return p    --All modules end by returning the variable containing their functions to Bharatpedia.
-- Now we can use this module by calling {{#invoke: Example | hello }},
-- Now we can use this module by calling {{#invoke: Example | hello }},
-- {{#invoke: Example | hello_to | foo }}, or {{#invoke:Example|count_fruit|bananas=5|apples=6}}
-- {{#invoke: Example | hello_to | foo }}, or {{#invoke:Example|count_fruit|bananas=5|apples=6}}
Line 64: Line 64:
-- variable that you returned.
-- variable that you returned.


-- The "print" function is not allowed in Wikipedia.  All output is accomplished
-- The "print" function is not allowed in Bharatpedia.  All output is accomplished
-- via strings "returned" to Wikipedia.
-- via strings "returned" to Bharatpedia.
Bots, trusted
7,437

edits