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.
Some other articles
U114 - Threading and Coroutines. Embedding Lua to perform tailored code at an interval Parallel but not really parallel. Moving game characters. Coroutines in Lua. Lua examples - coroutines, error handling, objects, etc Passing parameters to a coroutine in Lua What to do with a huge crop of apples This article Co-routines in Lua - co-operative processing U109 - Modules Lua - using modules to add your own utilities Lua examples - coroutines, error handling, objects, etc Encapsulating shared code in a Lua module This article U107 - Object Orientation - the Lua way Lua, Tcl, Python, C and C++ courses - at our Melksham HQ or on your site - forward from July 2017 Classic style OO code - in Lua Tables with values and code in Lua - looks like an object? Dot or Colon separator between table name and member in Lua - what is the difference? Metatables, Metamethods, classes and objects in Lua Is Lua an Object Oriented language? What is a metatable? How do I set one up? How do I use them? Lua Using Lua tables as objects Special __ methods you can use in Lua metatables Weak references in Lua - what are they, and why use them? Metaclasses (Python) and Metatables (Lua) Tables as Objects in Lua - a gentle introduction to data driven programming Private and Public - and things between __index and __newindex in Lua - metatable methods Lua Metatables Is Lua an Object Oriented language? Lua examples - coroutines, error handling, objects, etc A fresh example - objects the Lua way For Lua Programmers AND for Town Planners Calling base class constructors First class functions in Lua lead to powerful OO facilities This article Towards Object Oriented Programming in Lua U106 - Functions. Functions are first class variables in Lua and Python Lua - variable function arguments and select Returning multiple values from a function - Lua Lua examples - coroutines, error handling, objects, etc Passing multiple results back from a function - Lua, Python, etc Dot, dot, dot in Lua - variable length parameter lists What are closures in Lua? Lua - IAQ (Infrequently Answered Questions) Lua examples, Lua Courses First class functions in Lua lead to powerful OO facilities This article Sorting in lua - specifying your own sort routine Short circuit evaluation (lazy operator) in Lua U102 - Numbers and the Math library. Lua - changes to how integers and floats are handled - 5.2 to 5.3 BODMAS - the order a computer evaluates arithmetic expressions A life lesson from the accuracy of numbers in Excel and Lua Automatically initialising Lua variables the first time Lua examples, Lua Courses This article U101 - Introduction to Lua. Learning to program - variables and constants Line, block and nested comments - Lua compared to other languages Learning to Program in Lua - public / open training course / class Learning to write high quality code in Lua Lua Course, and the Wiltshire Countryside too Rules, suggestions, considerations for Lua variable names This article Lua Course - here is the index Training in Lua