27

I've been trying to embed lua in a c++ application but to no avail since the compiler complains about "lua_open".I'm using Lua 5.2.

I found alot of articles claiming that lua_open() was replaced in the fifth version but none of them mentioned with what.

Here's the code I am trying to compile

extern "C" {
#include "../lua/lua.h"
#include "../lua/lualib.h"
#include "../lua/lauxlib.h"
}

int main()
{
    int s=0;

    lua_State *L = lua_open();
    // load the libs
    luaL_openlibs(L);
    luaL_dofile(L,"example.lua");
    printf("\nDone!\n");
    lua_close(L);

    return 0;
}
CharlesB
  • 86,532
  • 28
  • 194
  • 218
NT_SYSTEM
  • 367
  • 1
  • 6
  • 14
  • 4
    `lua_open` was already not present in the 5.1 manual. It worked only for compatibility, which has now been removed in 5.2. – lhf Dec 18 '11 at 15:20
  • See also this very helpful stack overflow answer with an example of the lua_Alloc() function with links to the lua documentation. http://stackoverflow.com/questions/3880798/lua-runs-out-of-memory – Richard Chambers Dec 15 '12 at 16:54
  • Here is a second stack overflow answer giving a few more details regard lua memory allocation http://stackoverflow.com/questions/11324117/how-do-modern-vms-handle-memory-allocation – Richard Chambers Dec 15 '12 at 17:06

1 Answers1

37

Indeed, the lua_open function is not mentioned in the lua 5.2 reference manual

A lua_State is constructed with lua_newstate, and you can use luaL_newstate from lauxlib.h

A faster way to get the answers to such question is to look into the Lua 5.2 source code (which I just did).

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547