lua和c互调 参数传递

来源:互联网 发布:韩国主播用什么软件 编辑:程序博客网 时间:2024/04/28 08:17
int main (int argc, char **argv) {    lua_State *L = luaL_newstate();        //加载库        luaL_openlibs(L);        dofile(L,"app.lua");        lua_getglobal(L,"getString");        //把参数放入栈中        lua_pushstring(L,"ZhangSan");        //lua_call(lua_State* L,int nargs,int nreturns)        //1:lua_State* 2:参数数量  3:返回值数量        //lua_call会清空栈,把返回值放入栈中        lua_call(L,1,1);        if(lua_isstring(L,-1)){            printf("%s\n",lua_tostring(L,-1));        }        lua_pop(L,1);        lua_close(L);        return 0;}

app.lua

version = 2.1name = "lua"people={name="ZhangSan",age=20,com="eoe"}function getPeopleInfo()    return people.name,people.ageendlocal name,age = getPeopleInfo();--print(name,age);function main()    print("Hello Lua")endfunction getString(name)    return "Hello "..nameend
0 0
原创粉丝点击