lib

rubymodule.cpp
1/***************************************************************************
2 * rubyinterpreter.cpp
3 * This file is part of the KDE project
4 * copyright (C)2005 by Cyrille Berger (cberger@cberger.net)
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#include "rubymodule.h"
21
22#include "rubyconfig.h"
23#include "rubyextension.h"
24
25namespace Kross {
26
27namespace Ruby {
28
29class RubyModulePrivate {
30 friend class RubyModule;
33
34};
35
36RubyModule::RubyModule(Kross::Api::Module::Ptr mod, TQString modname) : d(new RubyModulePrivate)
37{
38 d->m_module = mod;
39 modname = modname.left(1).upper() + modname.right(modname.length() - 1 );
40 krossdebug(TQString("Module: %1").arg(modname));
41 VALUE rmodule = rb_define_module(modname.ascii());
42 rb_define_module_function(rmodule,"method_missing", (VALUE (*)(...))RubyModule::method_missing, -1);
43 VALUE rm = RubyExtension::toVALUE( (Kross::Api::Object::Ptr)mod.data() );
44 rb_define_const(rmodule, "MODULEOBJ", rm);
45}
46
50
51VALUE RubyModule::method_missing(int argc, VALUE *argv, VALUE self)
52{
53#ifdef KROSS_RUBY_MODULE_DEBUG
54 TQString funcname = rb_id2name(SYM2ID(argv[0]));
55 krossdebug(TQString("Function %1 missing in a module").arg(funcname));
56#endif
57
58 VALUE rubyObjectModule = rb_funcall( self, rb_intern("const_get"), 1, ID2SYM(rb_intern("MODULEOBJ")) );
59 RubyModule* objectModule;
60 Data_Get_Struct(rubyObjectModule, RubyModule, objectModule);
61 Kross::Api::Object::Ptr object = (Kross::Api::Object*)objectModule->d->m_module;
62
63 return RubyExtension::call_method(object, argc, argv);
64}
65
66}
67
68}
TDESharedPtr< Module > Ptr
Shared pointer to implement reference-counting.
Definition module.h:41
The common Object class all other object-classes are inheritated from.
Definition object.h:51
TDESharedPtr< Object > Ptr
Shared pointer to implement reference-counting.
Definition object.h:57
RubyModule(Kross::Api::Module::Ptr mod, TQString modname)
Constructor.
The Ruby plugin for the Kross scripting framework.
Definition rubyconfig.h:33
The Kross scripting bridge to embed scripting functionality into an application.
Definition callable.h:31
void krossdebug(const TQString &s)
Debugging function.