Kross

core/script.h
1 /***************************************************************************
2  * script.h
3  * This file is part of the KDE project
4  * copyright (C)2004-2006 by Sebastian Sauer ([email protected])
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Library General Public License for more details.
14  * You should have received a copy of the GNU Library General Public License
15  * along with this program; see the file COPYING. If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  ***************************************************************************/
19 
20 #ifndef KROSS_SCRIPT_H
21 #define KROSS_SCRIPT_H
22 
23 #include "errorinterface.h"
24 
25 #include <QStringList>
26 #include <QVariant>
27 #include <QObject>
28 
29 namespace Kross
30 {
31 
32 // Forward declarations.
33 class Interpreter;
34 class Action;
35 
36 /**
37  * Base class for interpreter dependent functionality
38  * each script provides.
39  *
40  * Each \a Action holds a pointer to a class
41  * that implements the \a Script functionality for the
42  * defined \a Interpreter .
43  */
44 class KROSSCORE_EXPORT Script : public QObject, public ErrorInterface
45 {
46  Q_OBJECT
47 public:
48 
49  /**
50  * Constructor.
51  *
52  * \param interpreter The \a Interpreter instance that
53  * was used to created this \a Script instance.
54  * \param Action The \a Action instance this script is
55  * associated with.
56  */
57  Script(Interpreter *interpreter, Action *action);
58 
59  /**
60  * Destructor.
61  */
62  ~Script() override;
63 
64 public Q_SLOTS:
65 
66  /**
67  * \return the \a Interpreter instance that was used to created
68  * this \a Script .
69  */
70  Interpreter *interpreter() const;
71 
72  /**
73  * \return the \a Action instance associated with this \a Script .
74  */
75  Action *action() const;
76 
77  /**
78  * Execute the script.
79  */
80  virtual void execute() = 0;
81 
82  /**
83  * \return the list of functionnames.
84  */
85  virtual QStringList functionNames() = 0;
86 
87  /**
88  * Call a function in the script.
89  *
90  * \param name The name of the function which should be called.
91  * \param args The optional list of arguments.
92  */
93  virtual QVariant callFunction(const QString &name, const QVariantList &args = QVariantList()) = 0;
94 
95  /**
96  * Evaluate some scripting code.
97  *
98  * \param code The scripting code to evaluate.
99  * \return The return value of the evaluation.
100  */
101  virtual QVariant evaluate(const QByteArray &code) = 0;
102 
103 private:
104  /// \internal d-pointer class.
105  class Private;
106  /// \internal d-pointer instance.
107  Private *const d;
108 };
109 
110 }
111 
112 #endif
113 
Base class for interpreter dependent functionality each script provides.
Definition: core/script.h:44
Interface for error-handling.
Definition: action.cpp:36
const QLatin1String name
Base class for interpreter implementations.
The Action class is an abstract container to deal with scripts like a single standalone script file...
Definition: action.h:95
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Fri Nov 26 2021 23:00:38 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.