/* Evaluate a function given by a name (without arguments) */ SEXP do_eval_fun(char *name) { SEXP exp, fun, res; fun = get_fun_from_name(name); if (!fun) return NULL; PROTECT(fun); PROTECT(exp = allocVector(LANGSXP, 1)); SETCAR(exp, fun); PROTECT(res = do_eval_expr(exp)); UNPROTECT(3); return res; }
VALUE RObj_lcall(VALUE self, VALUE args){ SEXP exp, e, res; SEXP r_obj; int conv, default_mode; VALUE obj; //Ensure we have an array args = rb_check_array_type(args); // A SEXP with the function to call and the arguments PROTECT(exp = allocVector(LANGSXP, RARRAY_LEN(args)+1)); e = exp; Data_Get_Struct(self, struct SEXPREC, r_obj); SETCAR(e, r_obj); e = CDR(e); // Add the arguments to the SEXP if (!make_argl(args, &e)) { UNPROTECT(1); return Qnil; } // Evaluate PROTECT(res = do_eval_expr(exp)); if (!res) { UNPROTECT(2); return Qnil; } default_mode = NUM2INT(rb_iv_get(RSRUBY,"@default_mode")); // Convert if (default_mode < 0){ conv = NUM2INT(rb_iv_get(self,"@conversion")); } else { conv = default_mode; } obj = to_ruby_with_mode(res, conv); UNPROTECT(2); return obj; }
//lcall method that is safe to call during RSRuby initialisation VALUE RObj_init_lcall(VALUE self, VALUE args){ SEXP exp, e, res; SEXP r_obj; VALUE obj; //Ensure we have an array args = rb_check_array_type(args); // A SEXP with the function to call and the arguments PROTECT(exp = allocVector(LANGSXP, RARRAY_LEN(args)+1)); e = exp; Data_Get_Struct(self, struct SEXPREC, r_obj); SETCAR(e, r_obj); e = CDR(e); // Add the arguments to the SEXP if (!make_argl(args, &e)) { UNPROTECT(1); return Qnil; } // Evaluate PROTECT(res = do_eval_expr(exp)); if (!res) { UNPROTECT(2); return Qnil; } obj = to_ruby_with_mode(res, BASIC_CONVERSION); UNPROTECT(2); return obj; }