Programming training is much more effective if the delegates are shown
how a particular program is written, rather than just the final result ... show them just the final result and they'll ask "but how did you come up with that?"
So whenever possible, I write new examples in front of my delegates - spill my guts if you like, describing what I'm writing, and what my logic is behind it. The result is that - by the end of the course - I have a whole folder full of new examples which I then sent through (zipped) to the delegates for them to use as post-course material in addition to the more formal printed notes.
After the three day Lua course in central London that finished yesterday evening, I took the long way round on my way home - a leisurely train ride via Waterloo and Salisbury to Trowbridge, and that gave me the opportunity to tidy up my examples - add in some more comments, and some sample output ... and I've added the better ones to our web resources - and here that are:
furry - Calculations / good variable naming conventions
prncr - Output of a prompt without a new line
wcd - exchange rate loop
whilly - while loop - break and alternative
andor - combining and / or operators
moopark - theme park entrance prices
stem - simple string function use
tat - pairs v ipairs
cleversort - Sorting using a user defined comparator
party - building up a table as data is entered
fav - function as table member - polymorphic tables
dress1 - function call - simple example
dress2 - local variables in a function
dress3 - conditional function definition
fsr - variable number and type of parameters
cuboid - Using a demonstration class
newCube.lua - A demonstration class definition
iiapc - Pattern Match to Postcode, with capture
skill_lister - Read, analyse, sort data from file
I started this article saying how much more effective training is when you see he examples developed interactively, and yet I have now shown them to you as "final results only". However, with the comments I have added they are still a good resource for delegates who have taken some steps in Lua already, or who are geeks who lap up this stuff. If you look at them and think "I wish I could write code like that" ... the come along on our
public Lua course or book me for
a private course if you've a group of four or more.
(written 2008-08-08, updated 2008-08-09)
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
U110 - Lua - Input / Output [1841] Formatting with a leading + / Lua and Perl - (2008-10-15)
[2344] Reading a data file and sensing EOF in Lua - (2009-08-10)
[3558] Python or Lua - which should I use / learn? - (2011-12-21)
U108 - Lua - Pattern matching [1847] Lua - IAQ (Infrequently Answered Questions) - (2008-10-18)
[2383] Lua Regular Expressions - (2009-08-28)
[2702] First and last match with Regular Expressions - (2010-04-02)
[2727] Making a Lua program run more than 10 times faster - (2010-04-16)
[3687] Binary / bitwise operations in Lua with the standard bit32 library - (2012-04-06)
[4366] Changing what operators do on objects - a comparison across different programming languages - (2014-12-26)
U106 - Lua - Functions. [1685] Short circuit evaluation (lazy operator) in Lua - (2008-06-22)
[1697] Sorting in lua - specifying your own sort routine - (2008-07-05)
[1699] If you are learning Lua, here are some more examples - (2008-07-06)
[1743] First class functions in Lua lead to powerful OO facilities - (2008-08-07)
[2312] What are closures in Lua? - (2009-07-31)
[2347] Dot, dot, dot in Lua - variable length parameter lists - (2009-08-11)
[2356] Passing multiple results back from a function - Lua, Python, etc - (2009-08-13)
[2455] Lua examples - coroutines, error handling, objects, etc - (2009-10-15)
[2723] Returning multiple values from a function - Lua - (2010-04-15)
[2949] Lua - variable function arguments and select - (2010-09-08)
[3695] Functions are first class variables in Lua and Python - (2012-04-13)
U104 - Lua - Strings and the String library. [2348] Finding literals rather than patterns in Lua - (2009-08-11)
[2357] Checking if the user has entered a number (Lua) - (2009-08-13)
[2500] Dynamically formatting your results (Lua) - (2009-11-10)
[4274] String formatting in Lua - string.format as a wrapper for sprintf - (2014-05-07)
U102 - Lua - Numbers and the Math library. [2345] Automatically initialising Lua variables the first time - (2009-08-10)
[2509] A life lesson from the accuracy of numbers in Excel and Lua - (2009-11-21)
[3917] BODMAS - the order a computer evaluates arithmetic expressions - (2012-11-09)
[4569] Lua - changes to how integers and floats are handled - 5.2 to 5.3 - (2015-11-02)
Some other Articles
Hotel room prices - Melksham, WiltshireWho is watching you?London for the visitor, for freeMoodle, Drupal, Django (and Rails)Lua examples, Lua CoursesLua - Table elements v table as a wholeAge ConcernVertical LondonBath, Snake or Nag?