Example #1
0
static VALUE
setup_classes(VALUE unused)
{
    rb_mod_remove_const(rb_cObject, ID2SYM(rb_intern("Mutex")));
    rb_cMutex = rb_define_class("Mutex", rb_cObject);
    rb_define_alloc_func(rb_cMutex, rb_mutex_alloc);
    rb_define_method(rb_cMutex, "marshal_load", dummy_load, 1);
    rb_define_method(rb_cMutex, "marshal_dump", dummy_dump, 0);
    rb_define_method(rb_cMutex, "locked?", rb_mutex_locked_p, 0);
    rb_define_method(rb_cMutex, "try_lock", rb_mutex_try_lock, 0);
    rb_define_method(rb_cMutex, "lock", rb_mutex_lock, 0);
    rb_define_method(rb_cMutex, "unlock", rb_mutex_unlock, 0);
    rb_define_method(rb_cMutex, "exclusive_unlock", rb_mutex_exclusive_unlock, 0);
    rb_define_method(rb_cMutex, "synchronize", rb_mutex_synchronize, 0);

    rb_mod_remove_const(rb_cObject, ID2SYM(rb_intern("ConditionVariable")));
    rb_cConditionVariable = rb_define_class("ConditionVariable", rb_cObject);
    rb_define_alloc_func(rb_cConditionVariable, rb_condvar_alloc);
    rb_define_method(rb_cConditionVariable, "marshal_load", dummy_load, 1);
    rb_define_method(rb_cConditionVariable, "marshal_dump", dummy_dump, 0);
    rb_define_method(rb_cConditionVariable, "wait", rb_condvar_wait, 1);
    rb_define_method(rb_cConditionVariable, "broadcast", rb_condvar_broadcast, 0);
    rb_define_method(rb_cConditionVariable, "signal", rb_condvar_signal, 0);

    rb_mod_remove_const(rb_cObject, ID2SYM(rb_intern("Queue")));
    rb_cQueue = rb_define_class("Queue", rb_cObject);
    rb_define_alloc_func(rb_cQueue, rb_queue_alloc);
    rb_define_method(rb_cQueue, "marshal_load", rb_queue_marshal_load, 1);
    rb_define_method(rb_cQueue, "marshal_dump", rb_queue_marshal_dump, 0);
    rb_define_method(rb_cQueue, "clear", rb_queue_clear, 0);
    rb_define_method(rb_cQueue, "empty?", rb_queue_empty_p, 0);
    rb_define_method(rb_cQueue, "length", rb_queue_length, 0);
    rb_define_method(rb_cQueue, "num_waiting", rb_queue_num_waiting, 0);
    rb_define_method(rb_cQueue, "pop", rb_queue_pop, -1);
    rb_define_method(rb_cQueue, "push", rb_queue_push, 1);
    rb_alias(rb_cQueue, rb_intern("enq"), rb_intern("push"));
    rb_alias(rb_cQueue, rb_intern("<<"), rb_intern("push"));
    rb_alias(rb_cQueue, rb_intern("deq"), rb_intern("pop"));
    rb_alias(rb_cQueue, rb_intern("shift"), rb_intern("pop"));
    rb_alias(rb_cQueue, rb_intern("size"), rb_intern("length"));

    rb_mod_remove_const(rb_cObject, ID2SYM(rb_intern("SizedQueue")));
    rb_cSizedQueue = rb_define_class("SizedQueue", rb_cQueue);
    rb_define_method(rb_cSizedQueue, "initialize", rb_sized_queue_max_set, 1);
    rb_define_method(rb_cSizedQueue, "clear", rb_queue_clear, 0);
    rb_define_method(rb_cSizedQueue, "empty?", rb_queue_empty_p, 0);
    rb_define_method(rb_cSizedQueue, "length", rb_queue_length, 0);
    rb_define_method(rb_cSizedQueue, "num_waiting", rb_queue_num_waiting, 0);
    rb_define_method(rb_cSizedQueue, "pop", rb_queue_pop, -1);
    rb_define_method(rb_cSizedQueue, "push", rb_queue_push, 1);
    rb_define_method(rb_cSizedQueue, "max", rb_sized_queue_max, 0);
    rb_define_method(rb_cSizedQueue, "max=", rb_sized_queue_max_set, 1);
    rb_alias(rb_cSizedQueue, rb_intern("<<"), rb_intern("push"));
    rb_alias(rb_cSizedQueue, rb_intern("deq"), rb_intern("pop"));
    rb_alias(rb_cSizedQueue, rb_intern("shift"), rb_intern("pop"));

    return Qnil;
}
Example #2
0
/*
  Foo = Numo::Struct.new {
    int8     :byte
    float64  :float, [2,2]
    dcomplex :compl
  }
 */
