summaryrefslogtreecommitdiffstats
path: root/lib/kross/ruby/rubyextension.h
blob: f6287961c9b1610e42621e43bd6e101275f7467f (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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/***************************************************************************
 * rubyinterpreter.cpp
 * This file is part of the KDE project
 * copyright (C)2005 by Cyrille Berger (cberger@cberger.net)
 *
 * 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_RUBYRUBYEXTENSION_H
#define KROSS_RUBYRUBYEXTENSION_H

#include <ruby.h>

#include <api/class.h>
#include <api/dict.h>
#include <api/list.h>
#include <api/object.h>

namespace Kross {

namespace Ruby {

class RubyExtensionPrivate;

/**
 * This class wraps a \a Kross::Api::Object into the world of ruby.
 * @author Cyrille Berger
 */
class RubyExtension{
        friend class RubyInterpreter;
        friend class RubyModule;
        friend class RubyScript;
    public:
        /**
         * Constructor.
         *
         * @param object The \a Kross::Api::Object instance this
         *        extension provides access to.
         */
        RubyExtension(Kross::Api::Object::Ptr object);
        /**
         * Destructor.
         */
        ~RubyExtension();
    private:
        /**
         * This function will catch functions that are undefined.
         */
        static VALUE method_missing(int argc, VALUE *argv, VALUE self);
        /**
         * This function will call a function in a Kross object
         * @param obj kross object which contains the function
         * @param argc the number of argument
         * @param argv the lists of arguments (the first argument is the Ruby ID of the function)
         */
        static VALUE call_method( Kross::Api::Object::Ptr obj, int argc, VALUE *argv);
        /**
         * This function is called by ruby to delete a RubyExtension object
         */
        static void delete_object(void* object);
        /**
         * This function is called by ruby to delete a RubyExtension object
         */
        static void delete_exception(void* object);
    private: // Tests
        /**
         * Test if the ruby object is an exception.
         */
        static bool isOfExceptionType(VALUE obj);
        /**
         * Test if the ruby object is an object
         */
        static bool isOfObjectType(VALUE obj);
    private: //Converting functions
        /**
         * Convert a ruby object to the exception type.
         * @return 0 if the object wasn't an exception.
         */
        static Kross::Api::Exception::Ptr convertToException(VALUE obj);
        /**
         * Wrap an exception in a ruby object.
         */
        static VALUE convertFromException(Kross::Api::Exception::Ptr exc);
        /**
         * This function iterats through a ruby hash
         */
        static int convertHash_i(VALUE key, VALUE value, VALUE vmap);
        /**
         * Converts a \a VALUE into a \a Kross::Api::Object.
         * \param object The ruby VALUE to convert.
         * \return The to a Kross::Api::Object converted Py::Object.
         */
        static Kross::Api::Object::Ptr toObject(VALUE value);
        /**
         * Converts a TQString to a VALUE. If
         * the TQString isNull() then a "" will
         * be returned.
         * \param s The TQString to convert.
         * \return The converted TQString.
         */
        static VALUE toVALUE(const TQString& s);

        /**
         * Converts a TQStringList to a VALUE.
         * \param list The TQStringList to convert.
         * \return The converted TQStringList.
         */
        static VALUE toVALUE(TQStringList list);

        /**
         * Converts a TQMap to a VALUE.
         * \param map The TQMap to convert.
         * \return The converted TQMap.
         */
        static VALUE toVALUE(TQMap<TQString, TQVariant> map);

        /**
         * Converts a TQValueList to a VALUE.
         * \param list The TQValueList to convert.
         * \return The converted TQValueList.
         */
        static VALUE toVALUE(TQValueList<TQVariant> list);
        /**
         * Converts a TQVariant to a VALUE.
         * \param variant The TQVariant to convert.
         * \return The converted TQVariant.
         */
        static VALUE toVALUE(const TQVariant& variant);

        /**
         * Converts a \a Kross::Api::Object to a VALUE.
         * \param object The Kross::Api::Object to convert.
         * \return The converted Kross::Api::Object.
         */
        static VALUE toVALUE(Kross::Api::Object::Ptr object);

        /**
         * Converts a \a Kross::Api::List into a VALUE.
         * \param list The Kross::Api::List to convert.
         * \return The converted Kross::Api::List.
         */
        static VALUE toVALUE(Kross::Api::List::Ptr list);
    private:
        /// Private d-pointer.
        RubyExtensionPrivate* d;
 };

}

}

#endif