bool KviKvsTreeNodeParameterReturn::execute(KviKvsRunTimeContext * c)
{
	KviKvsVariantList lBuffer;
	if(!m_pDataList->evaluate(c, &lBuffer))
		return false;
	if(lBuffer.count() == 0)
	{
		c->returnValue()->setNothing();
		return true;
	}
	if(lBuffer.count() == 1)
	{
		c->returnValue()->copyFrom(*(lBuffer.first()));
		return true;
	}

	QString all;
	lBuffer.allAsString(all);
	c->returnValue()->setString(all);
	return true;
}
bool KviKvsTreeNodeAliasSimpleCommand::execute(KviKvsRunTimeContext * c)
{
	KviKvsVariantList l;
	if(!m_pParams->evaluate(c, &l))
		return false;

	KviKvsSwitchList swl;
	if(m_pSwitches)
	{
		if(!(m_pSwitches->evaluate(c, &swl)))
			return false;
	}

	const KviKvsScript * s = KviKvsAliasManager::instance()->lookup(m_szCmdName);
	if(!s)
	{
		if(KVI_OPTION_BOOL(KviOption_boolSendUnknownCommandsAsRaw))
		{
			QString szAll;
			l.allAsString(szAll);

			if(!szAll.isEmpty())
				szAll.prepend(" ");
			szAll.prepend(m_szCmdName);

			QByteArray szData;

			if(!c->window()->context())
				goto no_way_to_send_as_raw;
			if(!c->window()->connection())
				goto no_way_to_send_as_raw;

			szData = c->window()->connection()->encodeText(szAll);
			if(!szData.data())
				szData = "";

			if(!c->window()->connection()->sendData(szData.data()))
				goto no_way_to_send_as_raw;

			c->window()->output(KVI_OUT_RAW, __tr2qs_ctx("[RAW]: %Q", "kvs"), &szAll);
			return true;
		no_way_to_send_as_raw:
			c->warning(this, __tr2qs_ctx("Failed to send an unknown command as /RAW", "kvs"));
			c->error(this, __tr2qs_ctx("Call to undefined command '%Q'", "kvs"), &m_szCmdName);
			return false;
		}
		else
		{
			c->error(this, __tr2qs_ctx("Call to undefined command '%Q'", "kvs"), &m_szCmdName);
			return false;
		}
	}

	KviKvsScript copy(*s); // quick reference
	// FIXME: the ExtRTData could be a member structure
	//        it would avoid the constructor call each time
	KviKvsExtendedRunTimeData extData(&swl);

	if(!copy.run(c->window(), &l, nullptr, KviKvsScript::PreserveParams, &extData))
	{
		c->error(this, __tr2qs_ctx("Error in inner alias command call '%Q', called from this context", "kvs"), &m_szCmdName);
		return false;
	}
	return true;
}