Mailinglist Archive: yast-commit (747 mails)

< Previous Next >
[yast-commit] r39682 - in /trunk/ruby-bindings: ./ src/ruby/
  • From: dmacvicar@xxxxxxxxxxxxxxxx
  • Date: Wed, 25 Jul 2007 16:47:13 -0000
  • Message-id: <20070725164713.E12FC172A0@xxxxxxxxxxxxxxxx>
Author: dmacvicar
Date: Wed Jul 25 18:47:13 2007
New Revision: 39682

URL: http://svn.opensuse.org/viewcvs/yast?rev=39682&view=rev
Log:
merge various fixes

Added:
    trunk/ruby-bindings/src/ruby/Y2RubyTypePath.cc
    trunk/ruby-bindings/src/ruby/Y2RubyTypePath.h
    trunk/ruby-bindings/src/ruby/Y2RubyTypeTerm.cc
    trunk/ruby-bindings/src/ruby/Y2RubyTypeTerm.h
Modified:
    trunk/ruby-bindings/README
    trunk/ruby-bindings/TODO
    trunk/ruby-bindings/src/ruby/CMakeLists.txt
    trunk/ruby-bindings/src/ruby/RubyLogger.cc
    trunk/ruby-bindings/src/ruby/RubyLogger.h
    trunk/ruby-bindings/src/ruby/Y2CCRuby.cc
    trunk/ruby-bindings/src/ruby/Y2CCRuby.h
    trunk/ruby-bindings/src/ruby/Y2RubyComponent.cc
    trunk/ruby-bindings/src/ruby/Y2RubyComponent.h
    trunk/ruby-bindings/src/ruby/Y2RubyTypeConv.cc
    trunk/ruby-bindings/src/ruby/Y2RubyTypeConv.h
    trunk/ruby-bindings/src/ruby/YCP.cc
    trunk/ruby-bindings/src/ruby/YRuby.cc
    trunk/ruby-bindings/src/ruby/YRuby.h
    trunk/ruby-bindings/src/ruby/YRubyNamespace.cc
    trunk/ruby-bindings/src/ruby/YRubyNamespace.h

Modified: trunk/ruby-bindings/README
URL: http://svn.opensuse.org/viewcvs/yast/trunk/ruby-bindings/README?rev=39682&r1=39681&r2=39682&view=diff
==============================================================================
--- trunk/ruby-bindings/README (original)
+++ trunk/ruby-bindings/README Wed Jul 25 18:47:13 2007
@@ -1,2 +1,17 @@
-- Some attempts to access YaST from another languages
-  <dmacvicar@xxxxxxx>
\ No newline at end of file
+/*---------------------------------------------------------------------\
+|                                                                      |
+|                      __   __    ____ _____ ____                      |
+|                      \ \ / /_ _/ ___|_   _|___ \                     |
+|                       \ V / _` \___ \ | |   __) |                    |
+|                        | | (_| |___) || |  / __/                     |
+|                        |_|\__,_|____/ |_| |_____|                    |
+|                                                                      |
+|                                                                      |
+| ruby language support                              (C) Novell Inc.   |
+\----------------------------------------------------------------------/
+
+Author: Duncan Mac-Vicar <dmacvicar@xxxxxxx>
+
+Based on yast2-perl-bindings by
+  Martin Vidner <mvidner@xxxxxxx>
+  Stefan Hundhammer <sh@xxxxxxx>

Modified: trunk/ruby-bindings/TODO
URL: http://svn.opensuse.org/viewcvs/yast/trunk/ruby-bindings/TODO?rev=39682&r1=39681&r2=39682&view=diff
==============================================================================
--- trunk/ruby-bindings/TODO (original)
+++ trunk/ruby-bindings/TODO Wed Jul 25 18:47:13 2007
@@ -3,3 +3,4 @@
 - UI support
 - Conversion of some types from ruby to YCP like hash and arrays
 - handling of abort signal from the interpreter.
+- implement y2log functions

Modified: trunk/ruby-bindings/src/ruby/CMakeLists.txt
URL: http://svn.opensuse.org/viewcvs/yast/trunk/ruby-bindings/src/ruby/CMakeLists.txt?rev=39682&r1=39681&r2=39682&view=diff
==============================================================================
--- trunk/ruby-bindings/src/ruby/CMakeLists.txt (original)
+++ trunk/ruby-bindings/src/ruby/CMakeLists.txt Wed Jul 25 18:47:13 2007
@@ -15,6 +15,8 @@
   YRuby.cc
   YRubyNamespace.cc
   Y2RubyTypeConv.cc
+  Y2RubyTypePath.cc
+  Y2RubyTypeTerm.cc
 )
   
 SET(ruby_yast_plugin_HEADERS
@@ -22,7 +24,10 @@
   Y2CCRuby.h
   Y2RubyComponent.h
   YRuby.h
-  YRubyNamespace.h )
+  YRubyNamespace.h
+  Y2RubyTypePath.h
+  Y2RubyTypeTerm.h
+)
   
 INCLUDE_DIRECTORIES( ${RUBY_INCLUDE_PATH} )
 INCLUDE_DIRECTORIES( ${YAST_INCLUDE_DIR} )

Modified: trunk/ruby-bindings/src/ruby/RubyLogger.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/ruby-bindings/src/ruby/RubyLogger.cc?rev=39682&r1=39681&r2=39682&view=diff
==============================================================================
--- trunk/ruby-bindings/src/ruby/RubyLogger.cc (original)
+++ trunk/ruby-bindings/src/ruby/RubyLogger.cc Wed Jul 25 18:47:13 2007
@@ -1,3 +1,24 @@
+/*---------------------------------------------------------------------\
+|                                                                      |
+|                      __   __    ____ _____ ____                      |
+|                      \ \ / /_ _/ ___|_   _|___ \                     |
+|                       \ V / _` \___ \ | |   __) |                    |
+|                        | | (_| |___) || |  / __/                     |
+|                        |_|\__,_|____/ |_| |_____|                    |
+|                                                                      |
+|                                                                      |
+| ruby language support                              (C) Novell Inc.   |
+\----------------------------------------------------------------------/
+
+Author: Duncan Mac-Vicar <dmacvicar@xxxxxxx>
+
+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.
+
+*/
+
 #include "RubyLogger.h"
 #include <ycp/ExecutionEnvironment.h>
 

