Script Class Reference

A chunk of scripting code. Abstract. More...

`#include <Script.h>`

Inheritance diagram for Script:

## Public Slots

virtual bool | compile (bool for_eval=true)
| Compile the Code. Return true if the implementation doesn't support compilation. More...
virtual QVariant | eval ()
| Evaluate the Code, returning QVariant() on an error / exception. More...
virtual bool | exec ()
| Execute the Code, returning false on an error / exception. More...
virtual bool | setDouble (double, const char *)
virtual bool | setInt (int, const char *)
virtual bool | setQObject (const QObject *, const char *)

## Signals

void | codeChanged ()
| This is emitted whenever the code to be executed by exec() and eval() is changed. More...
void | error (const QString &message, const QString &scriptName, int lineNumber)
| signal an error condition / exception More...
void | print (const QString &output)
| output generated by the code More...

## Public Member Functions

virtual void | addCode (const QString &code)
| Append to the code that will be executed when calling exec() or eval() More...
const QString | code () const
| Return the code that will be executed when calling exec() or eval() More...
QObject * | context () const
| Return the context in which the code is to be executed. More...
bool | emitErrors () const
| Return whether errors / exceptions are to be emitted or silently ignored. More...
const QString | name () const
| Like QObject::name, but with unicode support. More...
| Script (ScriptingEnv *env, const QString &code, QObject *context=0, const QString &name="<input>")
ScriptingEnv * | scriptingEnv ()
virtual void | setCode (const QString &code)
| Set the code that will be executed when calling exec() or eval() More...
virtual void | setContext (QObject *context)
| Set the context in which the code is to be executed. More...
void | setEmitErrors (bool yes)
| Set whether errors / exceptions are to be emitted or silently ignored. More...
void | setName (const QString &name)
| Like QObject::setName, but with unicode support. More...
| ~Script ()

## Protected Types

enum | compileStatus { notCompiled, isCompiled, compileErr }

## Protected Member Functions

void | emit_error (const QString &message, int lineNumber)

## Protected Attributes

QString | Code
enum Script::compileStatus | compiled
QObject * | Context
bool | EmitErrors
ScriptingEnv * | Env
QString | Name

## Detailed Description

A chunk of scripting code. Abstract.

Script objects represent a chunk of code, possibly together with local variables. The code may be changed and executed multiple times during the lifetime of an object.

## Member Enumeration Documentation

enum Script::compileStatus

protected

Enumerator
notCompiled |
isCompiled |
compileErr |

## Constructor & Destructor Documentation

Script::Script | ( | ScriptingEnv * | env,
|  | const QString & | code,
|  | QObject * | context = `0`,
|  | const QString & | name = `"<input>"`
| ) |  |

inline

References context(), Context, EmitErrors, Env, and ScriptingEnv::incref().

Script::~Script | ( |  | ) |

inline

References ScriptingEnv::decref(), and Env.

## Member Function Documentation

virtual void Script::addCode | ( | const QString & | code | ) |

inline virtual

Append to the code that will be executed when calling exec() or eval()

References Code, codeChanged(), compiled, and notCompiled.

const QString Script::code | ( |  | ) | const

inline

Return the code that will be executed when calling exec() or eval()

References Code.

Referenced by ScriptEdit::evaluate(), and setCode().

void Script::codeChanged | ( |  | ) |

signal

This is emitted whenever the code to be executed by exec() and eval() is changed.

Referenced by addCode(), and setCode().

bool Script::compile | ( | bool | for_eval = `true` | ) |

virtual slot

Compile the Code. Return true if the implementation doesn't support compilation.

References emit_error().

Referenced by MatrixModel::calculate(), Table::calculate(), and Matrix::canCalculate().

QObject* Script::context | ( |  | ) | const

inline

Return the context in which the code is to be executed.

References Context.

Referenced by ScriptEdit::contextMenuEvent(), Script(), setContext(), and ScriptEdit::setFileName().

void Script::emit_error | ( | const QString & | message,
|  | int | lineNumber
| ) |  |

inline protected

References error().

Referenced by muParserScript::compile(), PythonScript::compile(), compile(), muParserScript::defineVariable(), muParserScript::eval(), PythonScript::eval(), eval(), muParserScript::exec(), PythonScript::exec(), exec(), and muParserScript::setDouble().

