Author: dmacvicar
Date: Wed Jun 27 16:36:42 2007
New Revision: 39057
URL: http://svn.opensuse.org/viewcvs/yast?rev=39057&view=rev
Log:
fixes, scr half working
fix load path
Added:
branches/tmp/dmacvicar/ruby-yast/examples/ruby/Bar.rb
branches/tmp/dmacvicar/ruby-yast/examples/ruby/Foo.rb
branches/tmp/dmacvicar/ruby-yast/examples/ruby/scr.rb
branches/tmp/dmacvicar/ruby-yast/examples/ruby/scr.ycp
Removed:
branches/tmp/dmacvicar/ruby-yast/examples/ruby/Duncan.rb
Modified:
branches/tmp/dmacvicar/ruby-yast/CMakeLists.txt
branches/tmp/dmacvicar/ruby-yast/cmake/modules/FindYast.cmake
branches/tmp/dmacvicar/ruby-yast/examples/ruby/ruby_from_ycp_2.ycp
branches/tmp/dmacvicar/ruby-yast/src/ruby/CMakeLists.txt
branches/tmp/dmacvicar/ruby-yast/src/ruby/Y2RubyTypeConv.cc
branches/tmp/dmacvicar/ruby-yast/src/ruby/YCP.cc
branches/tmp/dmacvicar/ruby-yast/src/ruby/YRuby.cc
Modified: branches/tmp/dmacvicar/ruby-yast/CMakeLists.txt
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/dmacvicar/ruby-yast/CMakeLists.txt?rev=39057&r1=39056&r2=39057&view=diff
==============================================================================
--- branches/tmp/dmacvicar/ruby-yast/CMakeLists.txt (original)
+++ branches/tmp/dmacvicar/ruby-yast/CMakeLists.txt Wed Jun 27 16:36:42 2007
@@ -1,5 +1,8 @@
PROJECT(yast2-bindings)
+SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O3 -Wall -Woverloaded-virtual" )
+SET( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O3 -Wall" )
+
# Library
IF ( DEFINED LIB )
SET ( LIB_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${LIB}" )
Modified: branches/tmp/dmacvicar/ruby-yast/cmake/modules/FindYast.cmake
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/dmacvicar/ruby-yast/cmake/modules/FindYast.cmake?rev=39057&r1=39056&r2=39057&view=diff
==============================================================================
--- branches/tmp/dmacvicar/ruby-yast/cmake/modules/FindYast.cmake (original)
+++ branches/tmp/dmacvicar/ruby-yast/cmake/modules/FindYast.cmake Wed Jun 27 16:36:42 2007
@@ -30,7 +30,14 @@
FIND_LIBRARY(YAST_PLUGIN_WFM_LIBRARY NAMES py2wfm
PATHS
- /usr/lib/YaST2/plugin
+ ${YAST_PLUGIN_DIR}
+ /usr/lib
+ /usr/local/lib
+)
+
+FIND_LIBRARY(YAST_PLUGIN_SCR_LIBRARY NAMES py2scr
+ PATHS
+ ${YAST_PLUGIN_DIR}
/usr/lib
/usr/local/lib
)
Added: branches/tmp/dmacvicar/ruby-yast/examples/ruby/Bar.rb
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/dmacvicar/ruby-yast/examples/ruby/Bar.rb?rev=39057&view=auto
==============================================================================
--- branches/tmp/dmacvicar/ruby-yast/examples/ruby/Bar.rb (added)
+++ branches/tmp/dmacvicar/ruby-yast/examples/ruby/Bar.rb Wed Jun 27 16:36:42 2007
@@ -0,0 +1,8 @@
+require 'yast'
+
+module Bar
+ def self.try
+ m = YaST::Module.new("SCR")
+ return m.Read(".proc.modules")
+ end
+end
Added: branches/tmp/dmacvicar/ruby-yast/examples/ruby/Foo.rb
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/dmacvicar/ruby-yast/examples/ruby/Foo.rb?rev=39057&view=auto
==============================================================================
(empty)
Modified: branches/tmp/dmacvicar/ruby-yast/examples/ruby/ruby_from_ycp_2.ycp
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/dmacvicar/ruby-yast/examples/ruby/ruby_from_ycp_2.ycp?rev=39057&r1=39056&r2=39057&view=diff
==============================================================================
--- branches/tmp/dmacvicar/ruby-yast/examples/ruby/ruby_from_ycp_2.ycp (original)
+++ branches/tmp/dmacvicar/ruby-yast/examples/ruby/ruby_from_ycp_2.ycp Wed Jun 27 16:36:42 2007
@@ -1,8 +1,8 @@
{
- import "Duncan";
- //integer result = (integer) Duncan::multiply_by_eight(6);
- integer result2 = (integer) Duncan::sum(2,3);
+ import "Foo";
+ //integer result = (integer) Foo::multiply_by_eight(6);
+ integer result2 = (integer) Foo::sum(2,3);
UI::OpenDialog(
`VBox(
`Label(sformat("%1", result2)),
Added: branches/tmp/dmacvicar/ruby-yast/examples/ruby/scr.rb
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/dmacvicar/ruby-yast/examples/ruby/scr.rb?rev=39057&view=auto
==============================================================================
--- branches/tmp/dmacvicar/ruby-yast/examples/ruby/scr.rb (added)
+++ branches/tmp/dmacvicar/ruby-yast/examples/ruby/scr.rb Wed Jun 27 16:36:42 2007
@@ -0,0 +1,5 @@
+require 'yast'
+
+m = YaST::Module.new("SCR")
+puts m.bar
+exit
\ No newline at end of file
Added: branches/tmp/dmacvicar/ruby-yast/examples/ruby/scr.ycp
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/dmacvicar/ruby-yast/examples/ruby/scr.ycp?rev=39057&view=auto
==============================================================================
--- branches/tmp/dmacvicar/ruby-yast/examples/ruby/scr.ycp (added)
+++ branches/tmp/dmacvicar/ruby-yast/examples/ruby/scr.ycp Wed Jun 27 16:36:42 2007
@@ -0,0 +1,13 @@
+
+{
+ import "Bar";
+ string result = (string) Bar::try();
+ UI::OpenDialog(
+ `VBox(
+ `Label(result),
+ `PushButton("OK")
+ )
+ );
+ UI::UserInput();
+ UI::CloseDialog();
+}
\ No newline at end of file
Modified: branches/tmp/dmacvicar/ruby-yast/src/ruby/CMakeLists.txt
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/dmacvicar/ruby-yast/src/ruby/CMakeLists.txt?rev=39057&r1=39056&r2=39057&view=diff
==============================================================================
--- branches/tmp/dmacvicar/ruby-yast/src/ruby/CMakeLists.txt (original)
+++ branches/tmp/dmacvicar/ruby-yast/src/ruby/CMakeLists.txt Wed Jun 27 16:36:42 2007
@@ -32,6 +32,7 @@
TARGET_LINK_LIBRARIES( yast ${YAST_LIBRARY} )
TARGET_LINK_LIBRARIES( yast ${YAST_YCP_LIBRARY} )
TARGET_LINK_LIBRARIES( yast ${YAST_PLUGIN_WFM_LIBRARY} )
+TARGET_LINK_LIBRARIES( yast ${YAST_PLUGIN_SCR_LIBRARY} )
TARGET_LINK_LIBRARIES( yast ${RUBY_LIBRARY} )
INSTALL(TARGETS yast LIBRARY DESTINATION ${RUBY_ARCH_DIR} )
Modified: branches/tmp/dmacvicar/ruby-yast/src/ruby/Y2RubyTypeConv.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/dmacvicar/ruby-yast/src/ruby/Y2RubyTypeConv.cc?rev=39057&r1=39056&r2=39057&view=diff
==============================================================================
--- branches/tmp/dmacvicar/ruby-yast/src/ruby/Y2RubyTypeConv.cc (original)
+++ branches/tmp/dmacvicar/ruby-yast/src/ruby/Y2RubyTypeConv.cc Wed Jun 27 16:36:42 2007
@@ -43,7 +43,7 @@
VALUE rbhash;
rbhash = rb_hash_new();
YCPMap map = ycpval->asMap();
- y2internal("map size %d\n", map.size());
+ y2internal("map size %d\n", (int) map.size());
for ( YCPMapIterator it = map.begin(); it != map.end(); ++it )
{
@@ -93,13 +93,16 @@
break;
case T_ARRAY:
// FIXME
+ return YCPValue();
break;
case T_HASH:
// FIXME
+ return YCPValue();
break;
case T_DATA:
rb_raise( rb_eRuntimeError, "Object");
break;
+ default:
std::cout << TYPE(value) << std::endl;
rb_raise( rb_eRuntimeError, "Conversion of Ruby type not supported");
return YCPValue();
Modified: branches/tmp/dmacvicar/ruby-yast/src/ruby/YCP.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/dmacvicar/ruby-yast/src/ruby/YCP.cc?rev=39057&r1=39056&r2=39057&view=diff
==============================================================================
--- branches/tmp/dmacvicar/ruby-yast/src/ruby/YCP.cc (original)
+++ branches/tmp/dmacvicar/ruby-yast/src/ruby/YCP.cc Wed Jun 27 16:36:42 2007
@@ -66,6 +66,20 @@
return ns;
}
+void init_wfm ()
+{
+ y2milestone("init_wfm");
+// if (Y2WFMComponent::instance () == 0)
+// {
+ y2milestone("WFM init");
+ owned_wfmc = Y2ComponentBroker::createClient ("wfm");
+ if (owned_wfmc == 0)
+ {
+ y2error ("Cannot create WFM component");
+ }
+// }
+}
+
typedef struct brokerinfo
{
Y2Component *component;
@@ -100,31 +114,57 @@
{
Check_Type(param_ns_name, T_STRING);
rb_iv_set(self, "@namespace_name", param_ns_name);
+ init_wfm ();
return self;
}
+
+VALUE
+yast_module_name( VALUE self )
+{
+ return rb_iv_get(self, "@namespace_name");
+}
+
VALUE
yast_module_methods( VALUE self )
{
return Qnil;
}
+//forward declaration
+YCPValue ycp_call_builtin ( const string &module_name, const string &func_name, int argc, VALUE *argv );
+
VALUE
yast_module_proxy_method( int argc, VALUE *argv, VALUE self )
{
VALUE symbol = argv[0];
+ VALUE namespace_name = rb_iv_get(self, "@namespace_name");
+
// the func name (1st argument, is a symbol
// lets convert it to string
VALUE symbol_str = rb_funcall(symbol, rb_intern("to_s"), 0);
- y2internal("Function: [%s] params: [%d]\n", RSTRING(symbol_str)->ptr, argc);
+ y2internal("Function: [%s::%s] params: [%d]\n", RSTRING(namespace_name)->ptr, RSTRING(symbol_str)->ptr, argc);
//Check_Type(argv[0], T_STRING);
//y2internal(RSTRING (symbol)->ptr);
//Data_Get_Struct( self, class Y2Namespace, ns );
//ns = gNameSpaces[self];
+ // get the name of the module
+ //VALUE namespace_name = rb_funcall(self, rb_intern("name"), 0);
+
+
+ // SCR
+ // this is a hack before the builtin namespaces get a uniform interface:
+ if (! strcmp (RSTRING (namespace_name)->ptr, "SCR"))
+ {
+ YCPValue res;
+ res = ycp_call_builtin( RSTRING(namespace_name)->ptr, RSTRING(symbol_str)->ptr, argc, argv);
+ //return ycpvalue_2_rbvalue(res);
+ return Qnil;
+ }
+
Y2Component *c;
- VALUE namespace_name = rb_iv_get(self, "@namespace_name");
c = Y2ComponentBroker::getNamespaceComponent(RSTRING (namespace_name)->ptr);
if (c == NULL)
{
@@ -194,6 +234,105 @@
return Qnil;
}
+YCPValue ycp_call_builtin ( const string &module_name, const string &func_name, int argc, VALUE *argv )
+{
+ // access directly the statically declared builtins
+ extern StaticDeclaration static_declarations;
+ string qualified_name_s = module_name + "::" + func_name;
+ const char *qualified_name = qualified_name_s.c_str ();
+
+ /*
+ this does not work across namespaces
+ TableEntry *bi_te = static_declarations.symbolTable ()->find (qualified_name);
+ if (bi_te == NULL)
+ {
+ y2error ("No such builtin %s",qualified_name);
+ return YCPNull ();
+ }
+
+ SymbolEntry *bi_se = bi_te->sentry ();
+ assert (bi_se != NULL);
+ assert (bi_se->isBuiltin ());
+ declaration_t bi_dt = bi_se->declaration ();
+ */
+ declaration_t *bi_dt = static_declarations.findDeclaration (qualified_name);
+ if (bi_dt == NULL)
+ {
+ y2error ("No such builtin '%s'", qualified_name);
+ return YCPNull ();
+ }
+
+ // construct a builtin call using the proper overloaded builtin
+ YEBuiltin *bi_call = new YEBuiltin (bi_dt);
+
+ // attach the parameters:
+
+ // we would like to know the destination type so that we could
+ // convert eg a Ruby scalar to a YCP symbol, but because the
+ // builtins may be overloaded, let's say we want Any
+
+ // maybe a special exceptional hack to make Path for the 1st argument?
+
+ // go through the actual parameters
+ unsigned j;
+ for (j = 0; j < argc; ++j)
+ {
+ // convert the value according to the expected type:
+ constTypePtr param_tp = (j == 0)? Type::Path : Type::Any;
+
+ YCPValue param_v = rbvalue_2_ycpvalue(argv[j] /*, param_tp */);
+ if (param_v.isNull ())
+ {
+ // an error has already been reported, now refine it.
+ // Can't know parameter name?
+ y2error ("... when passing parameter #%u to builtin %s",
+ j, qualified_name);
+ return YCPNull ();
+ }
+ // Such YConsts without a specific type produce invalid
+ // bytecode. (Which is OK here)
+ // The actual parameter's YCode becomes owned by the function call?
+ YConst *param_c = new YConst (YCode::ycConstant, param_v);
+ // for attaching the parameter, must get the real type so that it matches
+ constTypePtr act_param_tp = Type::vt2type (param_v->valuetype ());
+ // Attach the parameter
+ // Returns NULL if OK, Type::Error if excessive argument
+ // Other errors (bad code, bad type) shouldn't happen
+ constTypePtr err_tp = bi_call->attachParameter (param_c, act_param_tp);
+ if (err_tp != NULL)
+ {
+ if (err_tp->isError ())
+ {
+ // TODO really need to know the place in Ruby code
+ // where we were called from.
+ y2error ("Excessive parameter to builtin %s", qualified_name);
+ }
+ else
+ {
+ y2internal ("attachParameter returned %s", err_tp->toString ().c_str ());
+ }
+ return YCPNull ();
+ }
+ } // for each actual parameter
+
+ // now must check if we got fewer parameters than needed
+ // or there was another error while resolving the overload
+ constTypePtr err_tp = bi_call->finalize (RubyLogger::instance ());
+ if (err_tp != NULL)
+ {
+ // apparently the error was already reported?
+ y2error ("Error type %s when finalizing builtin %s",
+ err_tp->toString ().c_str (), qualified_name);
+ return YCPNull ();
+ }
+
+ // go call it now!
+ y2debug ("Ruby is calling builtin %s", qualified_name);
+ YCPValue ret_yv = bi_call->evaluate (false /* no const subexpr elim */);
+ delete bi_call;
+
+ return ret_yv;
+}
extern "C"
{
@@ -202,7 +341,6 @@
{
YCPPathSearch::initialize ();
-
for ( list<string>::const_iterator it = YCPPathSearch::searchListBegin (YCPPathSearch::Module); it != YCPPathSearch::searchListEnd (YCPPathSearch::Module) ; ++it )
{
y2internal("%s\n", (*it).c_str() );
@@ -219,461 +357,6 @@
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);
}
}
-
-
-// forward declaration
-//YCPValue YCP_call_SCR (pTHX_ const char * func_name, const vector