[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: question about table elements
- From: jdarling@...
- Date: Thu, 10 Aug 2006 08:54:56 -0700
Ryan, the same is true of your first example and this example.
inodes.tmp is asking for inodes['tmp'] and not inodes[tmp] witch is
what you want. The changes are easy from:
> tmp = db.inode
> print(tmp) --> 2340691
> print(inodes.tmp) --> nil
to:
tmp = dbinode
print(tmp) --> 2340691
print(inodes[tmp]) --> kernlog.0
Using dot notation says give me the element named after the dot. Using
brackets says give me the element named within the brackets. Thus if
you use dot notation with a "variable" name then you are looking for
that variable's name not value. To use the variables value you use
bracket notation.
example:
t1 = {
['a'] = 3,
tmp = 5,
3 = 'three'
}
tmp = t1.a
-- tmp now holds 3
print(t1.tmp) --> 5
print(t1[tmp]) --> three
Does that make more sense?
- Jeremy
"Help I suffer from the oxymoron Corporate Security."