Modified: trunk/ruby-bindings/src/ruby/RubyLogger.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/ruby-bindings/src/ruby/RubyLogger.h?rev=39682&r1=39681&r2=39682&view=diff
==============================================================================
--- trunk/ruby-bindings/src/ruby/RubyLogger.h (original)
+++ trunk/ruby-bindings/src/ruby/RubyLogger.h Wed Jul 25 18:47:13 2007
@@ -1,3 +1,24 @@
+/*---------------------------------------------------------------------\
+|                                                                      |
+|                      __   __    ____ _____ ____                      |
+|                      \ \ / /_ _/ ___|_   _|___ \                     |
+|                       \ V / _` \___ \ | |   __) |                    |
+|                        | | (_| |___) || |  / __/                     |
+|                        |_|\__,_|____/ |_| |_____|                    |
+|                                                                      |
+|                                                                      |
+| ruby language support                              (C) Novell Inc.   |
+\----------------------------------------------------------------------/
+
+Author: Duncan Mac-Vicar <dmacvicar@xxxxxxx>
+
+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 RubyLogger_h
 #define RubyLogger_h
 

Modified: trunk/ruby-bindings/src/ruby/Y2CCRuby.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/ruby-bindings/src/ruby/Y2CCRuby.cc?rev=39682&r1=39681&r2=39682&view=diff
==============================================================================
--- trunk/ruby-bindings/src/ruby/Y2CCRuby.cc (original)
+++ trunk/ruby-bindings/src/ruby/Y2CCRuby.cc Wed Jul 25 18:47:13 2007
@@ -1,3 +1,24 @@
+/*---------------------------------------------------------------------\
+|                                                                      |
+|                      __   __    ____ _____ ____                      |
+|                      \ \ / /_ _/ ___|_   _|___ \                     |
+|                       \ V / _` \___ \ | |   __) |                    |
+|                        | | (_| |___) || |  / __/                     |
+|                        |_|\__,_|____/ |_| |_____|                    |
+|                                                                      |
+|                                                                      |
+| ruby language support                              (C) Novell Inc.   |
+\----------------------------------------------------------------------/
+
+Author: Duncan Mac-Vicar <dmacvicar@xxxxxxx>
+
+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.
+
+*/
+
 #include "Y2CCRuby.h"
 #include <ycp/pathsearch.h>
 #define y2log_component "Y2Ruby"

Modified: trunk/ruby-bindings/src/ruby/Y2CCRuby.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/ruby-bindings/src/ruby/Y2CCRuby.h?rev=39682&r1=39681&r2=39682&view=diff
==============================================================================
--- trunk/ruby-bindings/src/ruby/Y2CCRuby.h (original)
+++ trunk/ruby-bindings/src/ruby/Y2CCRuby.h Wed Jul 25 18:47:13 2007
@@ -1,21 +1,23 @@
-/*-----------------------------------------------------------*- c++ -*-\
-|                                                                     |
-|                     __   __    ____ _____ ____                      |
-|                     \ \ / /_ _/ ___|_   _|___ \                     |
-|                      \ V / _` \___ \ | |   __) |                    |
-|                       | | (_| |___) || |  / __/                     |
-|                       |_|\__,_|____/ |_| |_____|                    |
-|                                                                     |
-|                              core system                            |
-|                                                   (C) SuSE Linux AG |
+/*---------------------------------------------------------------------\
+|                                                                      |
+|                      __   __    ____ _____ ____                      |
+|                      \ \ / /_ _/ ___|_   _|___ \                     |
+|                       \ V / _` \___ \ | |   __) |                    |
+|                        | | (_| |___) || |  / __/                     |
+|                        |_|\__,_|____/ |_| |_____|                    |
+|                                                                      |
+|                                                                      |
+| ruby language support                              (C) Novell Inc.   |
 \----------------------------------------------------------------------/
 
-  File:              Y2CCRuby.h
+Author: Duncan Mac-Vicar <dmacvicar@xxxxxxx>
 
-  Author:     Stefan Hundhammer <sh@xxxxxxx>
-
-/-*/
+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 _Y2CCRuby_h
 #define _Y2CCRuby_h

