Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
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 U106
Exercises, examples and other material relating to training module U106. This topic is presented on public courses Learning to program in Lua, Lua Programming, Lua Programming

Articles and tips on this subjectupdated
3695Functions are first class variables in Lua and Python
I've been training in Lua and Python this week - and the two languages are very diferent, but in many ways they're also much the same. Both languages are slim (ie not bloated with facilities). For example neither supports the ++ operator which those of us who do a lot of coding in Perl, PHP, C and C++ ...
2949Lua - variable function arguments and select
Lua's select function allows you to look at the variable arguments to your current function. If you're going to be calling a function from different places with different numbers of parameters, you can declare the function with its final parameter being "..." which sucks up the final parameters into ...
2347Dot, dot, dot in Lua - variable length parameter lists
Lua functions can take any number of parameters - the ... (dot,dot,dot) table given as a parameter 'soaking up' all remaining parameters into the indexed section of the table, rather this "*" in front of a parameter in PHP. (In Perl, the whole list appears in @_) function join (sep,...) togo = {...} There ...
2723Returning multiple values from a function - Lua
Does it strike you as odd that in many languages, functions can take in as many parameters as you like, but can only return one? Of course, you can return a single collection object (list, array, tuple, dictionary, hash, Vector, object ...) or set up global variables to hold side effect results if you ...
2455Lua examples - coroutines, error handling, objects, etc
I have presented a bespoke Lua course over the last three days ... and it has lead me to some interesting new examples which I'm sharing here. Object Orientation is more a way of thinking and coding than a language feature in Lua - when you set up a piece of data / structure / object, you do so in a ...
2356Passing multiple results back from a function - Lua, Python, etc
Have you ever wondered why you can pass in as many parameters as you like to a function, but only return one? It seems rather unfair, doesn't it - especially as you may have lots of results. In fact, in some languages such as Lua you can pass multiple values back:   a,b,c = symie(4,7,9) (see ...
2312What are closures in Lua?
When you're writing a sort routine, passing in "a" and "b" to be compared, how do you access other data that's needed in association with a and b? If - for example - a and b are keys to a hash or dictionary or associative array, and you want to sort based on the values in that array? You could make ...
1847Lua - 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 ...
1744Lua 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 - ...
1743First class functions in Lua lead to powerful OO facilities
"In Lua, function names are first class variables." Ok - so what does that mean? At the most direct / simplest, it means that a function can be stored in a variable - so that you can write function oik()   print ("does the real work!")   end and then action = oik action() to ...
1699If you are learning Lua, here are some more examples
During some courses, I write few (if any) new examples in front of my delegates, rather relying on the standard ones in the training notes (which I wrote anyway!) and making small changes and adjustments to illustrate how things work. On other courses, though, I write a some new examples from scratch ...
1697Sorting 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 ...
1685Short circuit evaluation (lazy operator) in Lua
In Lua, if a partial expression evaluates to true the following section will NOT be evaluated if it follows an or because the whole thing cannot be true. If a partial expression evaluates to false, the following section will NOT be evaluated if it follow an and because the whole thing must be true. If ...
Examples from our training material
aaa   A table of functions, calling each in turn
brvret   break v return
cl2d   First Closure demonstration
dress1   The problem of default global
dress2   declaring variables local to avoid global issues
dress3   Code loads at run time not compile time
ex106   excersize - functions
exrate   exchange rate example as a function
fav   Using tables and functions within them
fcv   Dynamic code loading
fsr   Flexible Function Calls
funone   Function calling and definition in Lua
funtwo   global, local and call by value
isd  An adaptive function in Lua
lazy   lazy operators / short circuit evaluation
loadthese.lua   functions to include within a test harness
lomore   variables local to a block
mj   A function to take a lot of parameters or a table
owsort   how sorting via callbacks works
rmv   returning multiple values
selit   variable number of parameters and the select function
size.lua   sample module - exercise answer
slct   Returning multiple results
summer   variable arguments - a function to add up numbers
symet   Symetric Functions
tabasnamed   function call via table
testharness   Loading functions from a file
vargs   Variable number of arguments
yik   Need to use local to reduce cope of variables
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
Defining and calling functions.
Variable scope.
Return values.
Chunks as functions.
Upvalues and Closures.
Variable Argument Lists.
Nesting and passing functions and recursion.
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.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/resources/U106.html • PAGE BUILT: Sun Oct 11 14:50:09 2020 • BUILD SYSTEM: JelliaJamb