[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: question about table elements
- From: "Chris Poole" <chris@...>
- Date: Thu, 10 Aug 2006 16:58:48 +0100
Hi Ryan,
I believe what you are looking for is
print(inodes[tmp])
As this uses the contents of temp as the key, rather than inodes.tmp
which would be equivalent to inodes['tmp']
Best regards,
Chris
> -----Original Message-----
> From: lua-bounces@bazar2.conectiva.com.br
> [mailto:lua-bounces@bazar2.conectiva.com.br] On Behalf Of Ryan Cresawn
> Sent: 10 August 2006 16:31
> To: Lua list
> Subject: Re: question about table elements
>
> Lua list,
>
> I think it's important that I explain the problem I'm trying
> to solve a little more clearly. I am writing a Lua script
> that is designed to monitor a log file and mail me the new
> content when it is found. The script is designed to run from
> cron and it is necessary that it account for the possibility
> that the log could be rotated.
>
> The real code which is similar to 't2' in the example is a
> persistent table that looks like this:
>
> db {
> ["inode"] = "2340691",
> ["pos"] = 9,
> }
>
> The 't1' equivalent is the output of 'ls -i1 /var/log'. I
> grab the inode and the file and enter them into a table
> called 'inodes'. The key is the inode and the value is the
> filename. A short version of the 'inodes' table looks like this:
>
> inodes {
> ["2299409"] = "kernlog",
> ["2340691"] = "kernlog.0",
> }
>
> My goal is to view the value stored in 'db.inode' and then
> find the filename to open in the 'inodes' table. I had hoped
> to do something like this:
>
> tmp = db.inode
> print(tmp) --> 2340691
> print(inodes.tmp) --> nil
>
> This fails and I have not come up with a way to circumvent
> it. Any ideas?
>
> Ryan
>
>
> On Thu, Aug 10, 2006 at 10:48:46AM -0400, Ryan Cresawn wrote:
> > Lua list,
> >
> > I'm having a difficult time accessing table elements and I would
> > appreciate some help. The code below is test code but it
> behaves the
> > same way that my larger program does.
> >
> > -- begin example --
> >
> > t1 = {
> > ["a"] = 1,
> > ["b"] = 2,
> > ["c"] = 3,
> > }
> >
> > t2 = {
> > ["x"] = "a",
> > }
> >
> > tmp = t2.x
> > print(tmp) --> a
> > print(t1.tmp) --> nil
> >
> > -- end example --
> >
> > How could I achieve the goal of using the value stored in 't2.x' to
> > access 't1.a'? I suspect I'm overlooking something simple
> and would
> > appreciate any advice you may offer.
> >
> > Ryan
>
>
>
>