Modified: trunk/ruby-bindings/src/ruby/Y2RubyComponent.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/ruby-bindings/src/ruby/Y2RubyComponent.cc?rev=39682&r1=39681&r2=39682&view=diff
==============================================================================
--- trunk/ruby-bindings/src/ruby/Y2RubyComponent.cc (original)
+++ trunk/ruby-bindings/src/ruby/Y2RubyComponent.cc Wed Jul 25 18:47:13 2007
@@ -1,3 +1,24 @@
+/*---------------------------------------------------------------------\
+|                                                                      |
+|                      __   __    ____ _____ ____                      |
+|                      \ \ / /_ _/ ___|_   _|___ \                     |
+|                       \ V / _` \___ \ | |   __) |                    |
+|                        | | (_| |___) || |  / __/                     |
+|                        |_|\__,_|____/ |_| |_____|                    |
+|                                                                      |
+|                                                                      |
+| ruby language support                              (C) Novell Inc.   |
+\----------------------------------------------------------------------/
+
+Author: Duncan Mac-Vicar <dmacvicar@xxxxxxx>
+
+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.
+
+*/
+
 #define y2log_component "Y2Ruby"
 #include <ycp/y2log.h>
 #include <ycp/pathsearch.h>

Modified: trunk/ruby-bindings/src/ruby/Y2RubyComponent.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/ruby-bindings/src/ruby/Y2RubyComponent.h?rev=39682&r1=39681&r2=39682&view=diff
==============================================================================
--- trunk/ruby-bindings/src/ruby/Y2RubyComponent.h (original)
+++ trunk/ruby-bindings/src/ruby/Y2RubyComponent.h Wed Jul 25 18:47:13 2007
@@ -1,3 +1,24 @@
+/*---------------------------------------------------------------------\
+|                                                                      |
+|                      __   __    ____ _____ ____                      |
+|                      \ \ / /_ _/ ___|_   _|___ \                     |
+|                       \ V / _` \___ \ | |   __) |                    |
+|                        | | (_| |___) || |  / __/                     |
+|                        |_|\__,_|____/ |_| |_____|                    |
+|                                                                      |
+|                                                                      |
+| ruby language support                              (C) Novell Inc.   |
+\----------------------------------------------------------------------/
+
+Author: Duncan Mac-Vicar <dmacvicar@xxxxxxx>
+
+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 Y2RubyComponent_h
 #define Y2RubyComponent_h
 
@@ -23,7 +44,7 @@
     /**
      * The name of this component.
      */
-    string name() const { return "perl"; }
+    string name() const { return "ruby"; }
 
     /**
      * Is called by the generic frontend when the session is finished.

Modified: trunk/ruby-bindings/src/ruby/Y2RubyTypeConv.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/ruby-bindings/src/ruby/Y2RubyTypeConv.cc?rev=39682&r1=39681&r2=39682&view=diff
==============================================================================
--- trunk/ruby-bindings/src/ruby/Y2RubyTypeConv.cc (original)
+++ trunk/ruby-bindings/src/ruby/Y2RubyTypeConv.cc Wed Jul 25 18:47:13 2007
@@ -1,3 +1,23 @@
+/*---------------------------------------------------------------------\
+|                                                                      |
+|                      __   __    ____ _____ ____                      |
+|                      \ \ / /_ _/ ___|_   _|___ \                     |
+|                       \ V / _` \___ \ | |   __) |                    |
+|                        | | (_| |___) || |  / __/                     |
+|                        |_|\__,_|____/ |_| |_____|                    |
+|                                                                      |
+|                                                                      |
+| ruby language support                              (C) Novell Inc.   |
+\----------------------------------------------------------------------/
+
+Author: Duncan Mac-Vicar <dmacvicar@xxxxxxx>
+
+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.
+
+*/
 
 #include <ycp/y2log.h>
 
@@ -7,6 +27,7 @@
 #include <ycp/YCPMap.h>
 #include <ycp/YCPString.h>
 #include <ycp/YCPInteger.h>
