Module:ArgsDemo/doc

This is an example module that demonstrates how to access arguments. It is used in Scribunto: An Introduction.

Hello world
&#123;{#invoke:ArgsDemo|hello_world}}

This function displays the text "Hello, world!". It doesn't use any arguments.

Example:


 * &rarr;

Hello
&#123;{#invoke:ArgsDemo|hello|name}}

This function greets the specified user. It uses one argument, name.

Examples:


 * &rarr;
 * &rarr;

Add
&#123;{#invoke:ArgsDemo|add|num1|num2}}

This function adds two numbers, num1 and num2.

Examples:


 * &rarr;
 * &rarr;

Count fruit
&#123;{#invoke:ArgsDemo|count|bananas=number|apples=number}}

This function displays how many apples and how many bananas we have. It uses named arguments.

Examples:


 * &rarr;
 * &rarr;

Has fruit
&#123;{#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:


 * &rarr;
 * &rarr;

Custom fruit
&#123;{#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:


 * &rarr;
 * &rarr;

Custom fruit 2
&#123;{#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  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:


 * &rarr;
 * &rarr;