lib

rubymodule.cpp

00001 /***************************************************************************
00002  * rubyinterpreter.cpp
00003  * This file is part of the KDE project
00004  * copyright (C)2005 by Cyrille Berger (cberger@cberger.net)
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Library General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2 of the License, or (at your option) any later version.
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Library General Public License for more details.
00014  * You should have received a copy of the GNU Library General Public License
00015  * along with this program; see the file COPYING.  If not, write to
00016  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018  ***************************************************************************/
00019 
00020 #include "rubymodule.h"
00021 
00022 #include "rubyconfig.h"
00023 #include "rubyextension.h"
00024 
00025 namespace Kross {
00026 
00027 namespace Ruby {
00028 
00029 class RubyModulePrivate {
00030     friend class RubyModule;
00032     Kross::Api::Module::Ptr m_module;
00033 
00034 };
00035 
00036 RubyModule::RubyModule(Kross::Api::Module::Ptr mod, QString modname) : d(new RubyModulePrivate)
00037 {
00038     d->m_module = mod;
00039     modname = modname.left(1).upper() + modname.right(modname.length() - 1 );
00040     krossdebug(QString("Module: %1").arg(modname));
00041     VALUE rmodule = rb_define_module(modname.ascii());
00042     rb_define_module_function(rmodule,"method_missing",  (VALUE (*)(...))RubyModule::method_missing, -1);
00043     VALUE rm = RubyExtension::toVALUE( mod.data() );
00044     rb_define_const(rmodule, "MODULEOBJ", rm);
00045 }
00046 
00047 RubyModule::~RubyModule()
00048 {
00049 }
00050 
00051 VALUE RubyModule::method_missing(int argc, VALUE *argv, VALUE self)
00052 {
00053 #ifdef KROSS_RUBY_MODULE_DEBUG
00054     QString funcname = rb_id2name(SYM2ID(argv[0]));
00055     krossdebug(QString("Function %1 missing in a module").arg(funcname));
00056 #endif
00057 
00058     VALUE rubyObjectModule = rb_funcall( self, rb_intern("const_get"), 1, ID2SYM(rb_intern("MODULEOBJ")) );
00059     RubyModule* objectModule;
00060     Data_Get_Struct(rubyObjectModule, RubyModule, objectModule);
00061     Kross::Api::Object::Ptr object = (Kross::Api::Object*)objectModule->d->m_module;
00062     
00063     return RubyExtension::call_method(object, argc, argv);
00064 }
00065 
00066 }
00067 
00068 }
KDE Home | KDE Accessibility Home | Description of Access Keys