Page 1 of 1

Stupid Lua Question - Concatenation of Table Name

Posted: 18 Dec 2008, 05:55
by Argh
Basically, I want to do something where I have table0, table1, table2, etc.

I want to refer to those tables by getting a value and matching that with the rest of the table name. However, it seems that table..X doesn't work. How do I correctly address that table?

Re: Stupid Lua Question - Concatenation of Table Name

Posted: 18 Dec 2008, 06:06
by lurker
Seriously? You can't just put them in another table? But okay, as long as they aren't local:
real_G = getfenv()
table = real_G['table'..X]

I worry that I shouldn't be telling you this.

Re: Stupid Lua Question - Concatenation of Table Name

Posted: 18 Dec 2008, 06:15
by Argh
Meh, I'm just trying to avoid a lot of very tedious copy-pasta, basically. Oops, I meant, "oh, my super-secret project requires that I need this". I didn't realize this was non-trivial, tbh, I just figured I was a little slow this evening.

Can't I just get the current index for the table, by getting the [0] value? Or is what you're showing me the only way to make it work? I don't really need this stuff to be global.

Re: Stupid Lua Question - Concatenation of Table Name

Posted: 18 Dec 2008, 06:22
by lurker
Argh wrote:Meh, I'm just trying to avoid a lot of very tedious copy-pasta, basically.
And you cant do that by making a big table with your little tables in it? supertable = {[1] = {}}
Argh wrote:Can't I just get the current index for the table, by getting the [0] value?
That... physically hurt.

The table variable IS the index, you crazy man.

Re: Stupid Lua Question - Concatenation of Table Name

Posted: 18 Dec 2008, 06:33
by Argh
:roll: What can I say? I hate fricking tables, and whenever I try to nest them, horrible things usually result. It's the one part of Lua that never gets any more fun for me.

Re: Stupid Lua Question - Concatenation of Table Name

Posted: 18 Dec 2008, 07:33
by Argh
<pant, pant>

Ok, multiple tables are finally working. Moving on, to the easy part...