ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TRuby.cxx
Go to the documentation of this file.
1 // @(#)root/ruby:$Id$
2 // Author: Elias Athanasopoulos, May 2004
3 //
4 // Interface for the Ruby shell.
5 //
6 // (c) 2004 - Elias Athanasopoulos <elathan@phys.uoa.gr>
7 //
8 //
9 
10 #include "TRuby.h"
11 
12 #include "TROOT.h"
13 #include "TSystem.h"
14 
15 #include "ruby.h"
16 
18 
19 extern VALUE cTObject;
20 
22 {
23  static int IsInitialized = 0;
24 
25  if (!IsInitialized)
26  {
27  ruby_init();
28  IsInitialized = 1;
29  }
30 
31  return true;
32 }
33 
34 void TRuby::Exec(const char *cmd)
35 {
36  int state = 0;
37 
39  rb_eval_string_protect(cmd, &state);
40 
41  /* Print error if needed. */
42  if (state) rb_eval_string("puts $!");
43 }
44 
45 TObject *TRuby::Eval(const char* expr)
46 {
47  TObject *res;
48  int state = 0;
49 
51  VALUE ret = rb_eval_string_protect(expr, &state);
52 
53  /* Print error if needed. */
54  if (state)
55  {
56  rb_eval_string("puts $!");
57  return (TObject*)(0);
58  }
59 
60  if (NIL_P(ret)) return (TObject*)0;
61 
62  /* Return the instance pointer if it is a ROOT
63  * object.
64  */
65  VALUE ptr = rb_iv_get(ret, "__rr__");
66  if (!NIL_P(ptr))
67  {
68  Data_Get_Struct(rb_iv_get(ret, "__rr__"), TObject, res);
69  return res;
70  }
71 
72  return (TObject*)0;
73 }
74 
75 Bool_t TRuby::Bind(TObject *obj, const char *label)
76 {
77  VALUE *v = ALLOC(VALUE);
78 
79  *v = rb_class_new_instance (0, 0, cTObject);
80 
81  rb_iv_set(*v, "__rr__", Data_Wrap_Struct (cTObject, 0, 0, obj));
82  rb_define_variable(label, v);
83 
84  return true;
85 }
86 
88 {
89  gSystem->Exec("irb");
90 }
bool Bool_t
Definition: RtypesCore.h:59
static void Exec(const char *cmd)
Definition: TRuby.cxx:34
ClassImp(TRuby) extern VALUE cTObject
void Initialize(Bool_t useTMVAStyle=kTRUE)
Definition: tmvaglob.cxx:176
R__EXTERN TSystem * gSystem
Definition: TSystem.h:545
SVector< double, 2 > v
Definition: Dict.h:5
virtual Int_t Exec(const char *shellcmd)
Execute a command.
Definition: TSystem.cxx:657
static TObject * Eval(const char *expr)
Definition: TRuby.cxx:45
Mother of all ROOT objects.
Definition: TObject.h:58
static void Prompt()
Definition: TRuby.cxx:87
VALUE cTObject
Definition: drr.cxx:54
Definition: TRuby.h:11
static Bool_t Bind(TObject *obj, const char *label)
Definition: TRuby.cxx:75
static Bool_t Initialize()
Definition: TRuby.cxx:21
TObject * obj