lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Thu, Jun 28, 2012 at 12:24 PM, luciano de souza <luchyanus@gmail.com> wrote:
> At my current stage, your code, Andrew,  sounds very enigmatic for me.
> I don't know how to use metatables. From what I was able to glean,
> it's a very hard subject. But it's also true the bennefits are very
> good. There are lots of things to learn. If I put myself the condition
> to understand metatable to advance in Lua, the results will delay and
> this is very negative for motivation. However, I think you are right.
> I understood how to use Classlib, I like Classlib, handling
> metatables, I will able to create properties.
>
> Cosmin, I took a look in three files you sent me. As there is a large
> quantity of code, I don't know if I will able to decode it. As I know
> only a few of Lua, I have short skill in review codes and make
> conclusions. For this reason, I have prefered to use only well
> documented libraries. Classlib is one of them. the problem is that
> there's no native support for properties.
>
> Well, it's time to study, study and verify if this is the moment to
> use properties!

(Please try to remember not to top-post.)

Metatables aren't as mysterious as it seems. If you're familiar with
Python's metamethods, you can just think of a metatable as being a
table containing metamethods -- a function that handles a.x/a['x']
syntax, a function that handles a.x=y / a['x']=y syntax, et cetera.
You'll learn a couple of idioms for creating "classes" that
automatically assign an appropriate metatable to a table on creation,
and the rest is pretty straightforward.

/s/ Adam