lua-users home
lua-l archive

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

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


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