24,854
社区成员
发帖
与我相关
我的任务
分享
function add(x, y)
print("call lua_file add")
return x + y
end
int lua_add(int x,int y)
{
int sum;
/*the function name*/
lua_getglobal(L,"add");
/*the first argument*/
lua_pushnumber(L,x);
/*the second argument*/
lua_pushnumber(L,y);
/*call the function with 2 arguments, return 1 result.*/
lua_call(L,2,1);
/*get the result.*/
sum = (int)lua_tonumber(L,-1);//可以正确读出返回值
/*cleanup the return*/
lua_pop(L,1);
return sum;
}
function parse(did)
string str = "did is not 1"
print("call lua_file parse")
if(1 == did)
then
str = "did is 1"
end
return str
end
int lua_parse(int did)
{
const char *buf;
uint len;
/*the function name*/
lua_getglobal(L,"parse");
/*the first argument*/
lua_pushnumber(L,did);
/*call the function with 1 arguments, return 1 result.*/
lua_call(L,1,1);
/*get the result.*/
buf = lua_tolstring(L,-1, &len);//我以为buf会得到lua函数返回的字符串的首地址
printf("ret len = %d\r\n", len);
/*cleanup the return*/
lua_pop(L,1);
return 0;
}