-1

Am I able to make a separated table filled with elements from other tables in Lua? Like this:

TableA = { a=1, b=2, c=3 }
TableB = { John=4, Jane =5 }
TableC = { x = "asd", y = "dsa", z = "sda" }

TableAll = { TableA.a, TableB.John, TableC.x}

It's a general example, but may work. I'm not sure in it.

Yu Hao
  • 119,891
  • 44
  • 235
  • 294
Zoltán Schmidt
  • 1,286
  • 2
  • 28
  • 48
  • 1
    I don't quite follow the issue you're having. Your code above seems *[to work](http://codepad.org/Akpo9FJh)*. Are you expecting different output? – greatwolf Aug 15 '13 at 01:25
  • @greatwolf I didn't know what to expect. I just wasn't sure that a table can reach another's key-value pairs. I know that I should have tried to run the code but I think thought that if I ask it, this question might be useful for beginner LUA users later. – Zoltán Schmidt Aug 15 '13 at 09:54

1 Answers1

2

Is there some reason why that wouldn't work?

All that tablename.key does is access an element of a table. This is a value; the fact that it came from a table is completely irrelevant. The value returned by tablename.key is no different than the value 5, nil, true, "some string", or any other value in Lua.

You can initialize a table with values; it doesn't matter where those values come from.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
  • If I'd know, why it wouldn't work, I either would answer my own question, or wouldn't even ask it. ;) thank you anyway! I just wasn't sure that a table can reach another's key-value pairs. – Zoltán Schmidt Aug 15 '13 at 00:52