+#include <ycp/YCPTerm.h>
 #include <ycp/YCPFloat.h>
 #include <ycp/YCPElement.h>
 #include <ycp/YCPSymbol.h>
@@ -14,8 +35,39 @@
 #include <ycp/YCPVoid.h>
 #include <ycp/Import.h>
 
+#include "Y2RubyTypePath.h"
+#include "Y2RubyTypeTerm.h"
+
 #include "Y2RubyTypeConv.h"
 
+static YCPMap rbhash_2_ycpmap( VALUE value )
+{
+  YCPMap map;
+  VALUE keys = rb_funcall(value, rb_intern("keys"), 0);
+  int n = NUM2LONG(rb_funcall(keys, rb_intern("size"), 0));
+  for ( int i=0; i<n; ++i)
+  {
+    VALUE rkey = rb_funcall(keys, rb_intern("at"), 1, i);
+    YCPValue ykey = rbvalue_2_ycpvalue(rkey);
+    YCPValue yvalue = rbvalue_2_ycpvalue( rb_funcall(value, rb_intern("[]"), 1, rkey) );
+    map.add(ykey, yvalue);
+  }
+  return map;
+}
+
+static YCPList rbarray_2_ycplist( VALUE value )
+{
+  YCPList list;
+  int n = NUM2LONG(rb_funcall(value, rb_intern("size"), 0));
+  for ( int i=0; i<n; ++i)
+  {
+    VALUE element = rb_funcall(value, rb_intern("[]"), 1, i);
+    list.add( rbvalue_2_ycpvalue(element) );
+  }
+  return list;
+}
+
+
 /**
  * Converts a YCPValue into a Ruby Value
  * Supports neested lists using recursion.
@@ -37,10 +89,23 @@
   {
     return rb_str_new2(ycpval->asString()->value().c_str());
   }
+  else if (ycpval->isPath())
+  {
+    // FIXME implement a ruby class for YCPPath
+    return rb_str_new2(ycpval->asPath()->asString()->value().c_str());
+  }
+  else if (ycpval->isTerm())
+  {
+    return ryast_term_from_term(ycpval->asTerm());
+  }
   else if (ycpval->isInteger())
   {
     return INT2NUM( ycpval->asInteger()->value() );
   }
+  else if (ycpval->isFloat())
+  {
+    return rb_float_new(ycpval->asFloat()->value());
+  }
   else if ( ycpval->isMap() )
   {
     VALUE rbhash;
@@ -103,18 +168,13 @@
     return YCPFloat(NUM2DBL(value));
     break;
   case T_ARRAY:
-    // FIXME
-    return YCPValue();
+    return rbarray_2_ycplist(value);
     break;
   case T_HASH:
-    // FIXME
-    return YCPValue();
+    return rbhash_2_ycpmap(value);
     break;
   case T_SYMBOL:
-    y2internal("mira un mono!!!");
-    //return YCPSymbol(RSTRING(rb_funcall(value, rb_intern("to_s"), 0))->ptr);
     return YCPSymbol(rb_id2name(rb_to_id(value)));
-    
   case T_DATA:
     rb_raise( rb_eRuntimeError, "Object");
     break;
@@ -130,4 +190,5 @@
 {
   VALUE stringrep = rb_funcall(value, rb_intern("to_s"), 0);
   return  YCPPath(RSTRING(stringrep)->ptr);
-}
\ No newline at end of file
+}
+

Modified: trunk/ruby-bindings/src/ruby/Y2RubyTypeConv.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/ruby-bindings/src/ruby/Y2RubyTypeConv.h?rev=39682&r1=39681&r2=39682&view=diff
==============================================================================
--- trunk/ruby-bindings/src/ruby/Y2RubyTypeConv.h (original)
+++ trunk/ruby-bindings/src/ruby/Y2RubyTypeConv.h Wed Jul 25 18:47:13 2007
@@ -1,3 +1,23 @@
+/*---------------------------------------------------------------------\
+|                                                                      |
+|                      __   __    ____ _____ ____                      |
+|                      \ \ / /_ _/ ___|_   _|___ \                     |
+|                       \ V / _` \___ \ | |   __) |                    |
+|                        | | (_| |___) || |  / __/                     |
+|                        |_|\__,_|____/ |_| |_____|                    |
+|                                                                      |
+|                                                                      |
+| ruby language support                              (C) Novell Inc.   |
+\----------------------------------------------------------------------/
+
+Author: Duncan Mac-Vicar <dmacvicar@xxxxxxx>
+
+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 Y2RUBYTYPECONV_H
 #define Y2RUBYTYPECONV_H
@@ -7,18 +27,22 @@
 
 /**
  * Converts a YCPValue into a Ruby Value
- * Supports neested lists using recursion.
+ * Supports neested lists and maps using recursion.
  */
 extern "C" VALUE
 ycpvalue_2_rbvalue( YCPValue ycpval );
 
 /**
  * Converts a Ruby Value into a YCPValue
- * Supports neested lists using recursion.
+ * Supports neested lists and maps using recursion.
  */
 YCPValue
 rbvalue_2_ycpvalue( VALUE value );
 
