Main Content

Lua - IAQ (Infrequently Answered Questions)

Archive - Originally posted on "The Horse's Mouth" - 2008-10-18 17:02:06 - Graham Ellis

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 called with, and can behave differently depending on what they find (Sample program showing a function that can be called with two numbers OR one table as parameters)

• Although Pattern Matching does NOT use regular expressions in Lua, it does use many of the same principles - anchors, literal characters, groups and counts. And it can provide much of the same power but in a far smaller package! (Sample program showing how a postcode is matched and vital sections extracted)

• You can find out what is in a module by looping through its table keys - because (I'm sure you've not forgotten!) everything is a table in Lua (Sample program that lists out everything in the OS module)

You'll find many more sample programs, tips and techniques in our Lua Index. If you start with our Introduction to Lua module page, you'll find some basics. And then down the right hand side of that page, you'll find links to other groups of Lua resources such as Pattern Matching and Combining Lua and C in the same program.