Skip to content

Commit

Permalink
allow passing ruby lazy code to YCP
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Mar 11, 2013
1 parent 31f09d5 commit 26aa460
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/binary/Y2RubyTypeConv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ as published by the Free Software Foundation; either version
#include <ycp/YCPVoid.h>
#include <ycp/YCPExternal.h>
#include <ycp/Import.h>
#include <ycp/YCode.h>

#include <cassert>

Expand Down Expand Up @@ -67,6 +68,37 @@ static YCPMap rbhash_2_ycpmap( VALUE value )
return map;
}

class YCPRubyProc : public YCode
{
private:
VALUE proc;
public:
YCPRubyProc(VALUE val):proc(val)
{}

virtual YCode::ykind kind() const
{ return YCode::yeExpression; }

//not needed
virtual std::ostream & toStream (std::ostream & str) const
{ return str; }

//not needed
virtual std::ostream & toXml (std::ostream & str, int indent ) const
{ return str; }

//only interesting stuff
virtual YCPValue evaluate (bool cse = false)
{
return rbvalue_2_ycpvalue(rb_proc_call(proc,rb_ary_new2(0)));
}
};

static YCPValue rbproc_2_ycpcode( VALUE value )
{
YCPCode c(new YCPRubyProc(value));
return c;
}

/*
* rbarray_2_ycplist
Expand Down Expand Up @@ -217,6 +249,10 @@ rbvalue_2_ycpvalue( VALUE value )
{
return rbreference_2_ycpreference(value);
}
else if ( !strcmp(class_name, "Proc"))
{
return rbproc_2_ycpcode(value);
}
else
{
rb_raise(rb_eRuntimeError, "Invalid value %s passed to component system", RSTRING_PTR(rb_inspect(value)));
Expand Down

0 comments on commit 26aa460

Please sign in to comment.