static int callFunc(lua_State *ls) { nlassert(ls); TLuaWrappedFunction func = (TLuaWrappedFunction) lua_touserdata(ls, lua_upvalueindex(1)); CLuaState *state = (CLuaState *) lua_touserdata(ls, lua_upvalueindex(2)); nlassert(func); nlassert(state); // get real function pointer from the values in the closure int numResults; int initialStackSize = state->getTop(); try { // call the actual function numResults = func(*state); } catch(const std::exception &e) { // restore stack to its initial size state->setTop(initialStackSize); lua_pushstring(ls, e.what()); // TODO : see if this is safe to call lua error there" ... (it does a long jump) lua_error(ls); } return numResults; }
int CKLBUIMultiImgItem::commandUI(CLuaState& lua, int argc, int cmd) { int ret = 0; switch(cmd) { default: { lua.retBoolean(false); ret = 1; } break; case UI_MULTIIMG_SET_INDEX: { if(argc != 3) { lua.retBoolean(false); ret = 1; break; } int idx = lua.getInt(3); // 指定されたindexが有効な範囲に収まらなければ、何もせずfalseを返す int max = m_idxMax; if(idx > max || idx < 0) { lua.retBoolean(false); ret = 1; break; } setIndex(idx); lua.retBoolean(true); ret = 1; } break; } return ret; }
int CKLBGenericTask::commandScript(CLuaState& lua) { int argc = lua.numArgs(); if(argc < 2) { lua.retBoolean(false); return 1; } int cmd = lua.getInt(2); int ret = 1; switch(cmd) { default: { lua.retBoolean(false); ret = 1; } break; case GENERIC_STOP_EXECUTE: { KLBDELETEA(m_luaFuncExec); m_luaFuncExec = NULL; lua.retBoolean(true); ret = 1; } break; } return ret; }
bool CKLBUpdateZip::initScript(CLuaState& lua) { // bool res = true; int argc = lua.numArgs(); // 引数チェック if(argc < ARG_ZIPREQUIRE || argc > ARG_ZIPNUM) { return false; } const char * callbackUnzip = (argc >= ARG_ZIPUNZIP_CALLBACK) ? lua.getString(ARG_ZIPUNZIP_CALLBACK) : NULL; const char * callbackFinish = (argc >= ARG_ZIPFINISH_CALLBACK) ? lua.getString(ARG_ZIPFINISH_CALLBACK) : NULL; const char * callbackError = (argc >= ARG_ZIPERROR_CALLBACK) ? lua.getString(ARG_ZIPERROR_CALLBACK) : NULL; const char * tmp_name = lua.getString(ARG_ZIPTMPNAME); m_tmpPath = CKLBUtility::copyString(tmp_name); // Load "Update" info if any if (lockExist()) { m_eStep = S_INIT_UNZIP; m_zipEntry = 0; m_callbackZIP = CKLBUtility::copyString(callbackUnzip); m_callbackFinish = CKLBUtility::copyString(callbackFinish); m_callbackError = callbackError ? CKLBUtility::copyString(callbackError) : NULL; return regist(NULL, P_NORMAL); } else { return false; } }
bool CKLBFormIF::updateUITextEdit(CLuaState& lua, int argc, int base, int subcmd, CKLBNode * pNode, int& ret, void * item, int index) { CKLBUITask* pTask = pNode->getUITask(); CKLBUITextBox * pText = (CKLBUITextBox *)pNode; // 2012-12-3(Mon) // pTaskが存在していない可能性が高いのでpTaskのNULLチェックを追加しました if ((pTask) && (pTask->getClassID() != CLS_KLBUITEXTINPUT)) { // Not valid pTask = NULL; } bool result = true; switch(subcmd) { default: { result = updateUIElement(lua, argc, base, subcmd, pNode, ret, item, index); } break; case FORM_LBL_GET_TEXT: // Trick : label & text command backward compatible. case FORM_TEXT_GET: { /* Do not understand why return false for now. if(argc != base) { result = false; break; }*/ const char * text; if (pTask) { text = ((CKLBUITextInput*)pTask)->getText(); } else { text = pText->getText(); } lua.retString(text); ret = 1; } break; case FORM_TEXT_SET: // Trick : label & text command backward compatible. case FORM_LBL_SET_TEXT: { if(argc != base + 1) { result = false; break; } const char * text = lua.getString(base + 1); if (pTask) { ((CKLBUITextInput*)pTask)->setText(text); } else { pText->setText((char *)text); } } break; } return result; }
// ********************************************************************************************************* void CLuaEventForwarder::onFocus(bool focused) { //H_AUTO(R2_CLuaEventForwarder_onFocus) CLuaState *ls = getLua(); if (!ls) return; ls->push(focused); executeHandler(LuaStr_onFocus, 1); }
// ********************************************************************************************************* void CLuaEventForwarder::onSelect(bool selected) { //H_AUTO(R2_CLuaEventForwarder_onSelect) CLuaState *ls = getLua(); if (!ls) return; ls->push(selected); executeHandler(LuaStr_onSelect, 1); }
void CKLBLuaLibMatrix::setVector(CLuaState& lua, VECTOR * vec) { lua.tableNew(); // ベクトル用のテーブル for(int n = 0; n < 4; n++) { lua.retInt(n + 1); lua.retDouble(vec->v[n]); lua.tableSet(); } }
// ********************************************** int CToolPick::luaCanPick(CLuaState &ls) { //H_AUTO(R2_CToolPick_luaCanPick) CLuaIHM::checkArgCount(ls, "canPick", 0); if (_CandidateInstance) ls.push(canPick(*_CandidateInstance)); else ls.push(false); return 1; }
void CKLBLuaLibMatrix::getVector(CLuaState& lua, VECTOR * vec) { // Luaスタックトップにはvectorテーブルが積んである for(int n = 0; n < 4; n++) { lua.retInt(n + 1); lua.tableGet(); vec->v[n] = lua.getFloat(-1); lua.pop(1); } }
// ********************************************************************************************************* void CLuaEventForwarder::onAttrModified(const std::string &attrName, sint32 index) { //H_AUTO(R2_CLuaEventForwarder_onAttrModified) CLuaState *ls = getLua(); if (!ls) return; ls->push(attrName); ls->push((double) index); executeHandler(LuaStr_onAttrModified, 2); }
// ********************************************************************************************************* void CLuaEventForwarder::onTargetInstancePostHrcMove(const std::string &refMakerAttr, sint32 refMakerAttrIndex) { //H_AUTO(R2_CLuaEventForwarder_onTargetInstancePostHrcMove) CLuaState *ls = getLua(); if (!ls) return; ls->push(refMakerAttr); ls->push((double) refMakerAttrIndex); executeHandler(LuaStr_onTargetInstancePostHrcMove, 2); }
int CKLBUITouchPad::commandScript(CLuaState& lua) { int argc = lua.numArgs(); if(argc < 2) { lua.retBool(false); return 1; } int cmd = lua.getInt(2); int ret = 1; switch(cmd) { default: { lua.retBool(false); ret = 1; } break; case UI_TOUCHPAD_SET_GROUP: { bool result = false; if(argc == 3) { const char * group_name = lua.getString(3); result = setGroup(group_name); } lua.retBoolean(result); ret = 1; } break; case UI_TOUCHPAD_LOCK: { bool result = false; if(argc == 3) { bool lock_mode = lua.getBool(3); lock(lock_mode); result = true; } lua.retBoolean(true); ret = 1; } break; case UI_TOUCHPAD_GET_ALL: { bool result = false; if(argc == 3) { setGetAll(lua.getBool(3)); result = true; } lua.retBoolean(result); ret = 1; } break; } return ret; }
bool CKLBFormIF::updateLabelNode(CLuaState& lua, int argc, int base, int subcmd, CKLBNode * pNode, int& ret, void * item, int index) { CKLBLabelNode * pLabel = (CKLBLabelNode *)pNode; CKLBUITask* pTask = pNode->getUITask(); // pTaskが存在していない可能性が高いのでpTaskのNULLチェックを追加しました if ((pTask) && (pTask->getClassID() != CLS_KLBUILABEL)) { // Not valid pTask = NULL; } bool result = true; switch(subcmd) { default: { result = updateUIElement(lua, argc, base, subcmd, pNode, ret, item, index); } break; case FORM_TEXT_SET: // Trick : label & text command backward compatible. case FORM_LBL_SET_TEXT: { if(argc != base + 1) { result = false; break; } const char * text = lua.getString(base + 1); if (pTask) { ((CKLBUILabel*)pTask)->setText(text); } else { pLabel->setText((char *)text); } } break; case FORM_LBL_GET_TEXT: // Trick : label & text command backward compatible. case FORM_TEXT_GET: { /* if(argc != base) { result = false; break; }*/ const char * uri; if (pTask) { uri = ((CKLBUILabel*)pTask)->getText(); } else { uri = pLabel->getText(); } lua.retString(uri); ret = 1; } break; } return result; }
bool CKLBUIButton::initScript(CLuaState& lua) { int argc = lua.numArgs(); if(argc < ARG_REQUIRE || argc > ARG_NUMS) return false; const char * funcname = lua.getString(ARG_CALLBACK); return init(NULL, funcname); }
bool CKLBUISimpleItem::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); return initCore(lua.getInt(ARG_ORDER),x,y,lua.getString(ARG_ASSET)); }
bool CKLBUITouchPad::initScript(CLuaState& lua) { int argc = lua.numArgs(); if(argc < ARG_REQUIRE || argc > ARG_NUMS) { return false; } const char * funcname = lua.getString(ARG_CALLBACK); bool modal = (argc >= ARG_MODAL) ? lua.getBool(ARG_MODAL) : false; return init(NULL, funcname, modal); }
bool CKLBUIControl::initScript(CLuaState& lua) { int argc = lua.numArgs(); if(argc != 2) return false; const char * onClick = lua.getString(1); const char * onDrag = lua.getString(2); return init(NULL, onClick, onDrag); }
// ********************************************************************************************************* void CLuaEventForwarder::onTargetInstanceAttrModified(const std::string &refMakerAttr, sint32 refMakerAttrIndex, const std::string &targetAttrName, sint32 targetAttrIndex) { //H_AUTO(R2_CLuaEventForwarder_onTargetInstanceAttrModified) CLuaState *ls = getLua(); if (!ls) return; ls->push(refMakerAttr); ls->push((double) refMakerAttrIndex); ls->push(targetAttrName); ls->push((double) targetAttrIndex); executeHandler(LuaStr_onTargetInstanceAttrModified, 4); }
bool CKLBPauseCtrl::initScript(CLuaState& lua) { int argc = lua.numArgs(); if(argc != 2) { return false; } const char * pause = (lua.isNil(1)) ? NULL : lua.getString(1); const char * resume = (lua.isNil(2)) ? NULL : lua.getString(2); return init(NULL, pause, resume); }
void CKLBLuaLibMatrix::getMatrix(CLuaState& lua, MATRIX * ret) { // 最上位には対象の配列が積んである for(int idx = 0; idx < 16; idx++) { lua.retInt(idx + 1); // Luaテーブル上のindexを積む lua.tableGet(); // 対応する値を取得する float val = lua.getFloat(-1); ret->m[idx] = val; lua.pop(1); } }
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値 }
void CKLBLuaLibMatrix::setMatrix(CLuaState& lua, MATRIX * mat) { // 最上位に対象の配列を作る lua.tableNew(); for(int idx = 0; idx < 16; idx++) { // key として index 値を積む lua.retInt(idx + 1); // 値を積む lua.retDouble(mat->m[idx]); // 値を設定する lua.tableSet(); } }
bool CKLBFormIF::updateUIWebView(CLuaState& lua, int argc, int base, int subcmd, CKLBNode * pNode, int& ret, void * item, int index) { CKLBUITask* pTask = pNode->getUITask(); bool result = true; switch(subcmd) { default: { result = updateUIElement(lua, argc, base, subcmd, pNode, ret, item, index); } break; case FORM_WEB_SET_URI: { if(argc != base + 1) { result = false; break; } const char * uri = lua.getString(base + 1); if (pTask) { CKLBUIWebArea* pWebTask = (CKLBUIWebArea*)pTask; pWebTask->setText(uri); } else { CKLBUIWebView * pWeb = (CKLBUIWebView *)pNode; pWeb->setText((char *)uri); } } break; case FORM_WEB_GET_URI: { if(argc != base) { result = false; break; } const char * uri; if (pTask) { CKLBUIWebArea* pWebTask = (CKLBUIWebArea*)pTask; uri = pWebTask->getText(); } else { CKLBUIWebView * pWeb = (CKLBUIWebView *)pNode; uri = pWeb->getText(); } lua.retString(uri); ret = 1; } break; } return result; }
void CKLBLuaLibMatrix::setVectorArray(CLuaState& lua, VECTOR * vec, int nums) { lua.tableNew(); // ベクトル配列用のテーブル for(int idx = 0; idx < nums; idx++) { lua.retInt(idx + 1); // ベクトル配列中のindexを指定する // ベクトルの値をスタック上に積む setVector(lua, &vec[idx]); // この時点で、ベクトル配列のindexと、ベクトルがスタックに積まれている lua.tableSet(); // ベクトル配列にベクトルを設定する } // 一通りの設定が終わり、ベクトル配列テーブルがスタック上に積まれた状態になる。 }
// **************************************************************************** int CSessionBrowserImpl::luaJoinRingSession(CLuaState &ls) { nldebug("SB: luaJoinRingSession"); const char *funcName = "joinRingSession"; CLuaIHM::checkArgCount(ls, funcName, 1); CLuaIHM::checkArgType(ls, funcName, 1, LUA_TNUMBER); CInterfaceManager *pIM = CInterfaceManager::getInstance(); CSessionBrowserImpl & sessionBrowser = CSessionBrowserImpl::getInstance(); sessionBrowser.joinSession(getCharId(), (TSessionId)(uint32) ls.toNumber(1), ClientCfg.ConfigFile.getVar("Application").asString(0)); if(!sessionBrowser.waitOneMessage(sessionBrowser.getMessageName("on_joinSessionResult"))) { nlwarning("joinSession callback return false"); } if(sessionBrowser._LastJoinSessionResult == 20) { CViewText* pVT = dynamic_cast<CViewText*>(pIM->getElementFromId("ui:interface:warning_free_trial:text")); if (pVT != NULL) pVT->setText(CI18N::get("uiRingWarningFreeTrial")); pIM->runActionHandler("enter_modal", NULL, "group=ui:interface:warning_free_trial"); } return 0; }
int CGroupTab::luaRemoveTab(CLuaState &ls) { const char *funcName = "removeTab"; CLuaIHM::checkArgCount(ls, funcName, 1); CLuaIHM::checkArgType(ls, funcName, 1, LUA_TNUMBER); removeTab((uint) ls.toNumber(1)); return 0; }
// ********************************************************************************************************* int CDisplayerVisualEntity::luaUpdatePermanentStatutIcon(CLuaState &ls) { //H_AUTO(R2_CDisplayerVisualEntity_luaUpdatePermanentStatutIcon) const char *funcName = "updatePermanentStatutIcon"; CLuaIHM::checkArgCount(ls, funcName, 1); updatePermanentStatutIcon(ls.toString(1)); return 0; }
//***************************************************************************************************************** int CGroupHeader::luaResizeColumnsAndContainer(CLuaState &ls) { const char *funcName = "resizeColumnsAndContainer"; CLuaIHM::checkArgCount(ls, funcName, 1); CLuaIHM::checkArgType(ls, funcName, 1, LUA_TNUMBER); resizeColumnsAndContainer((sint32) ls.toNumber(1)); return 0; }
//***************************************************************************************************************** int CGroupHeader::luaEnlargeColumns(CLuaState &ls) { const char *funcName = "enlargeColumns"; CLuaIHM::checkArgCount(ls, funcName, 1); CLuaIHM::checkArgType(ls, funcName, 1, LUA_TNUMBER); enlargeColumns((sint32) ls.toNumber(1)); return 0; }