#include "TRuby.h"
#include "TROOT.h"
#include "TSystem.h"
#include "ruby.h"
ClassImp(TRuby)
extern VALUE cTObject;
bool TRuby::Initialize()
{
    static int IsInitialized = 0;
    if (!IsInitialized)
      {
        ruby_init();
        IsInitialized = 1;
      }
    return true;
}
void TRuby::Exec(const char *cmd)
{
    int state = 0;
    TRuby::Initialize();
    rb_eval_string_protect(cmd, &state);
    
    if (state) rb_eval_string("puts $!");
}
TObject *TRuby::Eval(const char* expr)
{
    TObject *res;
    int state = 0;
    TRuby::Initialize();
    VALUE ret = rb_eval_string_protect(expr, &state);
    
    if (state)
      {
        rb_eval_string("puts $!");
        return (TObject*)(0);
      }
    if (NIL_P(ret)) return (TObject*)0;
    
    VALUE ptr = rb_iv_get(ret, "__rr__");
    if (!NIL_P(ptr))
      {
        Data_Get_Struct(rb_iv_get(ret, "__rr__"), TObject, res);
        return res;
      }
    return (TObject*)0;
}
bool TRuby::Bind(TObject *obj, const char *label)
{
    VALUE *v = ALLOC(VALUE);
    *v = rb_class_new_instance (0, 0, cTObject);
    rb_iv_set(*v, "__rr__", Data_Wrap_Struct (cTObject, 0, 0, obj));
    rb_define_variable(label, v);
    return true;
}
void TRuby::Prompt()
{
    gSystem->Exec("irb");
}
Last update: Thu Jan 17 09:02:59 2008
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.