title: Creating a simple table with Lua tables C API
body: <p>I'm running a MySQL query which always returns 4 rows:</p>
  
  <p><code>row-&gt;name</code>, <code>row-&gt;date</code>, <code>row-&gt;ip</code>, <code>row-&gt;custom</code></p>
  
  <p>What I want to achieve is create a simple table basing on the above results so it would look like:</p>
  
  <pre><code>{
       "name" = result of row-&gt;name,
       "date" = result of row-&gt;date,
       "ip"   = result of row-&gt;ip,
       "custom" = result of row-&gt;custom
  }
  </code></pre>
  
  <p>I have tried multiple possibilities, but the examples posted are really varied and I got a problems making it working.</p>
  
  <p>My last unsuccessful try:</p>
  
  <pre><code>lua_createtable(L, 0, 4);
  top = lua_gettop(L);
  lua_pushstring(L, "name");
  lua_pushstring(L, row-&gt;name);
  lua_pushstring(L, "date");
  lua_pushnumber(L, row-&gt;date);
  lua_pushstring(L, "ip");
  lua_pushstring(L, row-&gt;ip);
  lua_pushstring(L, "custom");
  lua_pushstring(L, row-&gt;custom);
  lua_settable(L, top);
  </code></pre>