【发布时间】:2016-08-19 21:54:15
【问题描述】:
所以函数是这样的:
send_success(lua_State *L){
MailService *mls = static_cast<MailService *>(lua_touserdata(L, lua_upvalueindex(1)));
Device *dev = static_cast<Device *>(lua_touserdata(L, lua_upvalueindex(2)));
int numArgs = lua_gettop(L);
TRACE << "Number of arguments passed is = " << numArgs;
/* here I do some operation to get the arguments.
I am expecting total of 5 arguments on the stack.
3 arguments are passed from function call in lua
and 2 arguments are pushed as closure
*/
string one_param = lua_tostring(L, 3, NULL)
string two_param = lua_tostring(L, 4, NULL)
string other_param = lua_tostring(L, 5, NULL)
}
现在将这个函数推送到 lua 堆栈上,我已经完成了以下操作
lua_pushstring(theLua, "sendSuccess");
lua_pushlightuserdata(theLua, (void*) mls);
lua_pushlightuserdata(theLua, (void*) this);
lua_pushcclosure(theLua, lua_send_success,2);
lua_rawset(theLua, lua_device); // this gets me device obj in lua
从 lua 调用它,我会这样做
obj:sendSuccess("one param","second param","third param")
但是当我检查参数的数量时。它应该给出 5 个参数。相反,只传递了 4 个参数。 我做了一些测试,我传递的两个对象是否正确传递了轻用数据。它们被正确传递了。
这里唯一缺少的是,缺少一个从 lua 端传递的参数。
我也试过只推一个对象,它工作正常。所以我不确定我是否在某个地方弄乱了参数编号
请说出你的意见
【问题讨论】: