c读取lua

来源:互联网 发布:达梦数据库客户端下载 编辑:程序博客网 时间:2024/05/20 11:22
<span style="font-size:18px;">#include <string.h>#include <iostream>extern "C"{#include "lua.h"#include "lauxlib.h"#include "lualib.h"}int main(){    int windows_width = 0;    int windows_height = 0;    lua_State * L = luaL_newstate();    luaL_openlibs(L);    //load lua file 加载lua文件    int bRet = luaL_loadfile(L, "cc.lua");    if (bRet)    {        return false;    }    // run lua file 运行lua文件    bRet = lua_pcall(L, 0, 0, 0);    if (bRet)    {        return false;    }    // lua--> stack    lua_getglobal(L, "width");    lua_getglobal(L, "height");    //type check 类型检测    int a = lua_isnumber(L, -2);    if (!a)    {        return false;    }    int b = lua_isnumber(L, -1);    if(!b)    {        return false;    }    //stack-->c    windows_height = lua_tointeger(L, -1);    windows_width = lua_tointeger(L, -2);    printf("width = %d, height = %d", windows_width, windows_height);    lua_close(L);    return 0;}</span>


0 0
原创粉丝点击