summaryrefslogtreecommitdiffstats
path: root/lib/kross/api/script.h
blob: 708e905884f18350648f46d1fea4f0b6f8720e20 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/***************************************************************************
 * script.h
 * This file is part of the KDE project
 * copyright (C)2004-2005 by Sebastian Sauer (mail@dipe.org)
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 * You should have received a copy of the GNU Library General Public License
 * along with this program; see the file COPYING.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 ***************************************************************************/

#ifndef KROSS_API_SCRIPT_H
#define KROSS_API_SCRIPT_H

#include <tqstring.h>
#include <tqstringlist.h>

#include "class.h"

namespace Kross { namespace Api {

    // Forward declarations.
    class Object;
    class Interpreter;
    class ScriptContainer;
    class List;
    class Exception;

    /**
     * Base class for interpreter dependend functionality
     * each script provides.
     *
     * Each \a ScriptContainer holds a pointer to a class
     * that implements the \a Script functionality for the
     * defined \a Interpreter .
     */
    class Script
    {
        public:

            /**
             * Constructor.
             *
             * \param interpreter The \a Interpreter instance
             *       that uses this \a Script instance.
             * \param scriptcontainer The \a ScriptContainer instance
             *       this script is associated with.
             */
            Script(Interpreter* const interpreter, ScriptContainer* const scriptcontainer);

            /**
             * Destructor.
             */
            virtual ~Script();

            /**
             * \return true if the script throwed an exception
             *        else false.
             */
            bool hadException();

            /**
             * \return the \a Exception the script throwed.
             */
            Exception::Ptr getException();

            /**
             * Set a new exception this script throwed.
             *
             * \param e The \a Exception .
             */
            void setException(Exception::Ptr e);

            /**
             * Clear previous exceptions. If called \a hadException()
             * will return false again.
             */
            void clearException();

            /**
             * Execute the script.
             *
             * \throws Exception on error.
             * \return The execution result. Could be NULL too.
             */
            virtual Kross::Api::Object::Ptr execute() = 0;

            /**
             * \return a list of callable functionnames this
             * script spends.
             */
            virtual const TQStringList& getFunctionNames() = 0;

            /**
             * Call a function.
             *
             * \throws Exception on error.
             * \param name The name of the function to execute.
             * \param args Optional arguments passed to the function.
             * \return The result of the called function. Could be NULL.
             */
            virtual Kross::Api::Object::Ptr callFunction(const TQString& name, Kross::Api::List::Ptr args) = 0;

            /**
             * \return a list of classnames.
             */
            virtual const TQStringList& getClassNames() = 0;

            /**
             * Create and return a new class instance.
             *
             * \throws Exception on error.
             * \param name The name of the class to create a instance of.
             * \return The new classinstance.
             */
            virtual Kross::Api::Object::Ptr classInstance(const TQString& name) = 0;

        protected:
            /// The \a Interpreter used to create this Script instance.
            Interpreter* const m_interpreter;
            /// The \a ScriptContainer associated with this Script.
            ScriptContainer* const m_scriptcontainer;

        private:
            /// The \a Exception this script throwed.
            Exception::Ptr m_exception;
    };

}}

#endif