Embedding Lua in C++

18,201

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).

Share:
18,201

Related videos on Youtube

NT_SYSTEM
Author by

NT_SYSTEM

Updated on June 17, 2022

Comments

  • NT_SYSTEM
    NT_SYSTEM almost 2 years

    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;
    }
    
    • lhf
      lhf over 12 years
      lua_open was already not present in the 5.1 manual. It worked only for compatibility, which has now been removed in 5.2.
    • Richard Chambers
      Richard Chambers over 11 years
      See also this very helpful stack overflow answer with an example of the lua_Alloc() function with links to the lua documentation. stackoverflow.com/questions/3880798/lua-runs-out-of-memory
    • Richard Chambers
      Richard Chambers over 11 years
      Here is a second stack overflow answer giving a few more details regard lua memory allocation stackoverflow.com/questions/11324117/…