C/C++如何调用Lua定义的全局函数
首先找到Lua中的对应函数如下
lua_getglobal(L, "startSearch"); // 获取函数,压入栈中
lua_pushinteger(L, (long) 267000000); // 压入第一个参数
lua_pushinteger(L, (long) 373000000); // 压入第二个参数
之后调用这个函数
int iRet = lua_pcall(L, 2, 1, 0); // 调用函数,调用完成以后,会将返回值压入栈中,2表示参数个数,1表示返回结果个数。
if (iRet) // 调用出错
{
const char *pErrorMsg = lua_tostring(L, -1);
LOGD("pErrorMsg %s", pErrorMsg);
lua_close(L);
return 1;
}
可以看到这个函数已经被调用了
function startSearch(start,end)
...
...
return 100
end