File indexing completed on 2024-04-14 14:27:11

0001 /***************************************************************************
0002  * script.h
0003  * This file is part of the KDE project
0004  * copyright (C)2007-2008 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_QTS_SCRIPT_H
0021 #define KROSS_QTS_SCRIPT_H
0022 
0023 #include <kross/core/krossconfig.h>
0024 #include <kross/core/interpreter.h>
0025 #include <kross/core/manager.h>
0026 #include <kross/core/script.h>
0027 #include <kross/core/action.h>
0028 #include <kross/core/object.h>
0029 
0030 namespace Kross
0031 {
0032 
0033 /**
0034 * The EcmaScript class implements a \a Kross::Script to handle
0035 * a single script. Each script and script file will have its
0036 * own \a EcmaScript instance as container for a Ecma QtScript
0037 * that is managed by the \a Kross::Action class.
0038 */
0039 class EcmaScript : public Kross::Script
0040 {
0041     Q_OBJECT
0042 public:
0043 
0044     /**
0045     * Constructor.
0046     *
0047     * \param interpreter The \a EcmaInterpreter instance this
0048     * script belongs to.
0049     * \param action The \a Kross::Action instance that contains
0050     * details about the script and that decorates this script.
0051     */
0052     EcmaScript(Kross::Interpreter *interpreter, Kross::Action *action);
0053 
0054     /**
0055     * Destructor.
0056     */
0057     ~EcmaScript() override;
0058 
0059 public Q_SLOTS:
0060 
0061     /**
0062     * Executes the script.
0063     */
0064     void execute() override;
0065 
0066     /**
0067     * \return a list of function-names.
0068     */
0069     QStringList functionNames() override;
0070 
0071     /**
0072     * Execute a function.
0073     *
0074     * \param name The name of the function that should be called.
0075     * \param args The optional arguments for the function.
0076     * \return The return value of the function.
0077     */
0078     QVariant callFunction(const QString &name, const QVariantList &args = QVariantList()) override;
0079 
0080     /**
0081      * Evaluate some scripting code.
0082      *
0083      * \param code The scripting code to evaluate.
0084      * \return The return value of the evaluation.
0085      */
0086     QVariant evaluate(const QByteArray &code) override;
0087 
0088     /**
0089     * \return the internal used QScriptEngine instance.
0090     */
0091     QObject *engine() const;
0092 
0093 private:
0094     class Private;
0095     Private *const d;
0096 };
0097 
0098 }
0099 
0100 #endif