lua-users home
lua-l archive

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


On Sun, Dec 19, 2010 at 1:37 AM, Eric Clark <eclark@ara.com> wrote:
> Hello All,
>
> I am a pretty new user to developing with Lua and I am having some issues
> trying to set up an inheritance hierarchy with Lua. I have created the
> tables using some code that I found on the internet, but I do not really
> understand the code. It works, but my understanding says it shouldn’t.
> Basically, I have 3 tables: Entity, Model, and PropertySet. The Model and
> PropertySet tables are supposed to inherit the Entity table. From what I
> understand, if I set the __index metamethod in Model’s table to the Entity
> table, then if the Model table is invoked with an invalid key, it will look
> in the Entity table for the same key as long as that table is set in the
> Model’s __index field. Is this correct? If so, could anyone give me some
> sample C/C++ code to show how you actually set the __index field to refer to
> a table?

Hi!
I'm sorry, I won't be able to give you code, as I don't have enough
time, but the following links from "Programming in Lua" should help
you get the answers and confirmations (and there are snippets of code
available there):
- chapter "The __index Metamethod" -- http://www.lua.org/pil/13.4.1.html
- chapter on C API, especially:
  - "Table Manipulation" -- http://www.lua.org/pil/25.1.html
  - "Metatables" (should be valid also for regular tables, not only
for "userdata") -- http://www.lua.org/pil/28.2.html

Hope that helps.
Greetings
Mateusz Czapliński