KVIrc  4.9.2
DeveloperAPIs
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Attributes | Friends | List of all members
KviKvsScript Class Reference

The KVIrc Script class. More...

#include <KviKvsScript.h>

+ Inheritance diagram for KviKvsScript:

Public Types

enum  RunFlags { PreserveParams = 1, AssumeLocals = 2, Pedantic = 4, Quiet = 8 }
 Holds the run flags of the script. More...
 
enum  RunStatus { Error = 0, Success = 1, HaltEncountered = 2 }
 Holds the run status of the script. More...
 
enum  ScriptType { InstructionList, Expression, Parameter }
 Holds the type of the script. More...
 

Public Member Functions

const QString & code () const
 Returns the code of the script. More...
 
void dump (const char *prefix)
 Dumps the instructions tree. More...
 
 KviKvsScript (const KviKvsScript &src)
 Constructs a KVIrc Script object. More...
 
 KviKvsScript (const QString &szName, const QString &szBuffer, ScriptType eType=InstructionList)
 Constructs a KVIrc Script object. More...
 
bool locked () const
 Returns true if the script is locked, false otherwise. More...
 
const QString & name () const
 Returns the name of the script context. More...
 
int run (KviWindow *pWnd, KviKvsVariantList *pParams=0, KviKvsVariant *pRetVal=0, int iRunFlags=0, KviKvsExtendedRunTimeData *pExtData=0)
 Runs the script. More...
 
int run (KviWindow *pWnd, KviKvsVariantList *pParams, QString &szRetVal, int iRunFlags=0, KviKvsExtendedRunTimeData *pExtData=0)
 Runs the script. More...
 
int run (KviKvsRunTimeContext *pContext, int iRunFlags=0)
 Runs the script. More...
 
void setName (const QString &szName)
 Sets the name of the script context. More...
 
 ~KviKvsScript ()
 Destroys a KVIrc Script object. More...
 

Static Public Member Functions

static int evaluate (const QString &szCode, KviWindow *pWindow, KviKvsVariantList *pParams, KviKvsVariant *pRetVal)
 Static helper for quick evaluating parameters. More...
 
static int evaluateAsString (const QString &szCode, KviWindow *pWindow, KviKvsVariantList *pParams, QString &szRetVal)
 Static helper for quick evaluating parameters. More...
 
static int run (const QString &szCode, KviWindow *pWindow, KviKvsVariantList *pParams=0, KviKvsVariant *pRetVal=0)
 Static helper for quick running. More...
 

Protected Member Functions

const QChar * buffer () const
 Returns the data of the script. More...
 
void detach ()
 Detaches this script from any other shallow copies. More...
 
int execute (KviWindow *pWnd, KviKvsVariantList *pParams=0, KviKvsVariant *pRetVal=0, int iRunFlags=0, KviKvsExtendedRunTimeData *pExtData=0)
 Runs the script. More...
 
int executeInternal (KviKvsRunTimeContext *pContext)
 Runs the script. More...
 
 KviKvsScript (const QString &szName, const QString &szBuffer, KviKvsTreeNodeInstruction *pPreparsedTree, ScriptType eType=InstructionList)
 Constructs a KVIrc Script object. More...
 
bool parse (KviWindow *pOutput=0, int iRunFlags=0)
 Returns true after a succesfull parsing, false otherwise. More...
 

Private Attributes

KviKvsScriptDatam_pData
 

Friends

class KviKvsObject
 
class KviKvsParser
 
class KviKvsRunTimeContext
 

Detailed Description

The KVIrc Script class.

Member Enumeration Documentation

Holds the run flags of the script.

Enumerator
PreserveParams 

Do not delete the eventual parameters passed (only execute() and run())

AssumeLocals 

Assume that the variables are local unless explicitly declared (flag used only for parse())

Pedantic 

Be more pedantic: spit more warnings and sometimes more errors

Quiet 

Don't print any errors

Holds the run status of the script.

Enumerator
Error 

The script returned an error

Success 

The script ran successfully

HaltEncountered 

The script ran successfully and halt was encountered

Holds the type of the script.

Enumerator
InstructionList 

The most common script type: a sequence of instructions

Expression 

An expression to be evaluated as in a $() call (pRetVal should be always set!)

Parameter 

A parameter to be evaluated (pRetVal should be always set!)

Constructor & Destructor Documentation

KviKvsScript::KviKvsScript ( const KviKvsScript src)

Constructs a KVIrc Script object.

This is a shallow copy of the script data useful when a script can be destroyed while running (like in timers)

Parameters
srcThe source script
Returns
KviKvsScript

References m_pData, and KviKvsScriptData::m_uRefs.

Referenced by KviKvsScriptAddon::allocateScripts(), KviKvsScriptAddon::setConfigureCallback(), and KviKvsScriptAddon::setHelpCallback().

KviKvsScript::KviKvsScript ( const QString &  szName,
const QString &  szBuffer,
ScriptType  eType = InstructionList 
)

Constructs a KVIrc Script object.

Parameters
szNameThe name of the context
szBufferThe buffer :)
eTypeThe type of the code in the buffer
Returns
KviKvsScript

References KviKvsScriptData::m_eType, KviKvsScriptData::m_pBuffer, m_pData, KviKvsScriptData::m_pTree, KviKvsScriptData::m_szBuffer, KviKvsScriptData::m_szName, KviKvsScriptData::m_uLock, KviKvsScriptData::m_uRefs, and szBuffer.

KviKvsScript::~KviKvsScript ( )

Destroys a KVIrc Script object.

References m_pData, KviKvsScriptData::m_pTree, KviKvsScriptData::m_uLock, and KviKvsScriptData::m_uRefs.

KviKvsScript::KviKvsScript ( const QString &  szName,
const QString &  szBuffer,
KviKvsTreeNodeInstruction pPreparsedTree,
ScriptType  eType = InstructionList 
)
protected

Constructs a KVIrc Script object.

Parameters
szNameThe name of the context
szBufferThe buffer :)
pPreparsedTreeThe synthax tree
eTypeThe type of the code in the buffer
Returns
KviKvsScript

References KviKvsScriptData::m_eType, KviKvsScriptData::m_pBuffer, m_pData, KviKvsScriptData::m_pTree, KviKvsScriptData::m_szBuffer, KviKvsScriptData::m_szName, KviKvsScriptData::m_uLock, KviKvsScriptData::m_uRefs, and szBuffer.

Member Function Documentation

const QChar * KviKvsScript::buffer ( ) const
protected

Returns the data of the script.

Returns
const QChar *

References KviKvsScriptData::m_pBuffer, and m_pData.

Referenced by KviKvsRunTimeContext::report().

const QString & KviKvsScript::code ( ) const
void KviKvsScript::detach ( )
protected
void KviKvsScript::dump ( const char *  prefix)

Dumps the instructions tree.

Parameters
prefixThe prefix of the instruction
Returns
void

References KviKvsTreeNodeInstruction::dump(), m_pData, and KviKvsScriptData::m_pTree.

Referenced by KviKvsTreeNodeCallbackCommand::dumpCallback().

int KviKvsScript::evaluate ( const QString &  szCode,
KviWindow pWindow,
KviKvsVariantList pParams,
KviKvsVariant pRetVal 
)
static

Static helper for quick evaluating parameters.

Returns a combination of RunStatus flags (nonzero on no error) It does NOT take params ownership. pRetVal CAN'T be zero here since we're evaluating stuff here

Parameters
szCodeThe source code to run
pWindowThe window that the command has to be bound to
pParamsThe parameter list
pRetValReturn value buffer
Returns
int

References Parameter, PreserveParams, run(), and s.

Referenced by KviInputEditor::checkWordSpelling(), KviChannelWindow::closeEvent(), KviInputEditor::fillSpellCheckerCorrectionsPopup(), KviWindow::getDefaultLogFileName(), KviKvsCoreFunctions::KVSCF(), OptionsWidget_textEncoding::OptionsWidget_textEncoding(), KviIrcContext::terminateConnectionRequest(), and KviIrcConnection::useRealName().

int KviKvsScript::evaluateAsString ( const QString &  szCode,
KviWindow pWindow,
KviKvsVariantList pParams,
QString &  szRetVal 
)
static

Static helper for quick evaluating parameters.

Returns a combination of RunStatus flags (nonzero on no error) It does NOT take params ownership. The QString return buffer CAN'T be zero here since we're evaluating stuff here

Parameters
szCodeThe source code to run
pWindowThe window that the command has to be bound to
pParamsThe parameter list
szRetValReturn value buffer
Returns
int

References KviKvsVariant::asString(), Parameter, PreserveParams, run(), and s.

int KviKvsScript::execute ( KviWindow pWnd,
KviKvsVariantList pParams = 0,
KviKvsVariant pRetVal = 0,
int  iRunFlags = 0,
KviKvsExtendedRunTimeData pExtData = 0 
)
protected

Runs the script.

Returns 0 (KviKvsScript::RunFailure) on error Returns a nonzero combination of RunStatus flags on success

Parameters
pWndThe window that the command has to be bound to
pParamsThe parameter list (0 if you don't pass params)
pRetValReturn value buffer (0 if you ignore it)
iRunFlagsA combination of run flags (usually default)
pExtDataExtended data (usually 0)
Returns
int

References KviKvsRunTimeContext::disableReporting(), KviKvsKernel::emptyParameterList(), Error, executeInternal(), KviKvsKernel::instance(), KVI_OUT_PARSERERROR, m_pData, KviKvsScriptData::m_pTree, KviWindow::outputNoFmt(), PreserveParams, and Quiet.

Referenced by run().

int KviKvsScript::executeInternal ( KviKvsRunTimeContext pContext)
protected

Runs the script.

Returns 0 (KviKvsScript::RunFailure) on error Returns a nonzero combination of RunStatus flags on success

Parameters
pContextThe context where the script is bound to
Returns
int

References Error, KviKvsRunTimeContext::error(), KviKvsTreeNodeInstruction::execute(), KviKvsRunTimeContext::haltCalled(), HaltEncountered, m_pData, KviKvsScriptData::m_pTree, KviKvsScriptData::m_uLock, and Success.

Referenced by execute(), and run().

bool KviKvsScript::locked ( ) const

Returns true if the script is locked, false otherwise.

The lock is set while the script is being executed

Returns
bool

References m_pData, and KviKvsScriptData::m_uLock.

const QString & KviKvsScript::name ( ) const
bool KviKvsScript::parse ( KviWindow pOutput = 0,
int  iRunFlags = 0 
)
protected

Returns true after a succesfull parsing, false otherwise.

pOutput is useful only for printing errors; if 0, no errors are printed

Parameters
pOutputThe output window for errors
iRunFlagsA combination of run flags (usually default)
Returns
bool

References KviKvsParser::AssumeLocals, AssumeLocals, detach(), KviKvsParser::error(), Expression, InstructionList, KviKvsScriptData::m_eType, KviKvsScriptData::m_pBuffer, m_pData, KviKvsScriptData::m_pTree, KviKvsScriptData::m_uLock, KviKvsScriptData::m_uRefs, p, Parameter, KviKvsParser::parse(), KviKvsParser::parseAsExpression(), KviKvsParser::parseAsParameter(), KviKvsParser::Pedantic, Pedantic, and Quiet.

Referenced by run().

int KviKvsScript::run ( KviWindow pWnd,
KviKvsVariantList pParams = 0,
KviKvsVariant pRetVal = 0,
int  iRunFlags = 0,
KviKvsExtendedRunTimeData pExtData = 0 
)

Runs the script.

Returns 0 (KviKvsScript::RunFailure) on error Returns a nonzero combination of RunStatus flags on success

If PreserverParams is not used, the ownership is transferred. Extended data is used if you need to pass extended scope variables or alias switch lists...)

Parameters
pWndThe window that the command has to be bound to
pParamsThe parameter list (0 if you don't pass params)
pRetValReturn value buffer (0 if you ignore it)
iRunFlagsA combination of run flags (usually default)
pExtDataExtended data (usually 0)
Returns
int

References Error, execute(), m_pData, KviKvsScriptData::m_pTree, parse(), and PreserveParams.

Referenced by KviKvsAction::activate(), KviApplication::autoConnectToServers(), avatar_kvs_cmd_set(), KviScriptUserButton::btnClicked(), ClassEditorWidget::build(), KviKvsObjectScriptFunctionHandler::call(), ChannelsJoinDialog::clearClicked(), OptionsWidget_textEncoding::commit(), OptionsWidget_servers::connectCurrentClicked(), KviIrcContext::connectToCurrentServer(), KviApplication::createFrame(), KviIrcContext::createLinksWindow(), KviIrcContext::createListWindow(), KviMainWindow::customizeToolBars(), UrlDialog::dblclk_url(), KviKvsScriptAddon::description(), KviKvsUserAction::description(), KviKvsDnsManager::dnsLookupTerminated(), KviInputEditor::dropEvent(), evaluate(), evaluateAsString(), KviKvsPopupMenuItem::evaluateCondition(), KviKvsPopupMenuItemWithTextAndIcon::evaluateIcon(), KviKvsTreeNodeAliasFunctionCall::evaluateReadOnly(), KviKvsPopupMenuItemWithTextAndIcon::evaluateText(), CodeTesterWidget::execute(), KviKvsTreeNodeAliasSimpleCommand::execute(), KviKvsCallbackObject::execute(), KviKvsScriptAddon::executeConfigureCallback(), KviKvsScriptAddon::executeHelpCallback(), KviMainWindow::executeInternalCommand(), KviConsoleWindow::executeInternalCommand(), KviKvsScriptAddon::executeUninstallCallback(), AddonManagementDialog::getMoreScripts(), KviStatusBarUpdateIndicator::getNewVersion(), AddonFunctions::installAddonPackage(), KviFileTransferManager::invokeTransferWindow(), KviApplication::ipcMessage(), ChannelsJoinDialog::joinClicked(), KviKvsCoreSimpleCommands::KVSCSC(), KviCustomToolBarDescriptor::label(), KviKvsObjectClass::load(), KviApplication::loadDefaultScript(), KviIrcConnection::loginComplete(), KviIrcConnection::loginToIrcServer(), KviKvsAsyncDnsOperation::lookupTerminated(), KviStatusBarAwayIndicator::mouseDoubleClickEvent(), KviIrcView::mouseDoubleClickEvent(), ClassEditorWidget::newClass(), KviMenuBar::newConnectionToServer(), KviAsyncAvatarSelectionDialog::okClicked(), KviIrcServerParser::parseCtcpReplyAvatar(), KviIrcServerParser::parseCtcpRequestAction(), KviIrcServerParser::parseLiteralKick(), KviIrcServerParser::parseLiteralNotice(), KviIrcServerParser::parseLiteralPrivmsg(), KviIrcServerParser::parseNumericEndOfWhois(), KviIrcServerParser::parseNumericNoSuchNick(), KviIrcServerParser::parseNumericNoSuchServer(), KviInputEditor::pasteFile(), KviInputEditor::pasteSlow(), KviSoundSelector::playSound(), KviJoinChannelAction::popupActivated(), KviChangeNickAction::popupActivated(), KviConnectToServerAction::popupActivated(), KviChangeUserModeAction::popupActivated(), OptionsWidget_servers::recentServersPopupClicked(), ChannelsJoinDialog::regClicked(), DccFileTransfer::retryDCC(), DccFileTransfer::retryRevDCC(), DccFileTransfer::retryTDCC(), KviIrcUrl::run(), run(), UrlDialog::sayToWin(), setup_finish(), KviInputEditor::stopPasteSlow(), KviKvsTimerManager::timerEvent(), HttpFileTransfer::transferTerminated(), KviKvsProcessAsyncOperation::trigger(), KviKvsEventManager::triggerHandlers(), KviIrcView::triggerMouseRelatedKvsEvents(), KviConsoleWindow::triggerOnHighlight(), KviKvsScriptAddon::visibleName(), and KviKvsUserAction::visibleName().

int KviKvsScript::run ( KviWindow pWnd,
KviKvsVariantList pParams,
QString &  szRetVal,
int  iRunFlags = 0,
KviKvsExtendedRunTimeData pExtData = 0 
)

Runs the script.

Returns 0 (KviKvsScript::RunFailure) on error Returns a nonzero combination of RunStatus flags on success

The QString return buffer is useful only for evaluating InstructionList scripts. If PreserverParams is not used, the ownership is transferred. Extended data is used if you need to pass extended scope variables or alias switch lists...)

Parameters
pWndThe window that the command has to be bound to
pParamsThe parameter list (0 if you don't pass params)
szRetValReturn value buffer
iRunFlagsA combination of run flags (usually default)
pExtDataExtended data (usually 0)
Returns
int

References KviKvsVariant::asString(), and run().

int KviKvsScript::run ( KviKvsRunTimeContext pContext,
int  iRunFlags = 0 
)

Runs the script.

Returns 0 (KviKvsScript::RunFailure) on error Returns a nonzero combination of RunStatus flags on success

This is probably used only in /eval

Parameters
pContextThe context where the script is bound to
iRunFlagsA combination of run flags (usually default)
Returns
int

References KviKvsRunTimeContext::disableReporting(), KviKvsRunTimeContext::enableReporting(), Error, executeInternal(), m_pData, KviKvsScriptData::m_pTree, parse(), Quiet, KviKvsRunTimeContext::reportingDisabled(), and KviKvsRunTimeContext::window().

int KviKvsScript::run ( const QString &  szCode,
KviWindow pWindow,
KviKvsVariantList pParams = 0,
KviKvsVariant pRetVal = 0 
)
static

Static helper for quick running.

Returns a combination of RunStatus flags (nonzero on no error) It does NOT take params ownership

Parameters
szCodeThe source code to run
pWindowThe window that the command has to be bound to
pParamsThe parameter list (0 if you don't pass params)
pRetValReturn value buffer (0 if you ignore it)
Returns
int

References PreserveParams, run(), and s.

void KviKvsScript::setName ( const QString &  szName)

Sets the name of the script context.

Parameters
szNameThe name of the context
Returns
void

References detach(), m_pData, KviKvsScriptData::m_szName, and KviKvsScriptData::m_uRefs.

Referenced by KviKvsCoreCallbackCommands::KVSCCC().

Friends And Related Function Documentation

friend class KviKvsObject
friend
friend class KviKvsParser
friend
friend class KviKvsRunTimeContext
friend

Member Data Documentation

KviKvsScriptData* KviKvsScript::m_pData
private

The documentation for this class was generated from the following files: