Exercises, examples and other material relating to training module U108. This topic is presented on public courses Learning to program in Lua
, Lua Programming
, Lua Programming
|Articles and tips on this subject
|Changing what operators do on objects - a comparison across different programming languages
In Object Oriented languages, you used named pieces of code known as methods to perform an operation on a variable - for example you might write
to take a list of (something) for a week and add a list relating to weekend onto the end of it.
Sometimes, the method ...
|Binary / bitwise operations in Lua with the standard bit32 library
If you want to do bit manipulation in Lua, you can use the bit32 library (which is loaded as a table) from Lua 5.2, and it's backported to newer Lua 5.1 versions as well. Bit manipulation is particularly useful in applications where data is packed into a series of bytes - in effect an array of booleans.
|Lua Regular Expressions
OK - don't believe the headline - Lua doesn't support "Regular expressions" but it does have pattern matching. Why? Because Lua is designed to have a small footprint, and a conventional Regular Expression library would be 'bloat' - the pattern matching that's provided looks similar, and offers 80% ...
|Making a Lua program run more than 10 times faster
I made an extraordinary claim on Thursday. One of my delegates had written a program that analyzed a huge data file in a Lua script, and it was taking over half an hour to run. "Give me five minutes, and I could have that running in less that five minutes" I claimed.
It was all to do with pattern ...
|First and last match with Regular Expressions
Conventional Wisdom says that it's pointless to start a regular expression with ".*" or ".+", as this is implied within a match - regular expression matches are looking for strings that are contained anyway:
'/abc/' - contains abc
'/.*abc/' - contains anything or nothing, followed by abc
However - ...
|Lua - IAQ (Infrequently Answered Questions)
Here are a handful of "one line" answers from the end of the Lua Course I was running at the end of last week
• Command line parameters in Lua are available to the program in an indexed table called arg. (Sample Program)
• Functions in Lua can look at the number and type of parameters they're ...
|Lua examples, Lua Courses
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 - ...
Examples from our training material
| Pattern substitute, pattern match and extract
| Pattern matching in Lua (not Regular Expressions)
| Anchoring and delimiting patterns
| iterating through a string, choosing a pattern
| Pattern match and extract - a postcode
| Pattern matching - SLOW code
| Pattern matching - FAST code
| split or explode in Lua
| String Pattern Matching
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
Anchors, literal characters, counts and groups.
Capturing matchs, capturing all the matches (global)
Pattern Based functions.
If you are looking for a complete course and not just a information on a single subject, visit our Listing and schedule
Well House Consultants specialise in training courses in
. We run
throughout the UK (and beyond for longer courses), and
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.