+
+/**
+ * excplicitly create a YCPPath from a Ruby value
+ */
 YCPValue
 rbvalue_2_ycppath( VALUE value );
 

Added: trunk/ruby-bindings/src/ruby/Y2RubyTypePath.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/ruby-bindings/src/ruby/Y2RubyTypePath.cc?rev=39682&view=auto
==============================================================================
--- trunk/ruby-bindings/src/ruby/Y2RubyTypePath.cc (added)
+++ trunk/ruby-bindings/src/ruby/Y2RubyTypePath.cc Wed Jul 25 18:47:13 2007
@@ -0,0 +1,75 @@
+#include "YRuby.h"
+#include "Y2RubyTypePath.h"
+#include <ycp/YCPPath.h>
+
+static VALUE ryast_cPath;
+
+struct ryast_Path_Wrapper
+{
+  YCPPath path;
+};
+
+//-----------------------------------------------------------------------------
+// internal used only
+
+static void
+ryast_path_set_path( VALUE self, const YCPPath & path )
+{
+  ryast_Path_Wrapper *wrapper;
+  Data_Get_Struct(self, ryast_Path_Wrapper, wrapper);
+  wrapper->path = path;
+}
+
+static void
+ryast_path_mark (ryast_Path_Wrapper *r)
+{
+
+}
+
+static void
+ryast_path_free (ryast_Path_Wrapper *r)
+{
+  delete r;
+}
+
+static VALUE
+ryast_path_initialize( int argc, VALUE *argv, VALUE self )
+{
+    ryast_Path_Wrapper *wrapper;
+    Data_Get_Struct(self, ryast_Path_Wrapper, wrapper);
+    
+    // we should be using rb_scan_args here but I couldn't get it to work.
+
+//     if (argc > 0) {
+//   Check_Type( argv[0], T_STRING);
+//   version = StringValuePtr( argv[0] );
+//     }
+//     if (argc > 1) {
+//   Check_Type( argv[1], T_STRING);
+//   release = StringValuePtr( argv[1] );
+//     }
+//     if (argc > 2) {
+//   Check_Type( argv[2], T_FIXNUM);
+//   epoch = FIX2INT( argv[2] );
+//     }
+    wrapper->path = YCPPath();
+    return self;
+}
+
+
+static VALUE
+ryast_path_allocate(VALUE klass)
+{
+  // create struct
+  ryast_Path_Wrapper *wrapper = new ryast_Path_Wrapper();
+  // wrap and return struct
+  return Data_Wrap_Struct (klass, ryast_path_mark, ryast_path_free, wrapper);
+}
+
+void
+ryast_path_init( VALUE super )
+{
+  ryast_cPath = rb_define_class_under( super, "Path", rb_cObject );
+  rb_define_alloc_func( ryast_cPath, ryast_path_allocate );
+  rb_define_method( ryast_cPath, "initialize", RB_METHOD( ryast_path_initialize ), -1 );
+}

