File indexing completed on 2024-04-21 15:02:58
0001 /*************************************************************************** 0002 * script.h 0003 * This file is part of the KDE project 0004 * copyright (C)2004-2006 by Sebastian Sauer (mail@dipe.org) 0005 * 0006 * This program is free software; you can redistribute it and/or 0007 * modify it under the terms of the GNU Library General Public 0008 * License as published by the Free Software Foundation; either 0009 * version 2 of the License, or (at your option) any later version. 0010 * This program is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 * Library General Public License for more details. 0014 * You should have received a copy of the GNU Library General Public License 0015 * along with this program; see the file COPYING. If not, write to 0016 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 * Boston, MA 02110-1301, USA. 0018 ***************************************************************************/ 0019 0020 #ifndef KROSS_SCRIPT_H 0021 #define KROSS_SCRIPT_H 0022 0023 #include "errorinterface.h" 0024 0025 #include <QStringList> 0026 #include <QVariant> 0027 #include <QObject> 0028 0029 namespace Kross 0030 { 0031 0032 // Forward declarations. 0033 class Interpreter; 0034 class Action; 0035 0036 /** 0037 * Base class for interpreter dependent functionality 0038 * each script provides. 0039 * 0040 * Each \a Action holds a pointer to a class 0041 * that implements the \a Script functionality for the 0042 * defined \a Interpreter . 0043 */ 0044 class KROSSCORE_EXPORT Script : public QObject, public ErrorInterface 0045 { 0046 Q_OBJECT 0047 public: 0048 0049 /** 0050 * Constructor. 0051 * 0052 * \param interpreter The \a Interpreter instance that 0053 * was used to created this \a Script instance. 0054 * \param Action The \a Action instance this script is 0055 * associated with. 0056 */ 0057 Script(Interpreter *interpreter, Action *action); 0058 0059 /** 0060 * Destructor. 0061 */ 0062 ~Script() override; 0063 0064 public Q_SLOTS: 0065 0066 /** 0067 * \return the \a Interpreter instance that was used to created 0068 * this \a Script . 0069 */ 0070 Interpreter *interpreter() const; 0071 0072 /** 0073 * \return the \a Action instance associated with this \a Script . 0074 */ 0075 Action *action() const; 0076 0077 /** 0078 * Execute the script. 0079 */ 0080 virtual void execute() = 0; 0081 0082 /** 0083 * \return the list of functionnames. 0084 */ 0085 virtual QStringList functionNames() = 0; 0086 0087 /** 0088 * Call a function in the script. 0089 * 0090 * \param name The name of the function which should be called. 0091 * \param args The optional list of arguments. 0092 */ 0093 virtual QVariant callFunction(const QString &name, const QVariantList &args = QVariantList()) = 0; 0094 0095 /** 0096 * Evaluate some scripting code. 0097 * 0098 * \param code The scripting code to evaluate. 0099 * \return The return value of the evaluation. 0100 */ 0101 virtual QVariant evaluate(const QByteArray &code) = 0; 0102 0103 private: 0104 /// \internal d-pointer class. 0105 class Private; 0106 /// \internal d-pointer instance. 0107 Private *const d; 0108 }; 0109 0110 } 0111 0112 #endif 0113