bool Script::emitErrors | ( |  | ) | const

inline

Return whether errors / exceptions are to be emitted or silently ignored.

References EmitErrors.

void Script::error | ( | const QString & | message,
|  | const QString & | scriptName,
|  | int | lineNumber
| ) |  |

signal

signal an error condition / exception

Referenced by emit_error(), and muParserScript::muParserScript().

QVariant Script::eval | ( |  | ) |

virtual slot

Evaluate the Code, returning QVariant() on an error / exception.

References emit_error().

Referenced by MatrixModel::calculate(), Table::calculate(), Matrix::canCalculate(), Table::cellEdited(), and ScriptEdit::evaluate().

bool Script::exec | ( |  | ) |

virtual slot

Execute the Code, returning false on an error / exception.

References emit_error().

Referenced by ScriptEdit::execute(), and ScriptEdit::executeAll().

const QString Script::name | ( |  | ) | const

inline

Like QObject::name, but with unicode support.

References Name.

Referenced by muParserScript::defineVariable(), muParserScript::setDouble(), and setName().

void Script::print | ( | const QString & | output | ) |

signal

output generated by the code

Referenced by muParserScript::muParserScript(), and PythonScript::write().

ScriptingEnv* Script::scriptingEnv | ( |  | ) |

inline

References Env.

Referenced by ScriptEdit::contextMenuEvent(), ScriptEdit::evaluate(), and muParserScript::tablecol().

virtual void Script::setCode | ( | const QString & | code | ) |

inline virtual

Set the code that will be executed when calling exec() or eval()

References code(), Code, codeChanged(), compiled, and notCompiled.

Referenced by ScriptEdit::evaluate(), ScriptEdit::execute(), and ScriptEdit::executeAll().

virtual void Script::setContext | ( | QObject * | context | ) |

inline virtual

Set the context in which the code is to be executed.

References compiled, context(), Context, and notCompiled.

Referenced by PythonScript::setContext(), and ScriptEdit::setContext().

virtual bool Script::setDouble | ( | double | ,
|  | const char * |
| ) |  |

inline virtual slot

Referenced by MatrixModel::calculate(), Table::calculate(), and Matrix::canCalculate().

void Script::setEmitErrors | ( | bool | yes | ) |

inline

Set whether errors / exceptions are to be emitted or silently ignored.

References EmitErrors.

virtual bool Script::setInt | ( | int | ,
|  | const char * |
| ) |  |

inline virtual slot

Referenced by Table::cellEdited().

void Script::setName | ( | const QString & | name | ) |

inline

Like QObject::setName, but with unicode support.

References compiled, name(), Name, and notCompiled.

Referenced by ScriptEdit::evaluate(), ScriptEdit::execute(), and ScriptEdit::executeAll().

virtual bool Script::setQObject | ( | const QObject * | ,
|  | const char * |
| ) |  |

inline virtual slot

## Member Data Documentation

QString Script::Code

protected

Referenced by addCode(), code(), muParserScript::compile(), PythonScript::compile(), and setCode().

enum Script::compileStatus Script::compiled

protected

Referenced by addCode(), muParserScript::compile(), PythonScript::compile(), muParserScript::eval(), PythonScript::eval(), muParserScript::exec(), PythonScript::exec(), setCode(), setContext(), PythonScript::setDouble(), PythonScript::setInt(), setName(), and PythonScript::setQObject().

QObject* Script::Context

protected

Referenced by muParserScript::avg(), muParserScript::cell(), muParserScript::col(), PythonScript::compile(), context(), muParserScript::max(), muParserScript::min(), muParserScript::muParserScript(), PythonScript::PythonScript(), Script(), PythonScript::setContext(), setContext(), muParserScript::sum(), muParserScript::tableCell(), and muParserScript::tablecol().

bool Script::EmitErrors

protected

Referenced by emitErrors(), Script(), and setEmitErrors().

ScriptingEnv* Script::Env

protected

Referenced by PythonScript::env(), Script(), scriptingEnv(), and ~Script().

QString Script::Name

protected

Referenced by PythonScript::compile(), name(), and setName().

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

- qtiplot/src/scripting/Script.h
- qtiplot/src/scripting/Script.cpp