Added: trunk/ruby-bindings/src/ruby/Y2RubyTypePath.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/ruby-bindings/src/ruby/Y2RubyTypePath.h?rev=39682&view=auto
==============================================================================
--- trunk/ruby-bindings/src/ruby/Y2RubyTypePath.h (added)
+++ trunk/ruby-bindings/src/ruby/Y2RubyTypePath.h Wed Jul 25 18:47:13 2007
@@ -0,0 +1,30 @@
+/*---------------------------------------------------------------------\
+|                                                                      |
+|                      __   __    ____ _____ ____                      |
+|                      \ \ / /_ _/ ___|_   _|___ \                     |
+|                       \ V / _` \___ \ | |   __) |                    |
+|                        | | (_| |___) || |  / __/                     |
+|                        |_|\__,_|____/ |_| |_____|                    |
+|                                                                      |
+|                                                                      |
+| ruby language support                              (C) Novell Inc.   |
+\----------------------------------------------------------------------/
+
+Author: Duncan Mac-Vicar <dmacvicar@xxxxxxx>
+
+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 Y2RUBY_TYPE_PATH_H
+#define Y2RUBY_TYPE_PATH_H
+
+#include <ruby.h>
+
+void ryast_path_init( VALUE super );
+
+#endif
+

Added: trunk/ruby-bindings/src/ruby/Y2RubyTypeTerm.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/ruby-bindings/src/ruby/Y2RubyTypeTerm.cc?rev=39682&view=auto
==============================================================================
--- trunk/ruby-bindings/src/ruby/Y2RubyTypeTerm.cc (added)
+++ trunk/ruby-bindings/src/ruby/Y2RubyTypeTerm.cc Wed Jul 25 18:47:13 2007
@@ -0,0 +1,109 @@
+/*---------------------------------------------------------------------\
+|                                                                      |
+|                      __   __    ____ _____ ____                      |
+|                      \ \ / /_ _/ ___|_   _|___ \                     |
+|                       \ V / _` \___ \ | |   __) |                    |
+|                        | | (_| |___) || |  / __/                     |
+|                        |_|\__,_|____/ |_| |_____|                    |
+|                                                                      |
+|                                                                      |
+| ruby language support                              (C) Novell Inc.   |
+\----------------------------------------------------------------------/
+
+Author: Duncan Mac-Vicar <dmacvicar@xxxxxxx>
+
+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.
+
+*/
+
+#include "YRuby.h"
+#include "Y2RubyTypeConv.h"
+#include "Y2RubyTypeTerm.h"
+#include <ycp/YCPTerm.h>
+
+static VALUE ryast_cTerm;
+
+struct ryast_Term_Wrapper
+{
+  ryast_Term_Wrapper()
+    : term("init-me")
+  {
+
+  }
+  YCPTerm term;
+};
+
+//-----------------------------------------------------------------------------
+// internal used only
+
+static void
+ryast_term_set_term( VALUE self, const YCPTerm & term )
+{
+  ryast_Term_Wrapper *wrapper;
+  Data_Get_Struct(self, ryast_Term_Wrapper, wrapper);
+  wrapper->term = term;
+}
+
+VALUE
+ryast_term_from_term( const YCPTerm &term )
+{
+  VALUE rterm_obj = rb_funcall( ryast_cTerm, rb_intern("new"), 0);
+  ryast_term_set_term( rterm_obj, term );
+  return rterm_obj;
+}
+
+static void
+ryast_term_mark (ryast_Term_Wrapper *r)
+{
+
+}
+
+static void
+ryast_term_free (ryast_Term_Wrapper *r)
+{
+  delete r;
+}
+
+static VALUE
+ryast_term_initialize( int argc, VALUE *argv, VALUE self )
+{
+    ryast_Term_Wrapper *wrapper;
+    Data_Get_Struct(self, ryast_Term_Wrapper, wrapper);
+    
+    // we should be using rb_scan_args here but I couldn't get it to work.
+
+    // we need at least the name to create a YCPTerm
+    Check_Type( argv[0], T_STRING);
+    wrapper->term = YCPTerm( RSTRING(argv[0])->ptr );
+    // add the remaining YCPTerm arguments
+    if (argc > 1)
+    {
+      int i=1;
+      for ( ; i<argc; ++i )
+      {
+        wrapper->term->add(rbvalue_2_ycpvalue(argv[i]));
+      }
+    }
+    return self;
+}
+
+
+static VALUE
+ryast_term_allocate(VALUE klass)
+{
+  // create struct
+  ryast_Term_Wrapper *wrapper = new ryast_Term_Wrapper();
+  // wrap and return struct
+  return Data_Wrap_Struct (klass, ryast_term_mark, ryast_term_free, wrapper);
+}
+
+void
+ryast_term_init( VALUE super )
+{
+  ryast_cTerm = rb_define_class_under( super, "Term", rb_cObject );
+  rb_define_alloc_func( ryast_cTerm, ryast_term_allocate );
+  rb_define_method( ryast_cTerm, "initialize", RB_METHOD( ryast_term_initialize ), -1 );
+}

Added: trunk/ruby-bindings/src/ruby/Y2RubyTypeTerm.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/ruby-bindings/src/ruby/Y2RubyTypeTerm.h?rev=39682&view=auto
==============================================================================
--- trunk/ruby-bindings/src/ruby/Y2RubyTypeTerm.h (added)
+++ trunk/ruby-bindings/src/ruby/Y2RubyTypeTerm.h Wed Jul 25 18:47:13 2007
@@ -0,0 +1,33 @@
+/*---------------------------------------------------------------------\
+|                                                                      |
+|                      __   __    ____ _____ ____                      |
+|                      \ \ / /_ _/ ___|_   _|___ \                     |
+|                       \ V / _` \___ \ | |   __) |                    |
+|                        | | (_| |___) || |  / __/                     |
+|                        |_|\__,_|____/ |_| |_____|                    |
+|                                                                      |
+|                                                                      |
+| ruby language support                              (C) Novell Inc.   |
+\----------------------------------------------------------------------/
+
+Author: Duncan Mac-Vicar <dmacvicar@xxxxxxx>
+
+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 Y2RUBY_TYPE_TERM_H
+#define Y2RUBY_TYPE_TERM_H
+
+#include <ruby.h>
+
+void ryast_term_init( VALUE super );
+
+VALUE
+ryast_term_from_term( const YCPTerm &term );
+
+#endif
+

Modified: trunk/ruby-bindings/src/ruby/YCP.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/ruby-bindings/src/ruby/YCP.cc?rev=39682&r1=39681&r2=39682&view=diff
==============================================================================
--- trunk/ruby-bindings/src/ruby/YCP.cc (original)
+++ trunk/ruby-bindings/src/ruby/YCP.cc Wed Jul 25 18:47:13 2007
@@ -1,3 +1,24 @@
+/*---------------------------------------------------------------------\
+|                                                                      |
+|                      __   __    ____ _____ ____                      |
+|                      \ \ / /_ _/ ___|_   _|___ \                     |
+|                       \ V / _` \___ \ | |   __) |                    |
+|                        | | (_| |___) || |  / __/                     |
+|                        |_|\__,_|____/ |_| |_____|                    |
+|                                                                      |
+|                                                                      |
+| ruby language support                              (C) Novell Inc.   |
+\----------------------------------------------------------------------/
+
+Author: Duncan Mac-Vicar <dmacvicar@xxxxxxx>
+
+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.
+
+*/
+
 // #include <y2/Y2Namespace.h>
 // #include <y2/Y2Component.h>
 #include <y2/Y2ComponentCreator.h>
