[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: is "__metatable" an event similar to "__gc" and "__tostring" or is it a convention?
- From: "Vijay Aswadhati" <wyseman@...>
- Date: Sat, 5 Jul 2003 22:27:27 -0700
I have been studying some of the examples such as
"UserDataWithPointerExample"
on the Wiki as well as some real code like the gdbm binding by LHF. To
support
object:method() syntax, LHF adds a "metatable" key to the "gdbm" table in
"C"
and then in "gdbm.lua" he has a statement like this:
gdbm.metatable.__index=gdbm
which is what is allowing the object:method() syntax to work; I am guessing
since this whole metatable business is still very unclear to me.
Whereas in the case of "UserDataWithPointerExample", the "IMAGE" table's
metatable gets an "__index" as well as "__metatable" keys both of them set
to the value of the "IMAGE" methods in "C".
The question finally. Could someone clarify in more elaborate terms all
this metatable magic and which of the two approaches are better. In terms
of understanding, I can atleast follow blindly "UserDataWithPointerExample"
and in fact got my own bindings working.
I tried LHF's approach and found out obviously it works as well, however
I am unable to figure out what exactly is the magic behind the statement
"gdbm.metatable.__index=gdbm"
Vijay Aswadhati