Page MenuHomePhabricator

Lua Task 8 - Lua Tables
Closed, DeclinedPublic


Prerequisite: Lua Task 7 - Repeating code. This task requires independent learning and is more difficult.

Lua has one structure - the table - that is used to store arrays, lists, or sets of values. The values may be of any type.

A simple table is demonstrated in and it is tested in

1 Make a copy of the function "mum" in your module sandbox. Save it.

2 Make a new section in your sandbox:

== Task 8 ==

and create a test for your "mum" function. Save it.

3 Amend your code so that it will display "Hello Dad" instead. Check it in your sandbox. (Do the check for each of the following instructions.)

Note that family[i] (where i is a variable containing a number) will refer to the ith member of the "family" table. Arrays in Lua start at 1 by default.

4 Amend your code so that it uses a numeric for loop to go from 1 to 5 to display "Hello " followed by each member of the "family" table.

5 Amend your code so you add two more names to the "family" table. These won't automatically display.

You can find the size of a simple table like "family" by using #family which gives the number of members of the table.

6 Amend your code so that it always displays all of the "family" members.

7 Amend your code so you add one more name to the "family" table. Check that it displays.

8 Leave a comment here linking to your sandbox.

Event Timeline

RexxS created this task.Dec 13 2017, 11:37 PM
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptDec 13 2017, 11:37 PM

I will mentor this in Google-Code-in 2017.

Aklapper closed this task as Declined.Jan 17 2018, 6:28 PM

Closing this task as it was a placeholder in Phab for Google-Code-in-2017 which is ending these days (no more new tasks can be claimed from now on in GCI 2017).