Module:ArgsDemo/doc
This is an example module that demonstrates how to access arguments. It is used in Scribunto: An Introduction.
Hello world
[edit source]{{#invoke:ArgsDemo|hello_world}}
This function displays the text "Hello, world!". It doesn't use any arguments.
Example:
{{#invoke:ArgsDemo|hello_world}}
→ Hello, world!
Hello
[edit source]{{#invoke:ArgsDemo|hello|name}}
This function greets the specified user. It uses one argument, name.
Examples:
{{#invoke:ArgsDemo|hello|Fred}}
→ Hello, Fred!{{#invoke:ArgsDemo|hello|Jane}}
→ Hello, Jane!
Add
[edit source]{{#invoke:ArgsDemo|add|num1|num2}}
This function adds two numbers, num1 and num2.
Examples:
{{#invoke:ArgsDemo|add|5|3}}
→ 8{{#invoke:ArgsDemo|add|100|25}}
→ 125
Count fruit
[edit source]{{#invoke:ArgsDemo|count|bananas=number|apples=number}}
This function displays how many apples and how many bananas we have. It uses named arguments.
Examples:
{{#invoke:ArgsDemo|count_fruit|bananas=5|apples=3}}
→ I have 5 bananas and 3 apples{{#invoke:ArgsDemo|count_fruit|apples=7|bananas=4}}
→ I have 4 bananas and 7 apples
Has fruit
[edit source]{{#invoke:ArgsDemo|has_fruit|name|bananas=number|apples=number|cherries=number}}
Displays the number of bananas, apples and cherries a named person has. This function mixes positional arguments with optional named arguments.
Examples:
{{#invoke:ArgsDemo|has_fruit|Fred|bananas=5|cherries=7}}
→ Fred has: 5 bananas 7 cherries{{#invoke:ArgsDemo|has_fruit|Jane|cherries=9|apples=4}}
→ Jane has: 4 apples 9 cherries
Custom fruit
[edit source]{{#invoke:ArgsDemo|custom_fruit|fruit1=number|fruit2=number|...}}
Displays the number of items of different fruit. Any fruit can be displayed; the function is not limited to particular types of fruit as it was in previous functions. This is done by iterating over the arguments. Note that the arguments are processed in an arbitrary order.
Examples:
{{#invoke:ArgsDemo|custom_fruit|pineapples=10|oranges=5}}
→ I have: 5 oranges 10 pineapples{{#invoke:ArgsDemo|custom_fruit|lemons=6|grapefruits=3|bananas=4|grapes=20}}
→ I have: 4 bananas 6 lemons 3 grapefruits 20 grapes
Custom fruit 2
[edit source]{{#invoke:ArgsDemo|custom_fruit_2|name|fruit1=number|fruit2=number|...}}
Displays the number of items of different fruit that a named person has. Similarly to the custom_fruit
function, this function iterates over the arguments, and so is not limited to any particular types of fruit. The difference is that the function checks that each fruit is not the first positional parameter, so that name isn't erroneously listed as a fruit.
Examples:
{{#invoke:ArgsDemo|custom_fruit_2|Fred|pineapples=10|oranges=5}}
→ Fred has: 5 oranges 10 pineapples{{#invoke:ArgsDemo|custom_fruit_2|Jane|lemons=6|grapefruits=3|bananas=4|grapes=20}}
→ Jane has: 4 bananas 6 lemons 3 grapefruits 20 grapes
See also
[edit source]
This is a documentation subpage for Module:ArgsDemo It may contain usage information, categories and other content that is not part of the original module page. |