Author: dmacvicar Date: Tue Nov 3 13:43:05 2009 New Revision: 59275 URL: http://svn.opensuse.org/viewcvs/yast?rev=59275&view=rev Log: support for nested namespaces (Foo::Bar) (bnc #551881) Added: trunk/ruby-bindings/src/ruby/Y2RubyUtils.cc trunk/ruby-bindings/src/ruby/Y2RubyUtils.h Modified: trunk/ruby-bindings/src/ruby/CMakeLists.txt trunk/ruby-bindings/src/ruby/YRuby.cc trunk/ruby-bindings/src/ruby/YRubyNamespace.cc Modified: trunk/ruby-bindings/src/ruby/CMakeLists.txt URL: http://svn.opensuse.org/viewcvs/yast/trunk/ruby-bindings/src/ruby/CMakeLists... ============================================================================== --- trunk/ruby-bindings/src/ruby/CMakeLists.txt (original) +++ trunk/ruby-bindings/src/ruby/CMakeLists.txt Tue Nov 3 13:43:05 2009 @@ -7,6 +7,7 @@ Y2RubyTypeTerm.cc # YCP.cc -> ryast_term_init() Y2RubyTypeConv.cc # YCP.cc -> ycpvalue_2_rbvalue(), rbvalue_2_ycpvalue() RubyLogger.cc + Y2RubyUtils.cc RubyLogger.h ) @@ -19,6 +20,7 @@ Y2RubyTypeConv.cc Y2RubyTypePath.cc Y2RubyTypeTerm.cc + Y2RubyUtils.cc ) SET(ruby_yast_plugin_HEADERS @@ -27,6 +29,7 @@ Y2RubyComponent.h YRuby.h YRubyNamespace.h + Y2RubyUtils.h Y2RubyTypePath.h Y2RubyTypeTerm.h ) Added: trunk/ruby-bindings/src/ruby/Y2RubyUtils.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/ruby-bindings/src/ruby/Y2RubyUtil... ============================================================================== --- trunk/ruby-bindings/src/ruby/Y2RubyUtils.cc (added) +++ trunk/ruby-bindings/src/ruby/Y2RubyUtils.cc Tue Nov 3 13:43:05 2009 @@ -0,0 +1,20 @@ +#include <vector> +#include <string> + +#include "y2util/stringutil.h" +#include "Y2RubyUtils.h" + +using namespace std; + +VALUE y2ruby_nested_const_get(const std::string &name) +{ + VALUE module = rb_mKernel; + // to save every component of Foo::Bar::Ehh + vector<string> name_levels; + stringutil::split( name, name_levels, "::", false); + + for ( unsigned i = 0; i < name_levels.size(); ++i ) { + module = rb_funcall( module, rb_intern("const_get"), 1, rb_str_new2(name_levels[i].c_str()) ); + } + return module; +} Added: trunk/ruby-bindings/src/ruby/Y2RubyUtils.h URL: http://svn.opensuse.org/viewcvs/yast/trunk/ruby-bindings/src/ruby/Y2RubyUtil... ============================================================================== --- trunk/ruby-bindings/src/ruby/Y2RubyUtils.h (added) +++ trunk/ruby-bindings/src/ruby/Y2RubyUtils.h Tue Nov 3 13:43:05 2009 @@ -0,0 +1,34 @@ +/*---------------------------------------------------------------------\ +| | +| __ __ ____ _____ ____ | +| \ \ / /_ _/ ___|_ _|___ \ | +| \ V / _` ___ \ | | __) | | +| | | (_| |___) || | / __/ | +| |_|__,_|____/ |_| |_____| | +| | +| | +| ruby language support (C) Novell Inc. | +----------------------------------------------------------------------/ + +Author: Duncan Mac-Vicar <dmacvicar@suse.de> + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version +2 of the License, or (at your option) any later version. + +*/ + +#ifndef Y2RubyUtils_H +#define Y2RubyUtils_H + +#include <ruby.h> +#include <string> + +/** + * string to constant, with nested + * support ("Foo::Bar" strings) + */ +VALUE y2ruby_nested_const_get(const std::string &name); + +#endif Modified: trunk/ruby-bindings/src/ruby/YRuby.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/ruby-bindings/src/ruby/YRuby.cc?r... ============================================================================== --- trunk/ruby-bindings/src/ruby/YRuby.cc (original) +++ trunk/ruby-bindings/src/ruby/YRuby.cc Tue Nov 3 13:43:05 2009 @@ -49,6 +49,7 @@ #include <ycp/YCPExternal.h> #include "YRuby.h" +#include "Y2RubyUtils.h" #define DIM(ARRAY) ( sizeof( ARRAY )/sizeof( ARRAY[0] ) ) @@ -142,7 +143,7 @@ YRuby::callInner (string module_name, string function, bool method, YCPList argList, constTypePtr wanted_result_type) { - VALUE module = rb_funcall( rb_mKernel, rb_intern("const_get"), 1, rb_str_new2(module_name.c_str()) ); + VALUE module = y2ruby_nested_const_get(module_name); if (module == Qnil) { y2error ("The Ruby module '%s' is not provided by its rb file", module_name.c_str()); Modified: trunk/ruby-bindings/src/ruby/YRubyNamespace.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/ruby-bindings/src/ruby/YRubyNames... ============================================================================== --- trunk/ruby-bindings/src/ruby/YRubyNamespace.cc (original) +++ trunk/ruby-bindings/src/ruby/YRubyNamespace.cc Tue Nov 3 13:43:05 2009 @@ -31,9 +31,11 @@ #include <ycp/Type.h> #include <ycp/YCPVoid.h> //#include <YCP.h> -#include "YRuby.h" #include <stdio.h> +#include "YRuby.h" +#include "Y2RubyUtils.h" + /** * using this instead of plain strcmp * enables embedding argument names into the typeinfo @@ -175,18 +177,12 @@ } }; - - YRubyNamespace::YRubyNamespace (string name) : m_name (name), m_all_methods (true) { y2milestone("Creating namespace for '%s'", name.c_str()); - - //y2milestone("loadModule 3.5"); - //VALUE result = rb_eval_string((require_module).c_str()); - - VALUE module = rb_funcall( rb_mKernel, rb_intern("const_get"), 1, rb_str_new2(name.c_str()) ); + VALUE module = y2ruby_nested_const_get(name); if (module == Qnil) { y2error ("The Ruby module '%s' is not provided by its rb file", name.c_str()); @@ -222,7 +218,6 @@ { //sym_tp = new FunctionType (Type::Any, new FunctionType(Type::Any) ); // figure out arity. - y2milestone("1."); Check_Type(module,T_MODULE); VALUE methodobj = rb_funcall( module, rb_intern("method"), 1, current ); //VALUE methodobj = rb_funcall( module, rb_intern("send"), 2, rb_str_new2("method"), current ); @@ -231,10 +226,8 @@ y2error ("Cannot access method object '%s'", RSTRING(current)->ptr); continue; } - y2milestone("2."); string signature = "any( "; VALUE rbarity = rb_funcall( methodobj, rb_intern("arity"), 0); - y2milestone("3."); int arity = NUM2INT(rbarity); for ( int k=0; k < arity; ++k ) { -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org