title: Working with lua objects in c++
body: <p>I want to make something like this:<br>
  1. Create object in Lua<br>
  2. Get this object to C++<br>
  3. Perform some method on this object passing it from C++<br></p>
  
  <hr>
  
  <p>Now I have this in Lua:</p>
  
  <pre><code>Account = {balance = 0}
  
  function Account.Create(name)
      local a = Account:new(nil, name);
      return a;
  end
  
  function Account:new (o, name)
    o = o or {name=name}
    setmetatable(o, self)
    self.__index = self
    return o
  end
  
  function Account:Info ()
    return self.name;
  end
  </code></pre>
  
  <p>Code in C++</p>
  
  <pre><code>//get Lua object
  
  lua_getglobal (L, "Account");
  lua_pushstring(L, "Create");
  lua_gettable(L, -2);
  lua_pushstring(L, "SomeName");
  lua_pcall(L, 1, 1, 0);
  const void* pointer = lua_topointer(L, -1);
  lua_pop(L, 3);
  
  //then I want to perform some method on object
  
  lua_getglobal (L, "Account");
  lua_pushstring(L, "Info");
  lua_gettable(L, -2);
  lua_pushlightuserdata(L,(void*) pointer );
  lua_pcall(L, 0, 1, 0);
  //NOW I GET "attempt to index local 'self' (a userdata value)'
  const char* str = lua_tostring(L, -1);
  ...etc...
  </code></pre>
  
  <p>Do you what I made wrong ? How can I get this Lua object to C++ ?</p>