There's a general problem within your code. So let's do some basics:
You are mixing up integer and string table indices.
If you declare a table with
Code:
MYTAB = {'FRED1','FRED2','FRED3',...
(only values, without indices) then you automatically build a table with integer indices.
The result is this:
Code:
MYTAB = {
[1] = 'FRED1',
[2] = 'FRED2',
[3] = 'FRED3',
...
}
Now let's see your code:
Code:
for key in pairs(MYTAB) do
_,_,rest = strfind(key,"FRED(.*))
...
end
It will never work.
The construction
Code:
for k,v in pairs(t) do <stuff> end
will iterate over all key–value pairs of table t. Mind the
k,v part! With
the table constructor
Code:
MYTAB = {'FRED1','FRED2','FRED3',...
which is equal to
Code:
MYTAB = {
[1] = 'FRED1',
[2] = 'FRED2',
[3] = 'FRED3',
...
}
and with the expression
Code:
for key in pairs(MYTAB) do
you will get the keys only - which are just integer numbers. So your code
Code:
strfind(key,"FRED(.*))
won't work as expected.
Furthermore you can't access the table value via
Code:
MYTAB['BARNEY'..rest]
This is because 'BARNEY'..rest is a string index. But you build your inital table
with integer indices only (because you didn't specify any indices ... only values)
The only way to access the table
Code:
MYTAB = {'FRED1','FRED2','FRED3',...
is via integer indices:
Code:
MYTAB[1] --returns the string "FRED1"
In conclusion this means:
1. There are two possible table index types: integers and strings. Don't mix them up.
I kindly ask you to read the "Programming in Lua" handbook section about tables
(
http://www.lua.org/pil/2.5.html). I'm almost sure this will clarify a lot.
2. If you use string as indices (keys), then it is not possible to "change" them. You
could only change the values the keys are pointing to. (the only way is to remove
the old indices and to create new ones)
Hope this is somehow helpful for you.