
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 U107
Object Orientation - the Lua way
Exercises, examples and other material relating to training module U107. This topic is presented on public courses Learning to program in Lua, Lua Programming
| Articles and tips on this subject | updated | | 3524 | Metaclasses (Python) and Metatables (Lua) "A Metaclass (Python) or Metatable (Lua) adds extra code / data / behaviour to an object, table, or class."
What does that mean? It means that I can define a behavior that I want to be shared, that I want to define at run-time, that I want to amend ... in a separate module / zone / table from my main ... | 2011-12-03 | | 3396 | Tables as Objects in Lua - a gentle introduction to data driven programming In Lua, everything that's a collection is held in a table. During the Lua Course I have been giving this week, I set up a whole series of tables, object-like, to hold details of each station on the British main rail network. As well as data, the table holds code / code references, and by adding different ... | 2011-08-17 | | 3142 | Private and Public - and things between A public train service is one which is available for anyone to travel on; a private one only takes limited passengers as invites / made available by the operator. And there could be intermediate levels too - I understand that at times the British Transport Police protect the last train from Weymouth ... | 2011-01-25 (longer) | | 2710 | __index and __newindex in Lua - metatable methods When you call up an element in a table in Lua, it's like accessing an array element - and it works well. But you can go further by associating a metatable with a table - that's another table with a whole lot of extras - and that allows you to alter the behaviour of the original table. Since Lua works ... | 2010-04-05 | | 2701 | Is Lua an Object Oriented language? Lua isn't an object oriented languages in the sense that you define classes, create objects with a new method, define interfaces and declare variables to be private or protected ... but never the less is a tool in which you can use object oriented techniques with (indeed) a freedom and flexibility that ... | 2010-04-02 | | 2703 | Lua Metatables In a recent article ([here]), I asked if Lua was an object oriented language - and I concluded that it supports the OO paradigm very well, even though it doesn't have keywords like "class", "private" or "extends". At the end of that article, I mentioned metatables - a subject I have carefully sidestepped ... | 2010-04-02 | | 2455 | Lua 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 ... | 2009-10-17 | | 2359 | A fresh example - objects the Lua way One of the requirements we often have in our web server log file analyses is to connect together a series of accesses from a single IP address into a "visit", and this formed an example on Tuesday's Lua course.
In Lua, you can overload (i.e. redefine) operators so that they work differently on tables ... | 2009-08-13 | | 2318 | For Lua Programmers AND for Town Planners I'm always happy to be able to make multiple use of the same piece of work, and so it is with an example written last week.
READ THIS SIDE ... if you are a Lua or game programmer
I was asked to provide an exercise during the Lua course that related to game playing - where a series of elements (of ... | 2009-08-04 (longer) | | 1819 | Calling base class constructors In all object oriented languages, you have a facility called inheritance where you can define one type of thing ("class of object") based on another, and the newly defined class ("subclass" or "extended class") takes the initial ("base") class as it starting point.
In your code for your base class, ... | 2008-10-03 | | 1743 | First 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 ... | 2008-08-07 | | 1699 | If 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 ... | 2008-08-05 | | 1692 | Towards Object Oriented Programming in Lua I've spent a lot of the weekend working on our Lua course ... and for those of you new to this language I'll be sharing a few snippets with you here on "The Horse's Mouth" over coming weeks. Today, I've got a short section which starts to introduce how you can do OO programming in Lua. The section ... | 2008-06-30 |
Examples from our training material
| Cube.lua | Definition of a cube object | | Dice.lua | Definition of a dice object - Inheritance | | Sphere.lua | Definition of a sphere object | | alog | Program to use visit objects | | anim_o1.lua | Tables to associate functions with data | | animals.lua | Using a metatable to define print, <, etc | | couples | Moving towards Lua objects - Metatables | | cuboid | Illustrates use of a class of objects | | dibdab | We can keep funtions in a table too | | index_123 | __index and __newindex | | lottaob | Polymorphism in Lua - table of objects of different types | | meta1 | preparations for metatables - this is just a table | | meta2 | Simple use of a metatable to create a class | | meta3 | creating and using a table of tables("objects") | | meta4 | redefining operators | | metamid | Adding user methods via a metatable | | metapetite | Overriding an operator on a table | | metasmall | Metatable to change a table characteristics | | metatiny | Metatables - the mechanism | | newCube.lua | Definition of a class in Lua | | oblet | Hello Object World | | obtable | Polymorphism in Lua - table of objects of different types | | rail5 | a table for each station | | visit.lua | definition of visit objects | | zoo.txt | Sample data file for animal demo |
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 http://www.training-notes.co.uk.
Topics covered in this module
Mutable and Immutable Values. MetaMethods and functions as members Metatables, __index, __add and __lt Polymorphism and inheritance
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
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. Also
available is the Opentalk
Forum for discussion of technical questions.
|