Main Content

If you are learning Lua, here are some more examples

Archive - Originally posted on "The Horse's Mouth" - 2008-07-06 11:13:25 - Graham Ellis

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 - and such was the case during last Thurday and Friday's two day Lua training class.

Here - primarily for the delagates in that class - are links to the many of the new examples, which I have added to our on line resource. If you follow the links to any of these, you'll be offered links to other related examples too!

Lua Fundamentals

Comments in Lus
Simple sting.format example
for loop example in Lua
strip.rep to repeat a string
getting the minimum value from a table in Lua
Pattern Matching -getting names from amongst a stream of punctuation

Lua functions and modules

Variable number of arguments to a function
Lua functions to return larger of two values and largest of a table of values
How sorting works in Lua - looking under the counter
A Lua program that calls in a module and the module itself
An function which could usefully be turned into a coroutine and that example amended to run as a coroutine

Towards Object Orientation in Lua

A reminder of tables
Adding Lusa's metables to change functionallity
Creating and using a table of Lua 'objects'
Redefining operator behaviour on tables in Lua

Lua is a really excellent language with a small "footprint" - the more I use it, the more I like it (and I like it a lot!). You won't find the "bloat" of other open source languages, but you WILL find nifty and useful features which come together to make it a very valuable programming tool; it's this feature set that has led to its widespead adoption in the games industry where (for example) it's used in "The world or Warcraft" to customise the user interface.