VC6 调用lua

第一个入门例子

lua官网下载

LuaForWindows_v5.1.4-46.exe

里面拿出 include 和lib目录

新建一个工程,保护头文件

#include "include/lua.hpp"

#pragma comment(lib,"lua5.1.lib")



//五个步骤
//1、lua_open();    //初始化lua
//2、打开基本函数库 luaL_openlibs(L);
//3、加载脚本 luaL_loadbuffer(L, szLua.c_str(), szLua.length(),"line") 
//4、执行 lua_pcall(L, 0, 0, 0);
//5、关闭 lua_close(L);

#include <iostream>
#include <string>
using namespace std;
    

string szLua= "print \"safedebug\"";
int main()
{
    lua_State *L = lua_open();    //初始化lua
    luaL_openlibs(L);    //载入所有lua标准库
 

    //载入s里的lua代码后执行
    bool err = luaL_loadbuffer(L, szLua.c_str(), szLua.length(),
                "line") || lua_pcall(L, 0, 0, 0);
    if(err)
    {
        //如果错误,显示
        cerr << lua_tostring(L, -1);
        //弹出错误信息所在的最上层栈
        lua_pop(L, 1);
    }

    lua_close(L);//关闭
    return 0;
}


参考资料;http://www.cnblogs.com/stephen-liu74/archive/2012/07/30/2487201.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值