So the function is like :
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)
}
Now pushing this function on lua stack, I have done following
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
calling it from lua , i would do
obj:sendSuccess("one param","second param","third param")
But when i check for the number of arguments. It should give 5 arguments. Instead only 4 arguments are passed. I did some testing whether the two objects i pass a light used data are passed correctly. They are passed correctly.
Only thing missing here is, that one parameter is missing which is passed from lua side.
Also i tried pushing only one object and it worked correctly. so I am not sure if I am messing up with argument numbering somewhere
Please tell your opinions