static VALUE
nst_s_new(int argc, VALUE *argv, VALUE klass)
{
    VALUE name=Qnil, rest, size;
    VALUE st, members;
    ID id;

    rb_scan_args(argc, argv, "0*", &rest);
    if (RARRAY_LEN(rest)>0) {
        name = RARRAY_AREF(rest,0);
        if (!NIL_P(name)) {
            VALUE tmp = rb_check_string_type(name);
            if (!NIL_P(tmp)) {
                rb_ary_shift(rest);
            } else {
                name = Qnil;
            }
        }
    }

    if (NIL_P(name)) {
        st = rb_define_class_id(name, klass);
        rb_funcall(klass, rb_intern("inherited"), 1, st);
    }
    else {
        char *cname = StringValuePtr(name);
        id = rb_intern(cname);
        if (!rb_is_const_id(id)) {
            rb_name_error(id, "identifier %s needs to be constant", cname);
        }
        if (rb_const_defined_at(klass, id)) {
            rb_warn("redefining constant Struct::%s", cname);
            rb_mod_remove_const(klass, ID2SYM(id));
        }
        st = rb_define_class_under(klass, rb_id2name(id), klass);
    }

    rb_iv_set(st, "__members__", rb_ary_new());
    rb_iv_set(st, "__offset__", INT2FIX(0));

    if (rb_block_given_p()) {
        rb_mod_module_eval(0, 0, st);
    }

    size = rb_iv_get(st, "__offset__");
    members = rb_iv_get(st, "__members__");
    //printf("size=%d\n",NUM2INT(size));
    rb_define_const(st, CONTIGUOUS_STRIDE, size);
    rb_define_const(st, ELEMENT_BYTE_SIZE, size);
    rb_define_const(st, ELEMENT_BIT_SIZE,  rb_funcall(size,'*',1,INT2FIX(8)));

    OBJ_FREEZE(members);
    rb_define_const(st, "DEFINITIONS", members);

    rb_define_singleton_method(st, "new", rb_class_new_instance, -1);
    //rb_define_singleton_method(st, "[]", rb_class_new_instance, -1);
    rb_define_method(st, "allocate", nst_allocate, 0);

    return st;
}
Example #3
0
static VALUE
make_struct(VALUE name, VALUE members, VALUE klass)
{
    VALUE nstr;
    ID id;
    long i, len;

    OBJ_FREEZE(members);
    if (NIL_P(name)) {
	nstr = rb_class_new(klass);
#if !WITH_OBJC
	rb_make_metaclass(nstr, RBASIC(klass)->klass);
#endif
	rb_class_inherited(klass, nstr);
    }
    else {
	/* old style: should we warn? */
	name = rb_str_to_str(name);
	id = rb_to_id(name);
	if (!rb_is_const_id(id)) {
	    rb_name_error(id, "identifier %s needs to be constant",
		    StringValuePtr(name));
	}
	if (rb_const_defined_at(klass, id)) {
	    rb_warn("redefining constant Struct::%s", StringValuePtr(name));
	    rb_mod_remove_const(klass, ID2SYM(id));
	}
	nstr = rb_define_class_under(klass, rb_id2name(id), klass);
    }
    rb_ivar_set(nstr, id_members, members);

    rb_objc_define_method(*(VALUE *)nstr, "alloc", struct_alloc, 0);
    rb_objc_define_method(*(VALUE *)nstr, "new", rb_class_new_instance_imp, -1);
    rb_objc_define_method(*(VALUE *)nstr, "[]", rb_class_new_instance_imp, -1);
    rb_objc_define_method(*(VALUE *)nstr, "members", rb_struct_s_members_m, 0);
    len = RARRAY_LEN(members);
    for (i=0; i< len; i++) {
	ID id = SYM2ID(RARRAY_AT(members, i));
	if (rb_is_local_id(id) || rb_is_const_id(id)) {
	    long j = i; /* Needed for block data reference. */
	/* Struct attribute reader */
	rb_objc_define_method(nstr, rb_id2name(id),
		pl_imp_implementationWithBlock(^(VALUE obj) {
		    return RSTRUCT_PTR(obj)[j];
		}), 0);
	/* Struct attribute writer */
	rb_objc_define_method(nstr, rb_id2name(rb_id_attrset(id)),
		pl_imp_implementationWithBlock(^(VALUE obj, VALUE val) {
		    VALUE *ptr = RSTRUCT_PTR(obj);
		    rb_struct_modify(obj);
		    GC_WB(&ptr[i], val);
		    return val;
		}), 1);
Example #4
0
static VALUE
make_struct(VALUE name, VALUE members, VALUE klass)
{
    VALUE nstr;
    ID id;
    long i, count;

    OBJ_FREEZE(members);
    if (NIL_P(name)) {
	nstr = rb_class_new(klass);
#if !WITH_OBJC
	rb_make_metaclass(nstr, RBASIC(klass)->klass);
#endif
	rb_class_inherited(klass, nstr);
    }
    else {
	/* old style: should we warn? */
	name = rb_str_to_str(name);
	id = rb_to_id(name);
	if (!rb_is_const_id(id)) {
	    rb_name_error(id, "identifier %s needs to be constant",
		    StringValuePtr(name));
	}
	if (rb_const_defined_at(klass, id)) {
	    rb_warn("redefining constant Struct::%s", StringValuePtr(name));
	    rb_mod_remove_const(klass, ID2SYM(id));
	}
	nstr = rb_define_class_under(klass, rb_id2name(id), klass);
    }
    rb_iv_set(nstr, "__size__", LONG2NUM(RARRAY_LEN(members)));
    rb_iv_set(nstr, "__members__", members);

    rb_objc_define_method(*(VALUE *)nstr, "alloc", struct_alloc, 0);
    rb_objc_define_method(*(VALUE *)nstr, "new", rb_class_new_instance_imp, -1);
    rb_objc_define_method(*(VALUE *)nstr, "[]", rb_class_new_instance_imp, -1);
    rb_objc_define_method(*(VALUE *)nstr, "members", rb_struct_s_members_m, 0);
    for (i = 0, count = RARRAY_LEN(members); i < count; i++) {
	ID id = SYM2ID(RARRAY_AT(members, i));
	if (rb_is_local_id(id) || rb_is_const_id(id)) {
	    if (i < N_REF_FUNC) {
		rb_objc_define_method(nstr, rb_id2name(id), ref_func[i], 0);
	    }
	    else {
		rb_objc_define_method(nstr, rb_id2name(id), rb_struct_ref, 0);
	    }
	    rb_objc_define_method(nstr, rb_id2name(rb_id_attrset(id)),
		    rb_struct_set, 1);
	}
    }

    return nstr;
}
Example #5
0
static VALUE cov_generate_coverage_info(VALUE self) {
    VALUE cover;

    if (rb_const_defined_at(mRCOV__, id_cover)) rb_mod_remove_const(mRCOV__, ID2SYM(id_cover));

    cover = rb_hash_new();

    if (coverinfo) st_foreach(coverinfo, populate_cover, cover);

    rb_define_const(mRCOV__, "COVER", cover);

    return cover;
}
Example #6
0
static VALUE
make_struct(VALUE name, VALUE members, VALUE klass)
{
    VALUE nstr, *ptr_members;
    ID id;
    long i, len;

    OBJ_FREEZE(members);
    if (NIL_P(name)) {
	nstr = rb_class_new(klass);
	rb_make_metaclass(nstr, RBASIC(klass)->klass);
	rb_class_inherited(klass, nstr);
    }
    else {
	/* old style: should we warn? */
	name = rb_str_to_str(name);
	id = rb_to_id(name);
	if (!rb_is_const_id(id)) {
	    rb_name_error(id, "identifier %s needs to be constant", StringValuePtr(name));
	}
	if (rb_const_defined_at(klass, id)) {
	    rb_warn("redefining constant Struct::%s", StringValuePtr(name));
	    rb_mod_remove_const(klass, ID2SYM(id));
	}
	nstr = rb_define_class_id_under(klass, id, klass);
    }
    rb_ivar_set(nstr, id_members, members);

    rb_define_alloc_func(nstr, struct_alloc);
    rb_define_singleton_method(nstr, "new", rb_class_new_instance, -1);
    rb_define_singleton_method(nstr, "[]", rb_class_new_instance, -1);
    rb_define_singleton_method(nstr, "members", rb_struct_s_members_m, 0);
    ptr_members = RARRAY_PTR(members);
    len = RARRAY_LEN(members);
    for (i=0; i< len; i++) {
	ID id = SYM2ID(ptr_members[i]);
	if (rb_is_local_id(id) || rb_is_const_id(id)) {
	    if (i < N_REF_FUNC) {
		rb_define_method_id(nstr, id, ref_func[i], 0);
	    }
	    else {
		rb_define_method_id(nstr, id, rb_struct_ref, 0);
	    }
	    rb_define_method_id(nstr, rb_id_attrset(id), rb_struct_set, 1);
	}
    }

    return nstr;
}
Example #7
0
static VALUE
make_struct(VALUE name, VALUE members, VALUE klass)
{
    VALUE nstr;
    ID id;
    long i;

    OBJ_FREEZE(members);
    if (NIL_P(name)) {
	nstr = rb_class_new(klass);
	rb_make_metaclass(nstr, RBASIC(klass)->klass);
	rb_class_inherited(klass, nstr);
    }
    else {
	char *cname = StringValuePtr(name);
	id = rb_intern(cname);
	if (!rb_is_const_id(id)) {
	    rb_name_error(id, "identifier %s needs to be constant", cname);
	}
	if (rb_const_defined_at(klass, id)) {
	    rb_warn("redefining constant Struct::%s", cname);
	    rb_mod_remove_const(klass, ID2SYM(id));
	}
	nstr = rb_define_class_under(klass, rb_id2name(id), klass);
    }
    rb_iv_set(nstr, "__size__", LONG2NUM(RARRAY(members)->len));
    rb_iv_set(nstr, "__members__", members);

    rb_define_alloc_func(nstr, struct_alloc);
    rb_define_singleton_method(nstr, "new", rb_class_new_instance, -1);
    rb_define_singleton_method(nstr, "[]", rb_class_new_instance, -1);
    rb_define_singleton_method(nstr, "members", rb_struct_s_members_m, 0);
    for (i=0; i< RARRAY(members)->len; i++) {
	ID id = SYM2ID(RARRAY(members)->ptr[i]);
	if (rb_is_local_id(id) || rb_is_const_id(id)) {
	    if (i<10) {
		rb_define_method_id(nstr, id, ref_func[i], 0);
	    }
	    else {
		rb_define_method_id(nstr, id, rb_struct_ref, 0);
	    }
	    rb_define_method_id(nstr, rb_id_attrset(id), rb_struct_set, 1);
	}
    }

    return nstr;
}
static VALUE
new_struct(VALUE name, VALUE super)
{
    /* old style: should we warn? */
    ID id;
    name = rb_str_to_str(name);
    if (!rb_is_const_name(name)) {
        rb_name_error_str(name, "identifier %"PRIsVALUE" needs to be constant",
                          QUOTE(name));
    }
    id = rb_to_id(name);
    if (rb_const_defined_at(super, id)) {
        rb_warn("redefining constant %"PRIsVALUE"::%"PRIsVALUE, super, name);
        rb_mod_remove_const(super, ID2SYM(id));
    }
    return rb_define_class_id_under(super, id, super);
}
Example #9
0
/*
 * call-seq:
 *   IO.console      -> #<File:/dev/tty>
 *
 * Returns an File instance opened console.
 *
 * You must require 'io/console' to use this method.
 */
static VALUE
console_dev(VALUE klass)
{
    VALUE con = 0;
    rb_io_t *fptr;

    if (klass == rb_cIO) klass = rb_cFile;
    if (rb_const_defined(klass, id_console)) {
	con = rb_const_get(klass, id_console);
	if (RB_TYPE_P(con, T_FILE)) {
	    if ((fptr = RFILE(con)->fptr) && GetReadFD(fptr) != -1)
		return con;
	}
	rb_mod_remove_const(klass, ID2SYM(id_console));
    }
    {
	VALUE args[2];
#if defined HAVE_TERMIOS_H || defined HAVE_TERMIO_H || defined HAVE_SGTTY_H
# define CONSOLE_DEVICE "/dev/tty"
#elif defined _WIN32
# define CONSOLE_DEVICE "con$"
# define CONSOLE_DEVICE_FOR_READING "conin$"
# define CONSOLE_DEVICE_FOR_WRITING "conout$"
#endif
#ifndef CONSOLE_DEVICE_FOR_READING
# define CONSOLE_DEVICE_FOR_READING CONSOLE_DEVICE
#endif
#ifdef CONSOLE_DEVICE_FOR_WRITING
	VALUE out;
	rb_io_t *ofptr;
#endif
	int fd;

#ifdef CONSOLE_DEVICE_FOR_WRITING
	fd = rb_cloexec_open(CONSOLE_DEVICE_FOR_WRITING, O_WRONLY, 0);
	if (fd < 0) return Qnil;
        rb_update_max_fd(fd);
	args[1] = INT2FIX(O_WRONLY);
	args[0] = INT2NUM(fd);
	out = rb_class_new_instance(2, args, klass);
#endif
	fd = rb_cloexec_open(CONSOLE_DEVICE_FOR_READING, O_RDWR, 0);
	if (fd < 0) {
#ifdef CONSOLE_DEVICE_FOR_WRITING
	    rb_io_close(out);
#endif
	    return Qnil;
	}
        rb_update_max_fd(fd);
	args[1] = INT2FIX(O_RDWR);
	args[0] = INT2NUM(fd);
	con = rb_class_new_instance(2, args, klass);
	GetOpenFile(con, fptr);
#ifdef HAVE_RUBY_IO_H
	fptr->pathv = rb_obj_freeze(rb_str_new2(CONSOLE_DEVICE));
#else
	fptr->path = ruby_strdup(CONSOLE_DEVICE);
#endif
#ifdef CONSOLE_DEVICE_FOR_WRITING
	GetOpenFile(out, ofptr);
# ifdef HAVE_RB_IO_GET_WRITE_IO
	ofptr->pathv = fptr->pathv;
	fptr->tied_io_for_writing = out;
# else
	fptr->f2 = ofptr->f;
	ofptr->f = 0;
# endif
	ofptr->mode |= FMODE_SYNC;
#endif
	fptr->mode |= FMODE_SYNC;
	rb_const_set(klass, id_console, con);
    }
    return con;
}
Example #10
0
File: ruby.c Project: Shoes3/shoes3
//
// Everything exposed to Ruby is exposed here.
//
void shoes_ruby_init() {
    progname = rb_str_new2("(eval)");
    rb_define_variable("$0", &progname);
    rb_define_variable("$PROGRAM_NAME", &progname);

    instance_eval_proc = rb_eval_string("lambda{|o,b| o.instance_eval(&b)}");
    rb_gc_register_address(&instance_eval_proc);
    ssNestSlot = rb_eval_string("{:height => 1.0}");
    rb_gc_register_address(&ssNestSlot);

    s_aref = rb_intern("[]=");
    s_perc = rb_intern("%");
    s_mult = rb_intern("*");
    SYMBOL_DEFS(SYMBOL_INTERN);

    symAltQuest = ID2SYM(rb_intern("alt_?"));
    symAltSlash = ID2SYM(rb_intern("alt_/"));
    symAltEqual = ID2SYM(rb_intern("alt_="));
    symAltDot = ID2SYM(rb_intern("alt_."));
    symAltSemiColon = ID2SYM(rb_intern("alt_;"));

    //
    // I want all elements to be addressed Shoes::Name, but also available in
    // a separate mixin (cTypes), for inclusion in every Shoes.app block.
    //
    cTypes = rb_define_module("Shoes");
    rb_mod_remove_const(rb_cObject, rb_str_new2("Shoes"));

    cShoesWindow = rb_define_class_under(cTypes, "Window", rb_cObject);
    cMouse = rb_define_class_under(cTypes, "Mouse", rb_cObject);

    cCanvas = rb_define_class_under(cTypes, "Canvas", rb_cObject);
    rb_define_alloc_func(cCanvas, shoes_canvas_alloc);
    rb_define_method(cCanvas, "top", CASTHOOK(shoes_canvas_get_top), 0);
    rb_define_method(cCanvas, "left", CASTHOOK(shoes_canvas_get_left), 0);
    rb_define_method(cCanvas, "width", CASTHOOK(shoes_canvas_get_width), 0);
    rb_define_method(cCanvas, "height", CASTHOOK(shoes_canvas_get_height), 0);
    rb_define_method(cCanvas, "scroll_height", CASTHOOK(shoes_canvas_get_scroll_height), 0);
    rb_define_method(cCanvas, "scroll_max", CASTHOOK(shoes_canvas_get_scroll_max), 0);
    rb_define_method(cCanvas, "scroll_top", CASTHOOK(shoes_canvas_get_scroll_top), 0);
    rb_define_method(cCanvas, "scroll_top=", CASTHOOK(shoes_canvas_set_scroll_top), 1);
    rb_define_method(cCanvas, "displace", CASTHOOK(shoes_canvas_displace), 2);
    rb_define_method(cCanvas, "move", CASTHOOK(shoes_canvas_move), 2);
    rb_define_method(cCanvas, "style", CASTHOOK(shoes_canvas_style), -1);
    rb_define_method(cCanvas, "parent", CASTHOOK(shoes_canvas_get_parent), 0);
    rb_define_method(cCanvas, "contents", CASTHOOK(shoes_canvas_contents), 0);
    rb_define_method(cCanvas, "children", CASTHOOK(shoes_canvas_children), 0);
    rb_define_method(cCanvas, "draw", CASTHOOK(shoes_canvas_draw), 2);
    rb_define_method(cCanvas, "hide", CASTHOOK(shoes_canvas_hide), 0);
    rb_define_method(cCanvas, "show", CASTHOOK(shoes_canvas_show), 0);
    rb_define_method(cCanvas, "toggle", CASTHOOK(shoes_canvas_toggle), 0);
    rb_define_method(cCanvas, "remove", CASTHOOK(shoes_canvas_remove), 0);
    rb_define_method(cCanvas, "refresh_slot", CASTHOOK(shoes_canvas_refresh_slot), 0);
    rb_define_method(cCanvas, "refresh", CASTHOOK(shoes_canvas_refresh_slot), 0);
    rb_define_method(cCanvas, "cursor", CASTHOOK(shoes_canvas_get_cursor), 0);
    rb_define_method(cCanvas, "cursor=", CASTHOOK(shoes_canvas_set_cursor), 1);

    cShoes = rb_define_class("Shoes", cCanvas);
    rb_include_module(cShoes, cTypes);
    rb_const_set(cShoes, rb_intern("Types"), cTypes);

    shoes_version_init();

    // other Shoes:: constants
    rb_const_set(cTypes, rb_intern("RAD2PI"), rb_float_new(SHOES_RAD2PI));
    rb_const_set(cTypes, rb_intern("TWO_PI"), rb_float_new(SHOES_PIM2));
    rb_const_set(cTypes, rb_intern("HALF_PI"), rb_float_new(SHOES_HALFPI));
    rb_const_set(cTypes, rb_intern("PI"), rb_float_new(SHOES_PI));

    cApp = rb_define_class_under(cTypes, "App", rb_cObject);
    rb_define_alloc_func(cApp, shoes_app_alloc);
    rb_define_method(cApp, "fullscreen", CASTHOOK(shoes_app_get_fullscreen), 0);
    rb_define_method(cApp, "fullscreen=", CASTHOOK(shoes_app_set_fullscreen), 1);
    rb_define_method(cApp, "name", CASTHOOK(shoes_app_get_title), 0);
    rb_define_method(cApp, "name=", CASTHOOK(shoes_app_set_title), 1);
    rb_define_method(cApp, "location", CASTHOOK(shoes_app_location), 0);
    rb_define_method(cApp, "started?", CASTHOOK(shoes_app_is_started), 0);
    rb_define_method(cApp, "left", CASTHOOK(shoes_app_get_window_x_position), 0);
    rb_define_method(cApp, "top", CASTHOOK(shoes_app_get_window_y_position), 0);
    rb_define_method(cApp, "move", CASTHOOK(shoes_app_set_window_position), 2);
    rb_define_method(cApp, "width", CASTHOOK(shoes_app_get_width), 0);
    rb_define_method(cApp, "height", CASTHOOK(shoes_app_get_height), 0);
    rb_define_method(cApp, "resize", CASTHOOK(shoes_app_resize_window), 2);
    rb_define_method(cApp, "resizable", CASTHOOK(shoes_app_get_resizable), 0);
    rb_define_method(cApp, "resizable=", CASTHOOK(shoes_app_set_resizable), 1);
    rb_define_method(cApp, "slot", CASTHOOK(shoes_app_slot), 0);
    rb_define_method(cApp, "set_window_icon_path", CASTHOOK(shoes_app_set_icon), 1); // New in 3.2.19
    rb_define_method(cApp, "set_window_title", CASTHOOK(shoes_app_set_wtitle), 1); // New in 3.2.19
    rb_define_method(cApp, "opacity", CASTHOOK(shoes_app_get_opacity), 0);
    rb_define_method(cApp, "opacity=", CASTHOOK(shoes_app_set_opacity), 1);
    rb_define_method(cApp, "decorated", CASTHOOK(shoes_app_get_decoration), 0);
    rb_define_method(cApp, "decorated=", CASTHOOK(shoes_app_set_decoration), 1);
    rb_define_alias(cApp, "decorated?", "decorated");
    rb_define_method(cApp, "cache", CASTHOOK(shoes_app_get_cache), 0);
    rb_define_method(cApp, "cache=", CASTHOOK(shoes_app_set_cache), 1);
    rb_define_method(cApp, "cache_clear", CASTHOOK(shoes_app_clear_cache), 1);
    rb_define_method(cApp, "event=", CASTHOOK(shoes_app_set_event_handler), 1);
    rb_define_method(cApp, "replay_event", CASTHOOK(shoes_app_replay_event), 1);
    rb_define_method(cApp, "monitor", CASTHOOK(shoes_app_monitor_get), 0);
    rb_define_method(cApp, "monitor=", CASTHOOK(shoes_app_monitor_set), 1);
    rb_define_method(cApp, "id", CASTHOOK(shoes_app_id), 0);
    
    /* Settings holds global values, not per app values. Part of shoes_world_t */
    cSettings  = rb_define_class_under(cTypes, "Settings", rb_cObject);
    rb_define_alloc_func(cSettings, shoes_settings_alloc);
    rb_define_method(cSettings, "dbus", CASTHOOK(shoes_settings_dbus),0);
    rb_define_method(cSettings, "app_name", CASTHOOK(shoes_settings_app_name),0);
    rb_define_method(cSettings, "app_name=", CASTHOOK(shoes_settings_set_app_name),1);
    rb_define_method(cSettings, "icon_path", CASTHOOK(shoes_settings_app_icon),0);
    rb_define_method(cSettings, "icon_path=", CASTHOOK(shoes_settings_set_app_icon),1);
    rb_define_method(cSettings, "theme", CASTHOOK(shoes_settings_get_theme),0);
    rb_define_method(cSettings, "theme=", CASTHOOK(shoes_settings_set_theme),1);
    rb_define_method(cSettings, "mdi", CASTHOOK(shoes_settings_mdi),0);
    rb_define_method(cSettings, "use_menus", CASTHOOK(shoes_settings_menu),0);
    rb_define_method(cSettings, "rdomain", CASTHOOK(shoes_settings_rdomain),0);
    rb_define_method(cSettings, "rdomain=", CASTHOOK(shoes_settings_set_rdomain),1);
    rb_define_method(cSettings, "monitor_count", CASTHOOK(shoes_settings_monitor_count),0);
    rb_define_method(cSettings, "monitor_geometry", CASTHOOK(shoes_settings_monitor_geometry),1);
    rb_define_method(cSettings, "monitor_default", CASTHOOK(shoes_settings_monitor_default), 0);
    rb_define_method(cSettings, "extra1", CASTHOOK(shoes_setting_extra1), 0);
    rb_define_method(cSettings, "extra2", CASTHOOK(shoes_setting_extra2), 0);
    rb_define_method(cSettings, "wintmo", CASTHOOK(shoes_setting_get_wintmo), 0);
    rb_define_method(cSettings, "wintmo=", CASTHOOK(shoes_setting_set_wintmo), 1);
    rb_define_method(cSettings, "display_backend", CASTHOOK(shoes_setting_display_backend), 0);

    cDialog = rb_define_class_under(cTypes, "Dialog", cApp);

    eInvMode = rb_define_class_under(cTypes, "InvalidModeError", rb_eStandardError);
    eNotImpl = rb_define_class_under(cTypes, "NotImplementedError", rb_eStandardError);
    eImageError = rb_define_class_under(cTypes, "ImageError", rb_eStandardError);
    C(HEX_SOURCE, "/^(?:0x|#)?([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})$/i");
    C(HEX3_SOURCE, "/^(?:0x|#)?([0-9A-F])([0-9A-F])([0-9A-F])$/i");
    C(RGB_SOURCE, "/^rgb\\((\\d+), *(\\d+), *(\\d+)\\)$/i");
    C(RGBA_SOURCE, "/^rgb\\((\\d+), *(\\d+), *(\\d+), *(\\d+)\\)$/i");
    C(GRAY_SOURCE, "/^gray\\((\\d+)\\)$/i");
    C(GRAYA_SOURCE, "/^gray\\((\\d+), *(\\d+)\\)$/i");
    C(LF, "/\\r?\\n/");
    rb_eval_string(
        "def Shoes.escape(string);"
        "string.gsub(/&/n, '&amp;').gsub(/\\\"/n, '&quot;').gsub(/>/n, '&gt;').gsub(/</n, '&lt;');"
        "end"
    );

    rb_define_singleton_method(cShoes, "APPS", CASTHOOK(shoes_apps_get), 0);
    rb_define_singleton_method(cShoes, "app", CASTHOOK(shoes_app_main), -1);
    rb_define_singleton_method(cShoes, "p", CASTHOOK(shoes_p), 1);
    rb_define_singleton_method(cShoes, "log", CASTHOOK(shoes_log), 0);
    rb_define_singleton_method(cShoes, "show_console", CASTHOOK(shoes_app_console), 0); // New in 3.2.23
    rb_define_singleton_method(cShoes, "terminal", CASTHOOK(shoes_app_terminal), -1); // New in 3.3.2 replaces console
    rb_define_singleton_method(cShoes, "quit", CASTHOOK(shoes_app_quit), 0); // Shoes 3.3.2
    rb_define_singleton_method(cShoes, "settings", CASTHOOK(shoes_app_settings), 0); // Shoes 3.3.7 
    //rb_define_singleton_method(cShoes, "exit", CASTHOOK(shoes_app_quit), 0);

    //
    // Canvas methods
    // See ruby.h for the complete list of Canvas method signatures.
    // Macros are used to build App redirection methods, which should be
    // speedier than method_missing.
    //

    CANVAS_DEFS(RUBY_M);

    //
    // Shoes Kernel methods
    //
    //rb_define_method(rb_mKernel, "quit", CASTHOOK(shoes_app_quit), 0);
    //rb_define_method(rb_mKernel, "exit", CASTHOOK(shoes_app_quit), 0);
    rb_define_method(rb_mKernel, "secret_exit_hook", CASTHOOK(shoes_exit_setup),0); //unused?

    rb_define_method(rb_mKernel, "debug", CASTHOOK(shoes_canvas_debug), 1);
    rb_define_method(rb_mKernel, "info", CASTHOOK(shoes_canvas_info), 1);
    rb_define_method(rb_mKernel, "warn", CASTHOOK(shoes_canvas_warn), 1);
    rb_define_method(rb_mKernel, "error", CASTHOOK(shoes_canvas_error), 1);

    cFlow       = rb_define_class_under(cTypes, "Flow", cShoes);
    cStack      = rb_define_class_under(cTypes, "Stack", cShoes);
    cMask       = rb_define_class_under(cTypes, "Mask", cShoes);
    cWidget     = rb_define_class_under(cTypes, "Widget", cShoes);

    rb_define_method(cApp, "method_missing", CASTHOOK(shoes_app_method_missing), -1);

    rb_define_method(rb_mKernel, "alert", CASTHOOK(shoes_dialog_alert), -1);
    rb_define_method(rb_mKernel, "ask", CASTHOOK(shoes_dialog_ask), -1);
    rb_define_method(rb_mKernel, "confirm", CASTHOOK(shoes_dialog_confirm), -1);
    rb_define_method(rb_mKernel, "ask_color", CASTHOOK(shoes_dialog_color), 1);
    rb_define_method(rb_mKernel, "ask_open_file", CASTHOOK(shoes_dialog_open), -1);
    rb_define_method(rb_mKernel, "ask_save_file", CASTHOOK(shoes_dialog_save), -1);
    rb_define_method(rb_mKernel, "ask_open_folder", CASTHOOK(shoes_dialog_open_folder), -1);
    rb_define_method(rb_mKernel, "ask_save_folder", CASTHOOK(shoes_dialog_save_folder), -1);
    rb_define_method(rb_mKernel, "font", CASTHOOK(shoes_font), 1);
    
    SHOES_TYPES_INIT;
}