For 2023 (and 2024 ...) - we are now fully retired from IT training. We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.
Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!
I am also active in many other area and still look after a lot of web sites - you can find an index ((here)) |

Well House Consultants
You are on the site of
Well House Consultants
who provide
Open Source Training Courses
and business
hotel accommodation. You are welcome to browse and use
our resources subject to our copyright statement and to add in links from your pages to ours.
Other subject areas - resources
Java Resources
Well House Manor Resources
Perl Resources
Python Resources
PHP Resources
Object Orientation and General topics
MySQL Resources
Linux / LAMP / Tomcat Resources
Well House Consultants Resources
Extras Resources
C and C++ Resources
Ruby Resources
Tcl/Tk Resources
Web and Intranet Resources
|
Lua module U105
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, Lua Programming
Articles and tips on this subject | updated | 4571 | Lua - using modules to add your own utilities Lua is a small language ... but that doesn't mean it lacks capabiities - it just means that you need to write some code yourself to implement simple utilities that you would cherry pick from huge libraries in other languages.
For example from this week's course, I've written functions to split a line ... | 2015-11-05 | 4273 | Dot or Colon separator between table name and member in Lua - what is the difference? When do I use a dot and when do I use a colon in referencing a table member in Lua? It's a good question and one that we answer (and demonstrate to help make clear) on our Lua Programming Course.
Dot refers to a table member. So if I write
source.read()
I am saying "run the read function ... | 2014-05-06 | 4248 | Metatables, Metamethods, classes and objects in Lua In Lua, almost everything (!) is held as a table. You don't have lists, hashes, dicts, arrays, objects, namespaces - you have tables. It helps consistency, in helps keep the language small - but at times it does mean you have to be a little bit more aware of how the features of tables can be combined ... | 2014-03-20 | 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 |
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 | sf3 | Read file, split line, tables of tables | 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 [here].
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
Ruby,
Lua,
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.
|
|
|