37,720
社区成员
发帖
与我相关
我的任务
分享
local req = {};
req.opcode = GAME_OPCODE.CLI_PLAYCARD_REQ;
req.sSerialID = 1024;
req.nCardsCount = 1;
cards = {}
cards[1] = {}
cards[1].color = 0;
cards[1].value = 1;
cards[2] = {}
cards[2].color = 1;
cards[2].value = 3;
req.cards = cards;
sendToSdk(req)
CCard* getCardsFlied(lua_State *L, const char *szKey)
{ OutputDebugString("join getCardsFlied ~~~~");
CCard cards[20];
lua_pushstring(L , szKey); //这个压入的的就是上面的req.cards
lua_gettable(L , -2);
int n = lua_objlen(L , -1);
for (int i = 0; i < n; i ++)
{
lua_rawgeti(L,1,i + 1);
char buf[20];
sprintf(buf,"\n%d",i +1);
OutputDebugString(buf);
lua_pop(L , 1);
}
return cards;
}
CCard* getCardsFlied(lua_State *L, const char *szKey)
{
CCard cards[20];
lua_pushstring(L, szKey);
lua_gettable(L,-2);
for(int i = 0; i < 20; i ++)
{
//初始化卡牌属性
cards[i].m_nColor = -1;
cards[i].m_nValue = -1;
//压人对应的卡牌Key值
lua_pushnumber(L,i + 1);
lua_gettable(L , -2);
if (lua_istable(L,-1))
{
//压人卡牌参数"color"
lua_pushstring(L , "color");
lua_gettable(L , -2);
cards[i].m_nColor = lua_tonumber(L , -1);
lua_pop(L , 1);
//压人卡牌参数"value"
lua_pushstring(L , "value");
lua_gettable(L , -2);
cards[i].m_nValue = lua_tonumber(L , -1);
lua_pop(L , 1);
}
lua_pop(L , 1);
#ifdef MB_OS_WIN
char buf[50];
sprintf(buf,"\n\t cards[%d]:(%d , %d)",i,cards[i].m_nColor,cards[i].m_nValue);
OutputDebugString(buf);
#endif
}
return cards;
}
保存一下,做个笔记