Lua Metatables and OOP for dummies (i.e. Me)

Hello!
Despite having read several resources including the official Lua documentation (PIL, etc) about Metatables and OOP in Lua, I still have a difficult time understanding these concepts.

For example - I am looking at the following code on http://lua-users.org/wiki/LuaClassesWithMetatable:

[lua]Lua 5.0.3 Copyright © 1994-2006 Tecgraf, PUC-Rio
> t = { 11, 22, 33, you=‘one’, me=‘two’ }
> mt = { __index = print }
> = t.you
one
> = t.fred
nil
> setmetatable(t, mt)
> x = t.fred
table: 0x8075e80 fred
> = x
nil
> = t
table: 0x8075e80
> [/lua]

Okay, I see that the metatable has provided the ability for the result to be table: 0x8075e80 fred instead of nil. Not to sound rude, by so what? :slight_smile:

i.e. Is there some practical example you all can demonstrate using metatables/OOP, specifically in Corona?

I think I would have a better time understanding metatables and OOP via Corona-related examples, and this would help in understanding Lua in general.

Thank you for your help! [import]uid: 32833 topic_id: 7231 reply_id: 307231[/import]

Right after I posted the above question, I came across a very useful series of Corona SDK tutorials by Dr. Rafael Hernandez on YouTube.

In particular, I found this tutorial on how to create Corona SDK Modules very useful. It is pointing me in the right direction with my project.

Wanted to share with the rest of you in case you haven’t seen it:

Corona SDK 08: External Modules by Dr. Rafael Hernandez
http://www.youtube.com/watch?v=WX1Swovbhms [import]uid: 32833 topic_id: 7231 reply_id: 25417[/import]

A great video!! Thanks for share with us! :slight_smile: [import]uid: 50425 topic_id: 7231 reply_id: 32457[/import]

You might also want to read this great inheritance tutorial posted by Crawl Space Games:

http://www.crawlspacegames.com/blog/inheritance-in-lua/ [import]uid: 52430 topic_id: 7231 reply_id: 32537[/import]