lib
rubymodule.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "rubymodule.h"
00021
00022 #include <kdebug.h>
00023
00024 #include <api/object.h>
00025
00026 #include "rubyconfig.h"
00027 #include "rubyextension.h"
00028
00029 namespace Kross {
00030
00031 namespace Ruby {
00032
00033 class RubyModulePrivate {
00034 friend class RubyModule;
00036 Kross::Api::Module* m_module;
00037
00038 };
00039
00040 RubyModule::RubyModule(Kross::Api::Module* mod, QString modname) : d(new RubyModulePrivate)
00041 {
00042 d->m_module = mod;
00043 modname = modname.left(1).upper() + modname.right(modname.length() - 1 );
00044 kdDebug() << modname << endl;
00045 VALUE rmodule = rb_define_module(modname.ascii());
00046 rb_define_module_function(rmodule,"method_missing", (VALUE (*)(...))RubyModule::method_missing, -1);
00047 VALUE rm = RubyExtension::toVALUE((Kross::Api::Object*)mod);
00048 rb_define_const(rmodule, "MODULEOBJ", rm);
00049 }
00050
00051 RubyModule::~RubyModule()
00052 {
00053 }
00054
00055 VALUE RubyModule::method_missing(int argc, VALUE *argv, VALUE self)
00056 {
00057 #ifdef KROSS_RUBY_MODULE_DEBUG
00058 QString funcname = rb_id2name(SYM2ID(argv[0]));
00059 kdDebug() << "Function " << funcname << " \"missing\" in a module" << endl;
00060 #endif
00061
00062 VALUE rubyObjectModule = rb_funcall( self, rb_intern("const_get"), 1, ID2SYM(rb_intern("MODULEOBJ")) );
00063 RubyModule* objectModule;
00064 Data_Get_Struct(rubyObjectModule, RubyModule, objectModule);
00065 Kross::Api::Object::Ptr object = (Kross::Api::Object*)objectModule->d->m_module;
00066
00067 return RubyExtension::call_method(object, argc, argv);
00068 }
00069
00070 }
00071
00072 }
|