@@ -24,12 +45,16 @@
 #include <ycp/YCPFloat.h>
 #include <ycp/YCPElement.h>
 #include <ycp/Import.h>
+#include <ycp/y2log.h>
 
 #include "ruby.h"
 
 //#include "YRuby.h"
 #include "RubyLogger.h"
+#include "Y2RubyTypePath.h"
+#include "Y2RubyTypeTerm.h"
 #include "Y2RubyTypeConv.h"
+#include "YRuby.h"
 
 static VALUE rb_mYaST;
 static VALUE rb_cBroker;
@@ -276,7 +301,7 @@
   // maybe a special exceptional hack to make Path for the 1st argument?
 
   // go through the actual parameters
-  unsigned j;
+  int j;
   for (j = 1; j < argc; ++j)
   {
     y2milestone("builtin param '%d'", j-1);
@@ -343,7 +368,7 @@
   delete bi_call;
 
   return ret_yv;
-} 
+}
 
 extern "C"
 {
@@ -362,12 +387,14 @@
 
     rb_mYaST = rb_define_module("YaST");
 
-    // CIMClient
     rb_cBroker = rb_define_class_under( rb_mYaST, "Module", rb_cObject);
     //rb_define_singleton_method( rb_cBroker, "new", RB_METHOD(module_new), 1);
     rb_define_alloc_func(rb_cBroker, yast_module_allocate);
     rb_define_method(rb_cBroker, "initialize", RB_METHOD(yast_module_initialize), 1);
     rb_define_method( rb_cBroker, "method_missing", RB_METHOD(yast_module_proxy_method), -1);
     rb_define_method( rb_cBroker, "name", RB_METHOD(yast_module_name), -1);
+
+    ryast_path_init(rb_mYaST);
+    ryast_term_init(rb_mYaST);
   }
 }

Modified: trunk/ruby-bindings/src/ruby/YRuby.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/ruby-bindings/src/ruby/YRuby.cc?rev=39682&r1=39681&r2=39682&view=diff
==============================================================================
--- trunk/ruby-bindings/src/ruby/YRuby.cc (original)
+++ trunk/ruby-bindings/src/ruby/YRuby.cc Wed Jul 25 18:47:13 2007
@@ -1,3 +1,24 @@
+/*---------------------------------------------------------------------\
+|                                                                      |
+|                      __   __    ____ _____ ____                      |
+|                      \ \ / /_ _/ ___|_   _|___ \                     |
+|                       \ V / _` \___ \ | |   __) |                    |
+|                        | | (_| |___) || |  / __/                     |
+|                        |_|\__,_|____/ |_| |_____|                    |
+|                                                                      |
+|                                                                      |
+| ruby language support                              (C) Novell Inc.   |
+\----------------------------------------------------------------------/
+
+Author: Duncan Mac-Vicar <dmacvicar@xxxxxxx>
+
+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.
+
+*/
+
 #include <stdlib.h>
 #include <list>
 #include <iosfwd>
@@ -31,8 +52,6 @@
 
 #define DIM(ARRAY)     ( sizeof( ARRAY )/sizeof( ARRAY[0] ) )
 
-#define YCP_EXTERNAL_MAGIC "Reference to perl object (v1.0)"
-
 #include "Y2RubyTypeConv.h"
 
 static void prependModulePath()
@@ -45,11 +64,11 @@
       i;
       
   // count the number of directories to prepend
-  int n = 0;
-  for (i = b; i != e; ++i)
-  {
-    // do something
-  }
+//   int n = 0;
+//   for (i = b; i != e; ++i)
+//   {
+//     // do something
+//   }
 }
 
 YRuby * YRuby::_yRuby = 0;
