[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Having trouble with tables...
- From: Leo Razoumov <slonik.az@...>
- Date: Tue, 1 Feb 2011 08:45:20 -0500
On Mon, Jan 31, 2011 at 15:27, Eric Clark <eclark@ara.com> wrote:
> 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.
> Eric
>
Eric,
it is really worth its money to buy "Programming in Lua, 2nd edition"
by Roberto Ierusalimschi. The outdated 1-st edition of the book
covering previous version Lua-5.0 is available online
http://www.lua.org/pil/ for free.
> 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?
After reading chapter on tables and metatables many things will
become clear. E.g. you do not need C/C++ code at all to get/set a
table's metatable.
--file: mt.lua
mt= {a=1, b=2}
mt.__index= mt
tbl= {}
setmetatable(tbl, mt)
print(tbl.a, tbl.b)
--EOF
sh$ lua mt.lua
1 2
--Leo--