title: using a pointer from a C++ object, to another C++ object, to modify member variables, from Lua
body: <p>How do you get a reference to a C++ object, from another C++ object, inside a Lua script? I don't really know how to summarize that in words properly, so let me elaborate with a Lua example first:</p>
  
  <pre><code>function doSomething()
      compo = a:getComponent()
      compo:setVariable(0)
  end
  </code></pre>
  
  <p>a is a C++ object, and the function getComponent returns a pointer:</p>
  
  <pre><code>// inside A.h
  Component* A::getComponent();
  </code></pre>
  
  <p>It seems the problem is that <code>getComponent()</code> is passing a copy of the Component object to Lua, instead of a reference. I come across the same problem with every function that returns a pointer, Lua cannot modify the original object.</p>
  
  <p>Object a seems to be working correctly, if I modify a variable from within Lua, it's outcome is mirrored in C++. Both A and component are bound to Lua already, as well as the required methods.</p>
  
  <p>Am I missing something syntactically or is there more to it than that?</p>
  
  <p>I am using luabind, Lua 5.1, and MinGW. Thanks for any help in advance.</p>
  
  <p>EDIT</p>
  
  <p>Here is the luabind code. I summarized it because there's a bunch of other binds that have no relation to the problem:</p>
  
  <pre><code>luabind::class_&lt;A&gt;("A")
      .def("getComponent", &amp;A::getComponent)
  </code></pre>