title: Point table to another table in Lua
body: <p>is there any way to point table to another table? for example:</p>
  
  <pre><code>local a = {}
  local b = {}
  a.name = "Josh"
  print(a.name) -- Prints 'Josh'
  print(b.name) -- Prints 'Josh' aswell
  a.name = "I don't have a name"
  print(a.name) -- Print 'I don't have a name'
  print(b.name) -- Prints 'I don't have a name' aswell
  </code></pre>
  
  <p>I hope you get my point.. thanks</p>
  
  <p>EDIT:</p>
  
  <p>Okay, so here is the idea:</p>
  
  <p>I am making a dinamic function that is like this</p>
  
  <pre><code>local table = { 1, 2, "hey" }
  
  function drawimage(name, posx, posy referencetable)
      _tabledata[name] = { posx = posx, posy = posy, reference = {}}
      setmetatable(_tabledata[name].reference, { __index = referencetable })
  end
  
  drawimage("Header", 0, 50, table)
  </code></pre>
  
  <p>All good and fine, values work and we are all happy.. the problem occurs when the reference table changes it's value in this way</p>
  
  <pre><code>local data = { 123123, 545454, "heyou" } -- Data is sent from another script via a trigger
  table = data
  </code></pre>
  
  <p>Since I am not updating it by an index (ie: table[1] = 9999) reference variable is 'unsynced' with the real one, I hope you understand :)</p>
  
  <p>EDIT2:</p>
  
  <p>Okay here is a self working example of my main problem</p>
  
  <pre><code>local maintable = { "Stack", "Overflow" }
  local maintablecopy = {}
  
  maintablecopy = maintable
  
  print("maintable[1] = " ..maintable[1]) -- Prints Stack
  print("maintable[2] = " ..maintable[2]) -- Prints Overflow
  print("")
  print("maintablecopy[1] = " ..maintablecopy[1]) -- Prints Stack
  print("maintablecopy[2] = " ..maintablecopy[2]) -- Prints Overflow
  print("")
  
  print("Changing values..")
  local newdata = { "Hello", "World" }
  maintable = newdata
  
  print("")
  print("maintable[1] = " ..maintable[1]) -- Prints Hello
  print("maintable[2] = " ..maintable[2]) -- Prints World
  print("")
  print("maintablecopy[1] = " ..maintablecopy[1]) -- Prints Stack    -- PROBLEM
  print("maintablecopy[2] = " ..maintablecopy[2]) -- Prints Overflow -- PROBLEM
  
  print("Using setmetatable..")
  
  maintable = { "Stack", "Overflow" }
  maintablecopy = {}
  setmetatable(maintablecopy, { __index = maintable })
  
  print("maintable[1] = " ..maintable[1]) -- Prints Stack
  print("maintable[2] = " ..maintable[2]) -- Prints Overflow
  print("")
  print("maintablecopy[1] = " ..maintablecopy[1]) -- Prints Stack
  print("maintablecopy[2] = " ..maintablecopy[2]) -- Prints Overflow
  print("")
  
  print("Changing values..")
  local newdata = { "Hello", "World" }
  maintable = newdata
  
  print("")
  print("maintable[1] = " ..maintable[1]) -- Prints Hello
  print("maintable[2] = " ..maintable[2]) -- Prints World
  print("")
  print("maintablecopy[1] = " ..maintablecopy[1]) -- Prints Stack    -- PROBLEM
  print("maintablecopy[2] = " ..maintablecopy[2]) -- Prints Overflow -- PROBLEM
  </code></pre>
  
  <p>Why I cannot directly point it to the table when the variable updates? becouse I have 20 tables to update, it would be easier to do this</p>
  
  <pre><code>local _dynamics = {}
  
  local tbl1 = { "Hey", 8787 } 
  local tbl2 = { 123, "There" }
  local tbl3 = { "You", 1111 }  
  
  function dynamicFunction(name, posx, posy, textsize, reference)
      _dynamics[name] = { posx = posx, posy = posy, textsize = textsize, reference = reference }
  end
  
  dynamicFunction("first", 0, 0, 5, tbl1)
  dynamicFunction("second", 0, 0, 5, tbl2)
  dynamicFunction("third", 0, 0, 5, tbl3)
  
  for key in pairs(_dynamics) do
      local inf = _dynamics[key]
      for i = 1, #inf.reference do
          print(inf.reference[i])
          if i == #inf.reference then
              print("")
          end
      end
  end
  
  print("")
  print("")
  
  tbl1 = { "aaaaa", "bbbbbbbbbb" }
  tbl2 = { "ccccccccccc", "ttttttttttt" }
  tbl3 = { "rrrrrrr", "yyyyyyyyyyy" }
  
  for key in pairs(_dynamics) do
      local inf = _dynamics[key]
      for i = 1, #inf.reference do
          print(inf.reference[i])
          if i == #inf.reference then
              print("")
          end
      end
  end
  
  print("Values should get updated on the reference variable, but it doesn't.. this would save me     to do a check for every single variable")
  </code></pre>
  
  <p>You can run it on <a href="http://www.compileonline.com/execute_lua_online.php" rel="nofollow">http://www.compileonline.com/execute_lua_online.php</a> to see yourself what I mean.</p>
  
  <p>Sorry if it's a mess but my english is not the best :D</p>