tags:

views:

73

answers:

2

I've never been able to fully wrap my mind about how Lua uses metatables to implement Object Orientation in its programming. I've been reading over the online tutorial directory trying to understand, however the author wrote it with experienced programmers in mind, in which I am not. With abstract ideas and not-noob-friendly variables and explanations, going's been a little tough. Here is a link to the Object Orientation page on Lua's website.

Can anyone give a noob-friendly explanation of how to implement it? I'm doing some scripting for a game I play (not WoW), and I'd like to make my code better by using it. Thank you!

+3  A: 

There are many ways to code up an OO feel in Lua. Lua goes for mechanism, not policy. The best possible source is the chapter in Roberto's book on Object-Oriented Programming. Definitely noob-friendly. Great book. The link is to the previous edition, which is free online. But you will want to buy the latest edition :-)

Norman Ramsey
A: 

Disclaimer: I'm the developer of MiddleClass

I've developed a library for people like you. It's called MiddleClass.

It conveniently hides the metatables so you can concentrate on object-oriented stuff. It's also reasonably commented out, should you want to take a look underneath.

There's also a wiki page explaining how to use it.

egarcia