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)
22c0
Associated topics are indexed under
U102 - Lua - Numbers and the Math library. [3917] BODMAS - the order a computer evaluates arithmetic expressions - (2012-11-09)
[2509] A life lesson from the accuracy of numbers in Excel and Lua - (2009-11-21)
[2345] Automatically initialising Lua variables the first time - (2009-08-10)
[1699] If you are learning Lua, here are some more examples - (2008-07-06)
U104 - Lua - Strings and the String library. [2500] Dynamically formatting your results (Lua) - (2009-11-10)
[2357] Checking if the user has entered a number (Lua) - (2009-08-13)
[2348] Finding literals rather than patterns in Lua - (2009-08-11)
U106 - Lua - Functions. [3695] Functions are first class variables in Lua and Python - (2012-04-13)
[2949] Lua - variable function arguments and select - (2010-09-08)
[2723] Returning multiple values from a function - Lua - (2010-04-15)
[2455] Lua examples - coroutines, error handling, objects, etc - (2009-10-15)
[2356] Passing multiple results back from a function - Lua, Python, etc - (2009-08-13)
[2347] Dot, dot, dot in Lua - variable length parameter lists - (2009-08-11)
[2312] What are closures in Lua? - (2009-07-31)
[1847] Lua - IAQ (Infrequently Answered Questions) - (2008-10-18)
[1743] First class functions in Lua lead to powerful OO facilities - (2008-08-07)
[1697] Sorting in lua - specifying your own sort routine - (2008-07-05)
[1685] Short circuit evaluation (lazy operator) in Lua - (2008-06-22)
U108 - Lua - Pattern matching [3687] Binary / bitwise operations in Lua with the standard bit32 library - (2012-04-06)
[2727] Making a Lua program run more than 10 times faster - (2010-04-16)
[2702] First and last match with Regular Expressions - (2010-04-02)
[2383] Lua Regular Expressions - (2009-08-28)
U110 - Lua - Input / Output [3558] Python or Lua - which should I use / learn? - (2011-12-21)
[2344] Reading a data file and sensing EOF in Lua - (2009-08-10)
[1841] Formatting with a leading + / Lua and Perl - (2008-10-15)
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?