Page MenuHomePhabricator

[Lua task #4] Passing information to your Lua module
Closed, DeclinedPublic

Description

Prerequisite: Lua Task #3

Lots of uses of modules in Wikipedia require some information from the page where they are placed. We call information passed to a function a "parameter".

1 Examine https://en.wikipedia.org/wiki/Module:Sandbox/RexxS/SayHello - you should see a function called 'Hi'. Copy that function into your module sandbox. You already have the first and last lines, so you just need to copy the function, but make sure you copy it before the last line

return p

2 Edit your sandbox to add this line at the end:

{{#invoke:Sandbox/RexxS/SayHello|Hi|name=Andy}}

Save it and observe the result. The word 'Andy' is passed as the value of the parameter called 'name'.

3 Add another line to your sandbox that calls the function 'Hi' from your module sandbox instead. Save it.

4 Edit that line to change the name from Andy to your name. Save it.

5 Change your module sandbox so that the first line inside the function 'Hi' reads

strName = frame.args.name or "Jimbo"

Save it.

6 Add another line to your sandbox that is a copy of the previous line but without |name=Andy. Save it.
We use the 'or' operator to supply a default that is used if no parameter is given.

7 Leave a comment giving a link to your sandbox.