Ejemplo n.º 1
0
static VALUE ruby_function_proxy(VALUE self, VALUE _args)
{
    ID id = rb_frame_last_func();

    value_t* value = dict_lookup(global->functions, (void*)id);

    if(!value) {
        language_error(global->li, "[ruby] couldn't retrieve constant %s", rb_id2name(id));
        return Qnil;
    }

    if(value->type == TYPE_FUNCTION) {
        log_dbg("[ruby] calling function %s", rb_id2name(id));
        value_t*args = ruby_to_value(_args);
        value_t*ret = value->call(value, args);
        value_destroy(args);
        volatile VALUE r = value_to_ruby(ret);
        value_destroy(ret);
        log_dbg("[rb] returning from callback");
        return r;
    } else {
        log_dbg("[ruby] retrieving constant %s (%s)", rb_id2name(id), type_to_string(value->type));
        volatile VALUE r = value_to_ruby(value);
        return r;
    }
    return Qnil;
}
Ejemplo n.º 2
0
Archivo: ruby.c Proyecto: Shoes3/shoes3
void shoes_msg(ID typ, VALUE str) {
#ifndef RUBY_1_8
    ID func = rb_frame_this_func();
    rb_ary_push(shoes_world->msgs, rb_ary_new3(6,
                ID2SYM(typ), str, rb_funcall(rb_cTime, s_now, 0),
                func ? ID2SYM(func) : Qnil,
                rb_str_new2("<unknown>"), INT2NUM(0)));
#else
    ID func = rb_frame_last_func();
    rb_ary_push(shoes_world->msgs, rb_ary_new3(6,
                ID2SYM(typ), str, rb_funcall(rb_cTime, s_now, 0),
                func ? ID2SYM(func) : Qnil,
                rb_str_new2(ruby_sourcefile), INT2NUM(ruby_sourceline)));
#endif
}
Ejemplo n.º 3
0
static void error_pos(FILE *out, int cgi)
{
    char buff[BUFSIZ];
#if RUBY_VERSION_CODE >= 190
    ID last_func = rb_frame_this_func();
#else
    ID last_func = rb_frame_last_func();
#endif

    if (ruby_sourcefile) {
	if (last_func) {
	    snprintf(buff, BUFSIZ, "%s:%d:in `%s'", ruby_sourcefile, ruby_sourceline,
		     rb_id2name(last_func));
	}
	else {
	    snprintf(buff, BUFSIZ, "%s:%d", ruby_sourcefile, ruby_sourceline);
	}
	if (cgi)
	    write_escaping_html(out, buff, strlen(buff));
	else
	    fputs(buff, out);
    }
}