void CKLBLuaLibMatrix::getVectorArray(CLuaState& lua, VECTOR * vec, int /*nums*/) { lua.retNil(); while(lua.tableNext()) { lua.retValue(-2); int idx = lua.getInt(-1) - 1; lua.retValue(-2); getVector(lua, &vec[idx]); lua.pop(3); } }
bool CKLBUIScore::initUI(CLuaState& lua) { int argc = lua.numArgs(); // 引数の数が合わない場合 if(argc < ARG_REQUIRE || argc > ARG_NUMS) { return false; } float x = lua.getFloat(ARG_X); float y = lua.getFloat(ARG_Y); u32 order = lua.getInt(ARG_ORDER); s32 order_offset = lua.getInt(ARG_ODOFF); float stepX = lua.getFloat(ARG_STEP_X); float stepY = lua.getFloat(ARG_STEP_Y); int column = lua.getInt(ARG_COLS); bool fillzero = lua.getBool(ARG_FILLZERO); bool anim_flag = lua.getBool(ARG_ANIM); int align = (argc >= ARG_ALIGN) ? lua.getInt(ARG_ALIGN) : ALIGN_RIGHT; bool countclip = (argc >= ARG_COUNTCLIP) ? lua.getBool(ARG_COUNTCLIP) : false; const char * tex_list[10]; lua.retValue(ARG_TEXTBL); // 対象となる配列をスタックトップに積む lua.retNil(); // nil をスタックトップに積む int tex_cnt = 0; while(lua.tableNext()) { lua.retValue(-2); int idx = lua.getInt(-1) - 1; // Lua配列の添え字は1からなので、-1する。 const char * str = lua.getString(-1); // 与えられた配列のindexに整数以外が使われているときや、 // 範囲を超えたものがある場合はエラー扱いとする。 klb_assert((idx >= 0 && idx <= 9), "BAD INDEX [%s] in texture array.", str); if(idx < 0 || idx > 9) { // 数値以外のインデックスが指定されていたり、範囲を超えている場合 return false; } const char * texname = lua.getString(-2); // テクスチャ名称が格納されている。 tex_list[idx] = texname; tex_cnt++; lua.pop(2); } lua.pop(1); // テクスチャの数が足りなければエラーとする。 if(tex_cnt != 10) { klb_assert(tex_cnt == 10, "%s(%d): The number of textures is insufficient. ", lua.getScriptName(), lua.getNumLine()); return false; } return initCore(order, order_offset, x, y, tex_list, stepX, stepY, column, fillzero, anim_flag, align, countclip); }
bool CKLBUIMultiImgItem::getImgList(CLuaState& lua, IMGITEM* items, u32 /*max*/) { CKLBRenderingManager& rdr = CKLBRenderingManager::getInstance(); lua.retNil(); while(lua.tableNext()) { lua.retValue(-2); int idx = lua.getInt(-1) - 1; const char * name = lua.getString(-2); lua.pop(2); u32 handle; CKLBAsset * pAsset = CKLBUtility::loadAsset(name, &handle, NULL); if(pAsset->getAssetType() == ASSET_IMAGE) { CKLBSprite* pRender = rdr.allocateCommandSprite((CKLBImageAsset*)pAsset,m_order); items[idx].handle = handle; items[idx].sprite = pRender; } } return true; }
bool CKLBUIMultiImgItem::initUI(CLuaState& lua) { int argc = lua.numArgs(); if(argc < ARG_REQUIRE || argc > ARG_NUMS) return false; float x = lua.getFloat(ARG_X); float y = lua.getFloat(ARG_Y); u32 order = lua.getInt(ARG_ORDER); u32 idxImg = (argc >= ARG_INDEX) ? lua.getInt(ARG_INDEX) : 0; // asset list を取得 lua.retValue(ARG_ASSET_LIST); // 要素の数を数える int max = 0; lua.retNil(); // Read indexes and count entries. while(lua.tableNext()) { lua.retValue(-2); int idx = lua.getInt(-1); if(max < idx) max = idx; lua.pop(2); } IMGITEM* items = KLBNEWA(IMGITEM, max); if(!items) { return false; } // Reset all handle to NULL for(int idx = 0; idx < max; idx++) { items[idx].handle = 0; items[idx].sprite = NULL; } m_order = order; // Needed for getImgList if(!getImgList(lua,items,max)) { return false; } return initCore(order, x,y,idxImg,items,max); }
int CKLBLuaLibMatrix::getVectorNums(CLuaState& lua) { int idx = 0; lua.retNil(); while(lua.tableNext()) { lua.retValue(-2); int v = lua.getInt(-1); if(v > idx) idx = v; lua.pop(2); } return idx; // 最大のindex値 }
int CKLBUIScore::commandUI(CLuaState& lua, int argc, int cmd) { int ret = 0; switch(cmd) { case UI_SCORE_RESET: setValue(0); m_bScoreUpdate = true; break; case UI_SCORE_SET: { if(argc != 3) { lua.retNil(); ret = 1; break; } int value = lua.getInt(3); if(m_bCountClip && value >= m_maxvalue) value = m_maxvalue - 1; setValue(value); } break; case UI_SCORE_SETFLOAT: { if(argc != 4) { lua.retNil(); ret = 1; break; } float value = lua.getFloat(3); int pos = lua.getInt(4); if(m_bCountClip && value >= m_maxvalue) value = m_maxvalue - 1; setValueFloat(value, pos); } break; case UI_SCORE_SETDOT: { if(argc != 5) { lua.retNil(); ret = 1; break; } setDot(lua.getString(3), lua.getInt(4), lua.getInt(5)); } break; case UI_SCORE_GET: { int value = getValue(); lua.retInt(value); ret = 1; } break; case UI_SCORE_ENTERANIM: { if(argc != 8) { lua.retBoolean(false); ret = 1; break; } s32 mspt = lua.getInt(3); s32 tshift = lua.getInt(4); bool onlychg = lua.getBool(5); int type = lua.getInt(6); u32 affected = lua.getInt(7); float mat[8]; klb_assert(type > 0, "UI_Score: UI_SCORE_ENTERANIM type == 0"); // 配列を読む lua.retValue(8); lua.retNil(); while(lua.tableNext()) { lua.retValue(-2); int idx = lua.getInt(-1) - 1; klb_assert((idx >= 0 && idx < 8), "%s(%d): bad array index. UI_SCORE_ENTERANIM", lua.getScriptName(), lua.getNumLine()); mat[idx] = lua.getFloat(-2); lua.pop(2); } lua.pop(1); klb_assert(type != 0, "Custom animation is not authorized (type 0)"); m_pScoreNode->setEnterAnimation(mspt, tshift, onlychg, type, affected, mat); } break; case UI_SCORE_EXITANIM: { if(argc != 8) { lua.retBoolean(false); ret = 1; break; } s32 mspt = lua.getInt(3); s32 tshift = lua.getInt(4); bool onlychg = lua.getBool(5); int type = lua.getInt(6); u32 affected = lua.getInt(7); float mat[4]; klb_assert(type > 0, "UI_Score: UI_SCORE_ENTERANIM type == 0"); // 配列を読む lua.retValue(8); lua.retNil(); while(lua.tableNext()) { lua.retValue(-2); int idx = lua.getInt(-1) - 1; mat[idx] = lua.getFloat(-2); lua.pop(2); } lua.pop(1); klb_assert(type != 0, "Custom animation is not authorized (type 0)"); m_pScoreNode->setExitAnimation(mspt, tshift, onlychg, type, affected, mat); } break; case UI_SCORE_ALIGN: { bool bResult = false; if(argc == 3) { int align = lua.getInt(3); setAlign(align); bResult = true; } lua.retBool(bResult); ret = 1; } break; } return ret; }