在 C++ 中嵌入 Lua [英] Embedding Lua in C++

查看:25
本文介绍了在 C++ 中嵌入 Lua的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试将 lua 嵌入到 C++ 应用程序中,但无济于事,因为编译器抱怨lua_open".我使用的是 Lua 5.2.

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.

我发现很多文章声称 lua_open() 在第五版中被替换了,但没有一个提到什么.

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

这是我要编译的代码

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("
Done!
");
    lua_close(L);

    return 0;
}

推荐答案

确实,lua 5.2 参考手册

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

一个lua_State是用lua_newstate构造的,你可以使用lauxlib.h中的luaL_newstate

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

获得此类问题答案的更快方法是查看 Lua 5.2 源代码(我刚刚做了).

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

这篇关于在 C++ 中嵌入 Lua的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