title: Checking the value of a Lua stack item from C++
body: <p>how do I check the value of the top of the stack in Lua?</p>
  
  <p>I have the following C++ code:</p>
  
  <pre><code>if (luaL_loadfile(L, filename) == NULL) {
          return 0;// error..
      }
  
      lua_pcall(L,0,0,0); // execute the current script..
  
      lua_getglobal(L,"variable");
  
      if (!lua_isstring(L,-1)){ // fails this check..
          lua_pop(L,1);
          return 0; // error
  }
  </code></pre>
  
  <p>The contents of the file in question is</p>
  
  <pre><code>-- A comment
  variable = "MyString"
  </code></pre>
  
  <p>Any ideas?</p>