Tables and the table library.
Exercises, examples and other material relating to training module U105. This topic is presented on public courses
Learning to program in Lua,
Lua Programming
| Articles and tips on this subject | updated |
| 3725 | Lua Tables Lua's Tables are its "collection" variables - in other words, they hold a whole series of other variables, which can be looked up by a key of some sort.
I can set up a table like this:
occupancy = {2,5,5,3,2}
which will set up a Lua variable called "occupancy" with five members, numbered ... | 2012-05-12 (longer) |
| 3694 | Special __ methods you can use in Lua metatables In Lua, you can associate an additional table (known as a metatable) with each table of data and code you have. By doing so, repeated values and functions that apply across as whole series ("type", "class") of tables only have to be defined once. A very neat way for Lua to provide the OO facilities ... | 2012-04-12 |
| 2703 | Lua Metatables In a recent article ([here]), I asked if Lua was an object oriented language - and I concluded that it supports the OO paradigm very well, even though it doesn't have keywords like "class", "private" or "extends". At the end of that article, I mentioned metatables - a subject I have carefully sidestepped ... | 2010-04-02 |
| 2699 | Lua tables - they are everything In PHP, it sometimes feels like the answer to every question is "there's a function to do that" and in Lua, it seems the answer is always "it's a table" or "use a table"!
I'm running a Lua course this week, and I have just posted up an example in which I set up a table and showed some of the flexibilities ... | 2010-03-31 |
| 2499 | ourdog is Greyhound, Staffie and Ginger Cake It was the fact that the cake wrapper was on the bed, and not on the bedside table that was the clue that triggered me to realizing that something wasn't quite where I had left it. And examining the wrapper and finding it empty and clear, I realised that something else - the remaining slice of cake ... | 2009-11-10 |
| 2346 | The indexed and hashed parts of a Lua table A Lua table contains both a sequentially indexed section and a hash keyed section (and a few other things too). When you sort the table, you sort only the index keyed section, when you use ipairs you use just the first (indexed) section, but when you use pairs you use the whole table. See source code ... | 2009-08-12 |
| 1742 | Lua - Table elements v table as a whole Lua ... If you refer to a table name WITHOUT square brackets, you are referring to (and will effect) the whole table ... but if you refer to a table name and put something thereafter in square brackets, you are referring to just one element of the table. Actually, an almost identical story applies to ... | 2008-08-07 |
| 1697 | Sorting in lua - specifying your own sort routine In Lua, the table.sort function allows you to sort a table and by default is sorts into the order that's given back by the < operator on each of the objects to be sorted. If you want to override this behaviour, you can pass the name of a function into Lua's sort and it will call this function each ... | 2008-07-05 |
22b1
Examples from our training material
| asort | Sorting an Associative table |
| cleversort | Sorting with a user defined routine |
| clo_demo | User defined sorting in Lua |
| clone | Duplicate (clone) a table |
| duh | What is in a table? |
| imex | implode in Lua |
| moretab | Getting the minimum number from a table |
| ooco | Assignment of a table - by reference |
| party | Read and store data until we get a blank line |
| ph | pairs, ipairs and #tablename iteration |
| settab | Set up a table, output in reverse |
| sorting | Sorting tables |
| spjo | Split and Join a string into / from a table |
| synsug | . v ["...."] v insert |
| t1 | mixing associative and normal in table |
| taba | Tables as associative arrays |
| tabo | Tables - some basics |
| tat | whole table v single member, pairs v ipairs |
| tinies | Reading a file and creating a table |
Background information
Some modules are
available for download as a sample of our material or under an
Open Training Notes License for free download from
http://www.training-notes.co.uk.
Topics covered in this module
Introduction.
Tables as arrays.
Table equality and copying.
Sort, Concatanate, remove and others.
Table Traversal Functions.
Building other structures from tables.
Complete learning
If you are looking for a complete course and not just a information on a single subject, visit our
Listing and schedule page.
Well House Consultants specialise in training courses in
Python,
Perl,
PHP, and
MySQL. We run
Private Courses throughout the UK (and beyond for longer courses), and
Public Courses at our training centre in Melksham, Wiltshire, England.
It's surprisingly cost effective to come on our public courses -
even if
you live in a different
country or continent to us.
We have a technical library of over 700 books on the subjects on which we teach.
These books are available for reference at our training centre. Also
available is the Opentalk
Forum for discussion of technical questions.