title: Is it possible to access Lua table elements using a c pointer?
body: <p>I call a C function in Lua passing an array/table to it as argument:</p>
  
  <pre><code>tools:setColors({255,255,0})
  </code></pre>
  
  <p>In the C function I get the size of:</p>
  
  <pre><code>if (lua_gettop(state) == 2 &amp;&amp; lua_istable(state, -1))
  {
      lua_len(state, -1);
      int count = lua_tointeger(state, -1);
      lua_pop(state, 1);
  }
  </code></pre>
  
  <p>Instead of iterating over the table is it possible to get the C pointer to that array to use it later for <code>memcpy</code>? Or maybe there is another way to copy data directly?</p>
  
  <p><strong>update:</strong>
  What I actually try to do, so maybe someone has a better solution...
  In my Lua script I do some calculation with the colors. The RGB values of all colors are saved in the one big table (example above would mean one color). This table is passed back to my C code with setColors call, where I normally would copy it using memcpy to a std::vector (<code>memcpy(_colors.data(), data, length</code>);
  At the moment I do the following:</p>
  
  <pre><code>    // one argument with array of colors (triple per color)
      lua_len(state, -1);
      int count = lua_tointeger(state, -1);
      lua_pop(state, 1);
  
      for (int i=0; i &lt; count / 3; i++)
      {
          ColorRgb color; // struct {uint8_t red, uint8_t green, uint8_t blue}
          lua_rawgeti(state, 2, 1 + i*3);
          color.red = luaL_checkinteger(state, -1);
          lua_pop(state, 1);
  
          lua_rawgeti(state, 2, 2 + i*3);
          color.green = luaL_checkinteger(state, -1);
          lua_pop(state, 1);
  
          lua_rawgeti(state, 2, 3 + i*3);
          color.blue = luaL_checkinteger(state, -1);
          lua_pop(state, 1);
          _colors[i] = color;
      }
  </code></pre>
  
  <p>seems for me a lot of code for a simple copy operation...
  P.S.
  I work with Lua 5.3</p>