@@ -108,7 +127,7 @@
   string require_module = "require(\"" + module_path + "\")";
   //y2milestone("loadModule 3.5");
   VALUE result = rb_eval_string((require_module).c_str());
-  if ( result = Qfalse )
+  if ( result == Qfalse )
     return YCPError( "Ruby::loadModule() / Can't load ruby module '" + module_path + "'" );
   //y2milestone("loadModule 4");
   return YCPVoid();

Modified: trunk/ruby-bindings/src/ruby/YRuby.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/ruby-bindings/src/ruby/YRuby.h?rev=39682&r1=39681&r2=39682&view=diff
==============================================================================
--- trunk/ruby-bindings/src/ruby/YRuby.h (original)
+++ trunk/ruby-bindings/src/ruby/YRuby.h Wed Jul 25 18:47:13 2007
@@ -1,3 +1,24 @@
+/*---------------------------------------------------------------------\
+|                                                                      |
+|                      __   __    ____ _____ ____                      |
+|                      \ \ / /_ _/ ___|_   _|___ \                     |
+|                       \ V / _` \___ \ | |   __) |                    |
+|                        | | (_| |___) || |  / __/                     |
+|                        |_|\__,_|____/ |_| |_____|                    |
+|                                                                      |
+|                                                                      |
+| ruby language support                              (C) Novell Inc.   |
+\----------------------------------------------------------------------/
+
+Author: Duncan Mac-Vicar <dmacvicar@xxxxxxx>
+
+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 YRuby_h
 #define YRuby_h
 
@@ -7,6 +28,18 @@
 #include <ycp/YCPList.h>
 #include <ycp/Type.h>
 
+// make the compiler happy when
+// calling rb_define_method()
+typedef VALUE (ruby_method)(...);
+
+// more useful macros
+#define RB_FINALIZER(func) ((void (*)(...))func)
+
+// this macro saves us from typing
+// (ruby_method*) & method_name
+// in rb_define_method
+#define RB_METHOD(func) ((VALUE (*)(...))func)
+
 class YRuby
 {
 public:

Modified: trunk/ruby-bindings/src/ruby/YRubyNamespace.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/ruby-bindings/src/ruby/YRubyNamespace.cc?rev=39682&r1=39681&r2=39682&view=diff
==============================================================================
--- trunk/ruby-bindings/src/ruby/YRubyNamespace.cc (original)
+++ trunk/ruby-bindings/src/ruby/YRubyNamespace.cc Wed Jul 25 18:47:13 2007
@@ -1,3 +1,24 @@
+/*---------------------------------------------------------------------\
+|                                                                      |
+|                      __   __    ____ _____ ____                      |
+|                      \ \ / /_ _/ ___|_   _|___ \                     |
+|                       \ V / _` \___ \ | |   __) |                    |
+|                        | | (_| |___) || |  / __/                     |
+|                        |_|\__,_|____/ |_| |_____|                    |
+|                                                                      |
+|                                                                      |
+| ruby language support                              (C) Novell Inc.   |
+\----------------------------------------------------------------------/
+
+Author: Duncan Mac-Vicar <dmacvicar@xxxxxxx>
+
+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.
+
+*/
+
 #include "YRubyNamespace.h"
 
 // Ruby stuff
@@ -51,7 +72,7 @@
     m_call->add (YCPVoid ());
   }
 
-  //! if true, the perl function is passed the module name
+  //! if true, the ruby function is passed the module name
   virtual bool isMethod () = 0;
 
   //! called by YEFunction::evaluate

Modified: trunk/ruby-bindings/src/ruby/YRubyNamespace.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/ruby-bindings/src/ruby/YRubyNamespace.h?rev=39682&r1=39681&r2=39682&view=diff
==============================================================================
--- trunk/ruby-bindings/src/ruby/YRubyNamespace.h (original)
+++ trunk/ruby-bindings/src/ruby/YRubyNamespace.h Wed Jul 25 18:47:13 2007
@@ -1,6 +1,23 @@
+/*---------------------------------------------------------------------\
+|                                                                      |
+|                      __   __    ____ _____ ____                      |
+|                      \ \ / /_ _/ ___|_   _|___ \                     |
+|                       \ V / _` \___ \ | |   __) |                    |
+|                        | | (_| |___) || |  / __/                     |
+|                        |_|\__,_|____/ |_| |_____|                    |
+|                                                                      |
+|                                                                      |
+| ruby language support                              (C) Novell Inc.   |
+\----------------------------------------------------------------------/
+
+Author: Duncan Mac-Vicar <dmacvicar@xxxxxxx>
+
+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.
 
-
-
+*/
 
 #include <ruby.h>
 #include <y2/Y2Namespace.h>

--
To unsubscribe, e-mail: yast-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages