lib Library API Documentation

KSInterpreter Class Reference

This class offers the API to koscript functionality. More...

#include <koscript.h>

Collaboration diagram for KSInterpreter:

Collaboration graph
[legend]
List of all members.

Public Types

typedef KSSharedPtr< KSInterpreterPtr

Public Member Functions

 KSInterpreter ()
virtual ~KSInterpreter ()
QString runScript (const QString &filename, const QStringList &args)
bool runModule (KSContext &context, const QString &name, const QString &filename, const QStringList &args)
bool runModule (KSContext &context, const QString &name)
KSModule::Ptr module (const QString &name)
KSContext & context ()
void addSearchPath (const QString &p)
virtual bool processExtension (KSContext &context, KSParseNode *node)
KRegExp * regexp ()
QString readInput ()
KSValue::Ptr lastInputLine () const
KSNamespaceglobalNamespace ()

Protected Attributes

KSNamespacem_global
KSContext m_globalContext
QMap< QString, KSModule::Ptrm_modules
QStringList m_searchPaths
KRegExp m_regexp
QStringList m_args
int m_currentArg
QTextStreamm_outStream
QIODevicem_outDevice
KSValue::Ptr m_lastInputLine

Detailed Description

This class offers the API to koscript functionality.

If you want to execute a koscript on your hard disk or if you want to embed koscript in your application, then you need an instance of this class.

Author:
Torben Weis <weis@kde.org>

Definition at line 45 of file koscript.h.


Constructor & Destructor Documentation

KSInterpreter::KSInterpreter  ) 
 

Creates a new interpreter.

It is ok to have many of them at the same time.

Definition at line 39 of file koscript.cc.

References m_currentArg, m_global, m_globalContext, m_lastInputLine, m_modules, m_outDevice, and m_outStream.

KSInterpreter::~KSInterpreter  )  [virtual]
 

Destroys the interpreter and all associated modules etc.

Definition at line 58 of file koscript.cc.

References m_outDevice.


Member Function Documentation

QString KSInterpreter::runScript const QString filename,
const QStringList args
 

Reads the script filename from the hard disk and tries to execute it.

Parameters:
args is the list of parameters passed to the main function
Returns:
the stringified exception or an empty string if everything was ok. This is a convenience function for runModule.

Definition at line 78 of file koscript.cc.

References context(), m_args, m_globalContext, and runModule().

bool KSInterpreter::runModule KSContext &  context,
const QString name,
const QString filename,
const QStringList args
 

Runs a module located in the file filename.

The modules name is given by name. Usually you may want to use runScript instead.

Parameters:
context contains the initialized module as value and the exception in case of an error. Once the value ( read: the module ) of "context" is deleted, you may no longer use the exception contained in "context". That means you may not extract the exception and destroy the KSContext object and then still use the exception object.
args is the list of parameters passed to the main function

Definition at line 141 of file koscript.cc.

References KSValue::functionValue(), m_global, m_globalContext, and m_modules.

Referenced by runModule(), and runScript().

bool KSInterpreter::runModule KSContext &  context,
const QString name
 

This function is for convenience.

It searches the module in the search paths by appending a ".ks" suffix.

Definition at line 92 of file koscript.cc.

References m_modules, m_searchPaths, and runModule().

KSModule::Ptr KSInterpreter::module const QString name  ) 
 

Returns:
the pointer to an already loaded module or 0 if the module was not loaded successfully until now.

Definition at line 69 of file koscript.cc.

References m_modules.

KSContext& KSInterpreter::context  )  [inline]
 

The global context is needed for destructors, callbacks etc.

This method is internal. DON'T USE.

Definition at line 100 of file koscript.h.

Referenced by runScript().

void KSInterpreter::addSearchPath const QString p  )  [inline]
 

Add a search path.

KScript will search for modules in this path.

See also:
runModule

Definition at line 107 of file koscript.h.

References m_searchPaths.

bool KSInterpreter::processExtension KSContext &  context,
KSParseNode *  node
[virtual]
 

KScript can be extended with special syntax.

For example "Table1!A1" for use in some spread sheet. If such a node has to be evaluated, then this functions is told to do so.

Returns:
TRUE if the evaluation was successful

Definition at line 252 of file koscript.cc.

KRegExp * KSInterpreter::regexp  ) 
 

Internal function for implementing regexp and $0, $1, $2, ...

Definition at line 260 of file koscript.cc.

QString KSInterpreter::readInput  ) 
 

Internal function for implementing the <> operator.

Definition at line 265 of file koscript.cc.

References m_args, m_currentArg, m_lastInputLine, m_outDevice, and m_outStream.

KSValue::Ptr KSInterpreter::lastInputLine  )  const
 

Internal function used for implementing the $_ operator.

Definition at line 311 of file koscript.cc.

KSNamespace* KSInterpreter::globalNamespace  )  [inline]
 

Internal function that returns the global namespace of this interpreter.

Definition at line 137 of file koscript.h.


Member Data Documentation

KSNamespace* KSInterpreter::m_global [protected]
 

A pointer to the namespace of the KScript module.

Definition at line 143 of file koscript.h.

Referenced by KSInterpreter(), and runModule().

KSContext KSInterpreter::m_globalContext [protected]
 

Used by destructors.

Since they are invoked by reference counters, they dont get a context. Instead they use this context.

Definition at line 148 of file koscript.h.

Referenced by KSInterpreter(), runModule(), and runScript().

QMap<QString,KSModule::Ptr> KSInterpreter::m_modules [protected]
 

Maps the names of successfully loaded modules to their KSModule object.

The name is the logical name of the module, that means NOT the filename.

Definition at line 154 of file koscript.h.

Referenced by KSInterpreter(), module(), and runModule().

QStringList KSInterpreter::m_searchPaths [protected]
 

List of all classes where we can search for modules.

Definition at line 158 of file koscript.h.

Referenced by addSearchPath(), and runModule().

KRegExp KSInterpreter::m_regexp [protected]
 

Rgeular expression matcher used for constructions like "/(.+) (.+)/".

Definition at line 162 of file koscript.h.

QStringList KSInterpreter::m_args [protected]
 

The last arguments passed to runScript.

They are saved here, since the <> operator may be used to read the files named by the arguments.

Definition at line 167 of file koscript.h.

Referenced by readInput(), and runScript().

int KSInterpreter::m_currentArg [protected]
 

When reading in files with the <> operator, then this variable tells us which file we just opened.

So it is used like this: m_args[ m_currentArg ]. The initial value is -1, that means no argument file was opened until now.

See also:
m_args.

Definition at line 175 of file koscript.h.

Referenced by KSInterpreter(), and readInput().

QTextStream* KSInterpreter::m_outStream [protected]
 

When reading in files with the <> operator, then this stream handles the current input file.

If there is no such input file specified in the command line then this stream points to stdin.

Definition at line 181 of file koscript.h.

Referenced by KSInterpreter(), and readInput().

QIODevice* KSInterpreter::m_outDevice [protected]
 

Used for m_stream.

Definition at line 185 of file koscript.h.

Referenced by KSInterpreter(), readInput(), and ~KSInterpreter().

KSValue::Ptr KSInterpreter::m_lastInputLine [protected]
 

The last line read by the <> operator is stored here.

lastInputLine

Definition at line 191 of file koscript.h.

Referenced by KSInterpreter(), and readInput().


The documentation for this class was generated from the following files:
KDE Logo
This file is part of the documentation for lib Library Version 1.3.5.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Mar 11 11:50:59 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003