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 "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 }
|