c++lualuac

Access Violation while creating Lua State


I have this simple program:

#include <lua.hpp>

int main() {
    lua_State * ls = lua_newstate(0, 0);

    lua_close(ls);


    return 0;
}

I put the Lua DLL in the right folder, linked the libraries, setup the include folder, and compiled. It compiled cleanly, but when I run the program, it shows me this. I'm using the latest version of LuaBinaries with Visual Studio 2017


Solution

  • You're giving the lua_newstate a null pointer as the allocator. Naturally when it tries to allocate something there will be an access violation, as you saw.

    Why are you trying to call it this way? Maybe you want luaL_newstate() instead? It provides its own allocator system so you don't need to write your own.