Embedding Lua in C++

会有一股神秘感。 提交于 2019-12-17 22:36:32

问题


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;
}

回答1:


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



来源:https://stackoverflow.com/questions/8552560/embedding-lua-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!