Пример #1
0
		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;
		}
Пример #2
0
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;
}
Пример #3
0
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;
}
Пример #4
0
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;
	}
}
Пример #5
0
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;
}
Пример #6
0
// *********************************************************************************************************
void CLuaEventForwarder::onFocus(bool focused)
{
	//H_AUTO(R2_CLuaEventForwarder_onFocus)
	CLuaState *ls = getLua();
	if (!ls) return;
	ls->push(focused);
	executeHandler(LuaStr_onFocus, 1);
}
Пример #7
0
// *********************************************************************************************************
void CLuaEventForwarder::onSelect(bool selected)
{
	//H_AUTO(R2_CLuaEventForwarder_onSelect)
	CLuaState *ls = getLua();
	if (!ls) return;
	ls->push(selected);
	executeHandler(LuaStr_onSelect, 1);
}
Пример #8
0
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();
	}
}
Пример #9
0
// **********************************************
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;
}
Пример #10
0
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);
	}
}
Пример #11
0
// *********************************************************************************************************
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);
}
Пример #12
0
// *********************************************************************************************************
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);
}
Пример #13
0
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;
}
Пример #14
0
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;
}
Пример #15
0
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);
}
Пример #16
0
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));
} 
Пример #17
0
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);
}
Пример #18
0
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);
}
Пример #19
0
// *********************************************************************************************************
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);
}
Пример #20
0
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);
}
Пример #21
0
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);
	}
}
Пример #22
0
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値
}
Пример #23
0
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();
	}
}
Пример #24
0
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;
}
Пример #25
0
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;
}
Пример #27
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;
}
Пример #28
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;
}
Пример #29
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;
}
Пример #30
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;
}