Wikimedia

[Lua task #04] Pass information to your Lua module

To work on this, you must have successfully finished the task "[Lua task #03] Create your own Lua module on English Wikipedia" before!

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 new line (that's the second one) to your sandbox that invokes the function 'Hi' from your module sandbox instead. Save it. You'll be invoking the copy in your module sandbox from here onward.

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 new line (that's the third one) 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 here giving a link to your sandbox.

Task tags

  • lua
  • scribunto

Students who completed this task

Gammaburst_3000, Chen Wuyang, Sai, Liza Amini, Chen Xinpeng, Yajn Bollapragada, Sathvik Hebbar, Sanath, Kid116, OHM OMAR, Tarun Prasad, suufi, Priyanshu Ahuja, Linda Thelen, Jan Nowosielski, Gabriel CH Lee, C. F. Fairfeld, Gabe Mitnick, Rafid Aslam, srflp, Om Desai

Task type

  • code Code
close

2017