Beispiel #1
0
void
rb_singleton_class_promote_for_gc(VALUE klass)
{
    rb_objc_install_method2((Class)klass, "finalize",
	    (IMP)robj_sclass_finalize_imp);
}
Beispiel #2
0
void
Init_Thread(void)
{
    rb_cThread = rb_define_class("Thread", rb_cObject);
    rb_objc_define_method(*(VALUE *)rb_cThread, "alloc", thread_s_alloc, 0);

    thread_finalize_imp_super = rb_objc_install_method2((Class)rb_cThread,
	    "finalize", (IMP)thread_finalize_imp);

    rb_objc_define_method(*(VALUE *)rb_cThread, "start", thread_start, -1);
    rb_objc_define_method(*(VALUE *)rb_cThread, "fork", thread_start, -1);
    rb_objc_define_method(*(VALUE *)rb_cThread, "main", rb_thread_s_main, 0);
    rb_objc_define_method(*(VALUE *)rb_cThread, "current", thread_s_current, 0);
    rb_objc_define_method(*(VALUE *)rb_cThread, "stop", rb_thread_stop, 0);
    rb_objc_define_method(*(VALUE *)rb_cThread, "kill", rb_thread_s_kill, 1);
    rb_objc_define_method(*(VALUE *)rb_cThread, "exit", rb_thread_exit, 0);
    rb_objc_define_method(*(VALUE *)rb_cThread, "pass", thread_s_pass, 0);
    rb_objc_define_method(*(VALUE *)rb_cThread, "list", rb_thread_list, 0);
    rb_objc_define_method(*(VALUE *)rb_cThread, "abort_on_exception", rb_thread_s_abort_exc, 0);
    rb_objc_define_method(*(VALUE *)rb_cThread, "abort_on_exception=", rb_thread_s_abort_exc_set, 1);

    rb_objc_define_method(rb_cThread, "initialize", thread_initialize, -1);
    rb_objc_define_method(rb_cThread, "raise", thread_raise_m, -1);
    rb_objc_define_method(rb_cThread, "join", thread_join_m, -1);
    rb_objc_define_method(rb_cThread, "value", thread_value, 0);
    rb_objc_define_method(rb_cThread, "kill", rb_thread_kill, 0);
    rb_objc_define_method(rb_cThread, "terminate", rb_thread_kill, 0);
    rb_objc_define_method(rb_cThread, "exit", rb_thread_kill, 0);
    rb_objc_define_method(rb_cThread, "run", rb_thread_run, 0);
    rb_objc_define_method(rb_cThread, "wakeup", rb_thread_wakeup, 0);
    rb_objc_define_method(rb_cThread, "[]", rb_thread_aref, 1);
    rb_objc_define_method(rb_cThread, "[]=", rb_thread_aset, 2);
    rb_objc_define_method(rb_cThread, "key?", rb_thread_key_p, 1);
    rb_objc_define_method(rb_cThread, "keys", rb_thread_keys, 0);
    rb_objc_define_method(rb_cThread, "priority", rb_thread_priority, 0);
    rb_objc_define_method(rb_cThread, "priority=", rb_thread_priority_set, 1);
    rb_objc_define_method(rb_cThread, "status", rb_thread_status, 0);
    rb_objc_define_method(rb_cThread, "alive?", rb_thread_alive_p, 0);
    rb_objc_define_method(rb_cThread, "stop?", rb_thread_stop_p, 0);
    rb_objc_define_method(rb_cThread, "abort_on_exception", rb_thread_abort_exc, 0);
    rb_objc_define_method(rb_cThread, "abort_on_exception=", rb_thread_abort_exc_set, 1);
    rb_objc_define_method(rb_cThread, "safe_level", rb_thread_safe_level, 0);
    rb_objc_define_method(rb_cThread, "group", rb_thread_group, 0);

    rb_objc_define_method(rb_cThread, "inspect", rb_thread_inspect, 0);

    rb_cThGroup = rb_define_class("ThreadGroup", rb_cObject);
    rb_objc_define_method(*(VALUE *)rb_cThGroup, "alloc", thgroup_s_alloc, 0);
    rb_objc_define_method(rb_cThGroup, "list", thgroup_list, 0);
    rb_objc_define_method(rb_cThGroup, "enclose", thgroup_enclose, 0);
    rb_objc_define_method(rb_cThGroup, "enclosed?", thgroup_enclosed_p, 0);
    rb_objc_define_method(rb_cThGroup, "add", thgroup_add, 1);

    rb_cMutex = rb_define_class("Mutex", rb_cObject);
    rb_objc_define_method(*(VALUE *)rb_cMutex, "alloc", mutex_s_alloc, 0);
    rb_objc_define_method(rb_cMutex, "initialize", mutex_initialize, 0);
    rb_objc_define_method(rb_cMutex, "locked?", rb_mutex_locked_p, 0);
    rb_objc_define_method(rb_cMutex, "try_lock", rb_mutex_trylock, 0);
    rb_objc_define_method(rb_cMutex, "lock", rb_mutex_lock, 0);
    rb_objc_define_method(rb_cMutex, "unlock", rb_mutex_unlock, 0);
    rb_objc_define_method(rb_cMutex, "sleep", mutex_sleep, -1);
    rb_objc_define_method(rb_cMutex, "synchronize", mutex_synchronize, 0);

    rb_eThreadError = rb_define_class("ThreadError", rb_eStandardError);
}
Beispiel #3
0
void
Init_Hash(void)
{
    Init_NSDictionary();

    selFlattenBang = sel_registerName("flatten!:");
    selDefault = sel_registerName("default:");
    selHash = sel_registerName("hash");

    id_yield = rb_intern("yield");

    rb_cRubyHash = rb_define_class("Hash", rb_cNSMutableHash);
    rb_objc_install_NSObject_special_methods((Class)rb_cRubyHash);

    rb_objc_define_method(*(VALUE *)rb_cRubyHash, "new",
	    rb_class_new_instance_imp, -1);
    rb_objc_define_method(*(VALUE *)rb_cRubyHash, "alloc", rhash_alloc, 0);
    rb_objc_define_method(*(VALUE *)rb_cRubyHash, "[]", rhash_create, -1);
    rb_objc_define_method(*(VALUE *)rb_cRubyHash, "try_convert",
	    rhash_try_convert, 1);
    rb_objc_define_method(rb_cRubyHash, "initialize", rhash_initialize, -1);
    rb_objc_define_method(rb_cRubyHash, "initialize_copy", rhash_replace, 1);
    rb_objc_define_method(rb_cRubyHash, "dup", rhash_dup, 0);
    rb_objc_define_method(rb_cRubyHash, "rehash", rhash_rehash, 0);
    rb_objc_define_method(rb_cRubyHash, "to_hash", rhash_to_hash, 0);
    rb_objc_define_method(rb_cRubyHash, "to_a", rhash_to_a, 0);
    rb_objc_define_method(rb_cRubyHash, "to_s", rhash_inspect, 0);
    rb_objc_define_method(rb_cRubyHash, "inspect", rhash_inspect, 0);
    rb_objc_define_method(rb_cRubyHash, "==", rhash_equal, 1);
    rb_objc_define_method(rb_cRubyHash, "[]", rhash_aref, 1);
    rb_objc_define_method(rb_cRubyHash, "eql?", rhash_eql, 1);
    rb_objc_define_method(rb_cRubyHash, "fetch", rhash_fetch, -1);
    rb_objc_define_method(rb_cRubyHash, "[]=", rhash_aset, 2);
    rb_objc_define_method(rb_cRubyHash, "store", rhash_aset, 2);
    rb_objc_define_method(rb_cRubyHash, "default", rhash_default, -1);
    rb_objc_define_method(rb_cRubyHash, "default=", rhash_set_default, 1);
    rb_objc_define_method(rb_cRubyHash, "default_proc",
	    rhash_default_proc, 0);
    rb_objc_define_method(rb_cRubyHash, "default_proc=",
	    rhash_set_default_proc, 1);
    rb_objc_define_method(rb_cRubyHash, "key", rhash_key, 1);
    rb_objc_define_method(rb_cRubyHash, "index", rhash_index, 1);
    rb_objc_define_method(rb_cRubyHash, "size", rhash_size, 0);
    rb_objc_define_method(rb_cRubyHash, "length", rhash_size, 0);
    rb_objc_define_method(rb_cRubyHash, "empty?", rhash_empty, 0);
    rb_objc_define_method(rb_cRubyHash, "each_value", rhash_each_value, 0);
    rb_objc_define_method(rb_cRubyHash, "each_key", rhash_each_key, 0);
    rb_objc_define_method(rb_cRubyHash, "each_pair", rhash_each_pair, 0);
    rb_objc_define_method(rb_cRubyHash, "each", rhash_each_pair, 0);
    rb_objc_define_method(rb_cRubyHash, "keys", rhash_keys, 0);
    rb_objc_define_method(rb_cRubyHash, "values", rhash_values, 0);
    rb_objc_define_method(rb_cRubyHash, "values_at", rhash_values_at, -1);
    rb_objc_define_method(rb_cRubyHash, "shift", rhash_shift, 0);
    rb_objc_define_method(rb_cRubyHash, "delete", rhash_delete, 1);
    rb_objc_define_method(rb_cRubyHash, "delete_if", rhash_delete_if, 0);
    rb_objc_define_method(rb_cRubyHash, "keep_if", rhash_keep_if, 0);
    rb_objc_define_method(rb_cRubyHash, "select", rhash_select, 0);
    rb_objc_define_method(rb_cRubyHash, "select!", rhash_select_bang, 0);
    rb_objc_define_method(rb_cRubyHash, "reject", rhash_reject, 0);
    rb_objc_define_method(rb_cRubyHash, "reject!", rhash_reject_bang, 0);
    rb_objc_define_method(rb_cRubyHash, "clear", rhash_clear, 0);
    rb_objc_define_method(rb_cRubyHash, "invert", rhash_invert, 0);
    rb_objc_define_method(rb_cRubyHash, "update", rhash_update, 1);
    rb_objc_define_method(rb_cRubyHash, "replace", rhash_replace, 1);
    rb_objc_define_method(rb_cRubyHash, "merge!", rhash_update, 1);
    rb_objc_define_method(rb_cRubyHash, "merge", rhash_merge, 1);
    rb_objc_define_method(rb_cRubyHash, "assoc", rhash_assoc, 1);
    rb_objc_define_method(rb_cRubyHash, "rassoc", rhash_rassoc, 1);
    rb_objc_define_method(rb_cRubyHash, "flatten", rhash_flatten, -1);
    rb_objc_define_method(rb_cRubyHash, "include?", rhash_has_key, 1);
    rb_objc_define_method(rb_cRubyHash, "member?", rhash_has_key, 1);
    rb_objc_define_method(rb_cRubyHash, "has_key?", rhash_has_key, 1);
    rb_objc_define_method(rb_cRubyHash, "has_value?", rhash_has_value, 1);
    rb_objc_define_method(rb_cRubyHash, "key?", rhash_has_key, 1);
    rb_objc_define_method(rb_cRubyHash, "value?", rhash_has_value, 1);
    rb_objc_define_method(rb_cRubyHash, "compare_by_identity",
	    rhash_compare_by_id, 0);
    rb_objc_define_method(rb_cRubyHash, "compare_by_identity?",
	    rhash_compare_by_id_p, 0);

    rb_objc_install_method2((Class)rb_cRubyHash, "count",
	    (IMP)imp_rhash_count);
    rb_objc_install_method2((Class)rb_cRubyHash, "objectForKey:",
	    (IMP)imp_rhash_objectForKey);
    rb_objc_install_method2((Class)rb_cRubyHash, "keyEnumerator",
	    (IMP)imp_rhash_keyEnumerator);
    rb_objc_install_method2((Class)rb_cRubyHash, "setObject:forKey:",
	    (IMP)imp_rhash_setObjectForKey);
    rb_objc_install_method2((Class)rb_cRubyHash, "removeObjectForKey:",
	    (IMP)imp_rhash_removeObjectForKey);

    VALUE NSEnumerator = (VALUE)objc_getClass("NSEnumerator");
    assert(NSEnumerator != 0);
    rb_cRubyHashKeyEnumerator = rb_define_class("RubyHashKeyEnumerator",
	NSEnumerator);
    rb_objc_install_method2((Class)rb_cRubyHashKeyEnumerator, "allObjects",
	(IMP)imp_rhash_keyenum_allObjects);
    rb_objc_install_method2((Class)rb_cRubyHashKeyEnumerator, "nextObject",
	(IMP)imp_rhash_keyenum_nextObject);
}
Beispiel #4
0
void
Init_libyaml()
{
    id_plain = rb_intern("plain");
    id_quote1 = rb_intern("quote1");
    id_quote2 = rb_intern("quote2");
    id_inline = rb_intern("inline");
    id_fold = rb_intern("fold");
    id_literal = rb_intern("literal");

    sel_to_yaml = sel_registerName("to_yaml:");
    sel_call = sel_registerName("call:");
    sel_yaml_new = sel_registerName("yaml_new:");

    rb_mYAML = rb_define_module("YAML");

    rb_mLibYAML = rb_define_module_under(rb_mYAML, "LibYAML");
    rb_define_const(rb_mLibYAML, "VERSION",
	    rb_str_new2(yaml_get_version_string()));

    rb_cParser = rb_define_class_under(rb_mLibYAML, "Parser", rb_cObject);
    rb_objc_define_method(*(VALUE *)rb_cParser, "alloc", rb_yaml_parser_alloc,
	    0);
    rb_objc_define_method(rb_cParser, "initialize", rb_yaml_parser_initialize,
	    -1);
    rb_objc_define_method(rb_cParser, "input", rb_yaml_parser_input, 0);
    rb_objc_define_method(rb_cParser, "input=", rb_yaml_parser_set_input, 1);
    // commented methods here are just unimplemented; i plan to put them in soon.
    //rb_objc_define_method(rb_cParser, "encoding", rb_yaml_parser_encoding, 0);
    //rb_objc_define_method(rb_cParser, "encoding=", rb_yaml_parser_set_encoding, 1);
    rb_objc_define_method(rb_cParser, "error", rb_yaml_parser_error, 0);
    rb_objc_define_method(rb_cParser, "load", rb_yaml_parser_load, 0);
    rb_objc_define_method(rb_cParser, "parse", rb_yaml_parser_parse, 0);
    rb_yaml_parser_finalize_super = rb_objc_install_method2((Class)rb_cParser,
	    "finalize", (IMP)rb_yaml_parser_finalize);

    rb_cResolver = rb_define_class_under(rb_mLibYAML, "Resolver", rb_cObject);
    rb_objc_define_method(*(VALUE *)rb_cResolver, "alloc",
	    rb_yaml_resolver_alloc, 0);
    rb_objc_define_method(rb_cResolver, "initialize",
	    rb_yaml_resolver_initialize, 0);
    //rb_objc_define_method(rb_cResolver, "transfer", rb_yaml_resolver_transfer, 1);
    rb_objc_define_method(rb_cResolver, "add_type", rb_yaml_resolver_add_type,
	    2);
    //rb_objc_define_method(rb_cResolver, "add_domain_type", rb_yaml_resolver_add_domain_type, 2);
    //rb_objc_define_method(rb_cResolver, "add_ruby_type", rb_yaml_resolver_add_ruby_type, 1);
    //rb_objc_define_method(rb_cResolver, "add_builtin_type", rb_yaml_resolver_add_builtin_type, 1);
    //rb_objc_define_method(rb_cResolver, "add_private_type", rb_yaml_resolver_add_private_type, 1);
    rb_oDefaultResolver = rb_vm_call(rb_cResolver, sel_registerName("new"), 0, NULL);
    rb_define_const(rb_mLibYAML, "DEFAULT_RESOLVER", rb_oDefaultResolver);

    rb_cEmitter = rb_define_class_under(rb_mLibYAML, "Emitter", rb_cObject);
    rb_objc_define_method(*(VALUE *)rb_cEmitter, "alloc", rb_yaml_emitter_alloc, 0);
    rb_define_attr(rb_cEmitter, "output", 1, 1);
    rb_objc_define_method(rb_cEmitter, "initialize", rb_yaml_emitter_initialize, -1);
    rb_objc_define_method(rb_cEmitter, "output=", rb_yaml_emitter_set_output, 1);
    //rb_objc_define_method(rb_cEmitter, "dump", rb_yaml_emitter_dump, -1);
    rb_objc_define_method(rb_cEmitter, "stream", rb_yaml_emitter_stream, 0);
    rb_objc_define_method(rb_cEmitter, "document", rb_yaml_emitter_document, -1);
    rb_objc_define_method(rb_cEmitter, "seq", rb_yaml_emitter_sequence, 2);
    rb_objc_define_method(rb_cEmitter, "map", rb_yaml_emitter_mapping, 2);
    rb_objc_define_method(rb_cEmitter, "scalar", rb_yaml_emitter_scalar, 3);
    rb_objc_define_method(rb_cEmitter, "add", rb_yaml_emitter_add, -1);

    //rb_objc_define_method(rb_cEmitter, "error", rb_yaml_emitter_error, 0);
    //rb_objc_define_method(rb_cEmitter, "encoding", rb_yaml_emitter_encoding, 0);
    //rb_objc_define_method(rb_cEmitter, "encoding=", rb_yaml_emitter_set_encoding, 1);
    //rb_objc_define_method(rb_cEmitter, "indentation", rb_yaml_emitter_indent, 0);
    // TODO: fill in the rest of the accessors
    rb_yaml_emitter_finalize_super = rb_objc_install_method2((Class)rb_cEmitter, "finalize", (IMP)rb_yaml_emitter_finalize);

    rb_cYamlNode = rb_define_class_under(rb_mYAML, "YamlNode", rb_cObject);
}