Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualShaquil

Posted 02 November 2012 - 10:19 AM

After a bit of a struggle, I've gotten Lua to work with Visual Studio 2012 (Lua 5.2). Unfortunately, now, when I run some simple test code, it crashes at runtime with an unhandled exception, but only when I call lua_close(). Here's the code:

#include <iostream>
using namespace std;
extern "C"{
#include <lua.hpp>
}
int main()
{

  lua_State *L = luaL_newstate();

  if(!L)
   return -1;

  luaL_dostring(
   L,
   "function add(first, second)\n"
   " return first + second\n"
   "end\n"
  );

  lua_close(L); /*Unhandled exception at 0x100042C0 (Lua.dll) in one more gain.exe: 0xC0000005: Access violation writing location 0x6D79F934.*/

  cout << "Hello";

  system("PAUSE");
  return 0;
}

I've seen that sort of error before. I guess I'm accessing a null pointer? Yes the code gets past if(!L). Does anybody know what's going on?

EDIT: Screenshot added

#1Shaquil

Posted 02 November 2012 - 10:10 AM

After a bit of a struggle, I've gotten Lua to work with Visual Studio 2012 (Lua 5.2). Unfortunately, now, when I run some simple test code, it crashes at runtime with an unhandled exception, but only when I call lua_close(). Here's the code:

#include <iostream>
using namespace std;
extern "C"{
#include <lua.hpp>
}
int main()
{

  lua_State *L = luaL_newstate();

  if(!L)
   return -1;

  luaL_dostring(
   L,
   "function add(first, second)\n"
   " return first + second\n"
   "end\n"
  );

  lua_close(L); /*Unhandled exception at 0x100042C0 (Lua.dll) in one more gain.exe: 0xC0000005: Access violation writing location 0x6D79F934.*/

  cout << "Hello";

  system("PAUSE");
  return 0;
}

I've seen that sort of error before. I guess I'm accessing a null pointer? Yes the code gets past if(!L). Does anybody know what's going on?

PARTNERS