title: Managing stack with Lua and C++
body: <p>I need to pass a lua script a single string (path to file), and return 0 to many strings.</p>
  
  <pre><code>int error = 0;
  lua_State *L = lua_open();
  luaL_openlibs(L);
  
  std::vector&lt;string&gt; list_strings;
  </code></pre>
  
  <p>is used to push the string onto the stack, before I load and call the source file</p>
  
  <pre><code>if ((error = luaL_loadfile(L, "src/test.lua")) == 0)
  {
      lua_pushstring(L, path.c_str());
  
      if ((error = lua_pcall(L, 1, LUA_MULTRET, 0)) == 0)
      {
          lua_gettable(L, LUA_GLOBALSINDEX);
          lua_pcall(L,1,1,0);
  
          if (lua_gettop(L) == 1 &amp;&amp; lua_istable(L,1))
          {
              int len = lua_objlen(L,1);
              for (int i=1;i =&lt; len; i++)
              {
                  lua_pushinteger(L,i);
                  lua_gettable(L,1);
  
                  const char *s = lua_tostring(L,-1);
                  if (s)
                  {
                      list_strings.push_back(s);
                  }
  
                  lua_pop(L,1);
              }
          }
      }
  }
  </code></pre>
  
  <p>As it stands, I've just been copying code from examples so I'm not really sure if what I'm doing is what I want to do... I want push the path onto the stack, and call a lua function which takes that value off of the stack, and will parse the file which associates to that path.</p>
  
  <p>After parsing, it should return a table containing the strings that are inside of it (you can just think of it as a function that searches for a specific string, I suppose)</p>
  
  <p>edit: made more clear.</p>
  
  <p>Any advice/resources?
  Any similar questions here? or any helpful resources?</p>