title: Lua is it possible to return a reference to an element inside of a table?
body: <p>Lets say that I have a simple table, this table has another table inside of it that contains other values.
  For simplicity here is the layout:</p>
  
  <pre><code>local a = {b = {X = 123; Y = 321; Z = 456;}};
  </code></pre>
  
  <p>I have a function that is <em>supposed</em> to return a reference to the given value in the table a.b.</p>
  
  <pre><code>local function GetRef(member)
      --return a reference to a.b[member]
  end
  </code></pre>
  
  <p>The reason I need to call GetRef is because another function that calls it needs to be able to assign a new value to the supplied value inside of the table:</p>
  
  <pre><code>local function AssignValue(key, value)
      local ref = GetRef(key);
      ref = value;
  end
  </code></pre>
  
  <p>Now you <em>could</em> ask "why dont you just return a.b, and type ref[key] to assign it in the assign function instead?", and I <em>could</em> do that, however I wouldn't be learning anything new if I did just decide to implement what I am trying to implement that way now would I?</p>
  
  <p>I would appreciate any help.</p>
  
  <p>Thanks</p>