Exemplo n.º 1
0
void Init_native()
{
  mQuail = rb_define_module("Quail");
  rb_const_set(mQuail, rb_intern("LOCAL"), INT2NUM(CZMQ_SCOPE_LOCAL));
  rb_const_set(mQuail, rb_intern("GLOBAL"), INT2NUM(CZMQ_SCOPE_GLOBAL));
  czmq_set_error_handler(error_handler);

  Init_Quail_Handle(mQuail);
  Init_Quail_Exchange(mQuail);
  Init_Quail_Queue(mQuail);
}
Exemplo n.º 2
0
void init_libssh2_global() {
    rb_const_set(rb_mLibSSH2_Native,
            rb_intern("SESSION_BLOCK_INBOUND"),
            INT2FIX(LIBSSH2_SESSION_BLOCK_INBOUND));

    rb_const_set(rb_mLibSSH2_Native,
            rb_intern("SESSION_BLOCK_OUTBOUND"),
            INT2FIX(LIBSSH2_SESSION_BLOCK_OUTBOUND));

    rb_define_singleton_method(rb_mLibSSH2_Native, "exit", libexit, 0);
    rb_define_singleton_method(rb_mLibSSH2_Native, "init", init, 0);
    rb_define_singleton_method(rb_mLibSSH2_Native, "version", version, 0);
}
Exemplo n.º 3
0
void Init_nokogiri()
{
  xmlMemSetup(
      (xmlFreeFunc)ruby_xfree,
      (xmlMallocFunc)ruby_xmalloc,
      (xmlReallocFunc)ruby_xrealloc,
      strdup
  );

  mNokogiri         = rb_define_module("Nokogiri");
  mNokogiriXml      = rb_define_module_under(mNokogiri, "XML");
  mNokogiriHtml     = rb_define_module_under(mNokogiri, "HTML");
  mNokogiriXslt     = rb_define_module_under(mNokogiri, "XSLT");
  mNokogiriXmlSax   = rb_define_module_under(mNokogiriXml, "SAX");
  mNokogiriHtmlSax  = rb_define_module_under(mNokogiriHtml, "SAX");

  rb_const_set( mNokogiri,
                rb_intern("LIBXML_VERSION"),
                NOKOGIRI_STR_NEW2(LIBXML_DOTTED_VERSION, "UTF-8")
              );
  rb_const_set( mNokogiri,
                rb_intern("LIBXML_PARSER_VERSION"),
                NOKOGIRI_STR_NEW2(xmlParserVersion, "UTF-8")
              );

  init_xml_document();
  init_html_document();
  init_xml_node();
  init_xml_document_fragment();
  init_xml_text();
  init_xml_cdata();
  init_xml_processing_instruction();
  init_xml_attr();
  init_xml_entity_reference();
  init_xml_comment();
  init_xml_node_set();
  init_xml_xpath_context();
  init_xml_xpath();
  init_xml_sax_parser();
  init_xml_sax_push_parser();
  init_xml_reader();
  init_xml_dtd();
  init_xml_namespace();
  init_html_sax_parser();
  init_xslt_stylesheet();
  init_xml_syntax_error();
  init_html_entity_lookup();
  init_html_element_description();
  init_xml_schema();
  init_xml_relax_ng();
}
Exemplo n.º 4
0
Arquivo: nyara.c Projeto: fsword/nyara
void Init_nyara() {
  u8_encoding = rb_utf8_encoding();
  set_fd_limit(20000);

  nyara = rb_define_module("Nyara");
# include "inc/version.inc"
  rb_const_set(nyara, rb_intern("VERSION"), rb_enc_str_new(NYARA_VERSION, strlen(NYARA_VERSION), u8_encoding));

  // utils: hashes
  Init_hashes(nyara);

  // utils: method map
  volatile VALUE method_map = rb_class_new_instance(0, NULL, nyara_param_hash_class);
  rb_const_set(nyara, rb_intern("HTTP_METHODS"), method_map);
  VALUE tmp_key = Qnil;
# define METHOD_STR2NUM(n, name, string) \
    tmp_key = rb_enc_str_new(#string, strlen(#string), u8_encoding);\
    OBJ_FREEZE(tmp_key);\
    rb_hash_aset(method_map, tmp_key, INT2FIX(n));
  HTTP_METHOD_MAP(METHOD_STR2NUM);
# undef METHOD_STR2NUM
  OBJ_FREEZE(method_map);

  // utils: status codes
  volatile VALUE status_map = rb_hash_new();
  rb_const_set(nyara, rb_intern("HTTP_STATUS_CODES"), status_map);
  VALUE tmp_value = Qnil;
# define STATUS_DESC(status, desc) \
    tmp_value = rb_enc_str_new(desc, strlen(desc), u8_encoding);\
    OBJ_FREEZE(tmp_value);\
    rb_hash_aset(status_map, INT2FIX(status), tmp_value);
  HTTP_STATUS_CODES(STATUS_DESC);
# undef STATUS_DESC
  OBJ_FREEZE(status_map);

  VALUE ext = rb_define_module_under(nyara, "Ext");
  rb_define_singleton_method(ext, "rdtsc_start", ext_rdtsc_start, 0);
  rb_define_singleton_method(ext, "rdtsc", ext_rdtsc, 0);

  Init_accept(ext);
  Init_mime(ext);
  Init_request(nyara, ext);
  Init_request_parse(nyara, ext);
  Init_test_response(nyara);
  Init_event(ext);
  Init_route(nyara, ext);
  Init_url_encoded(ext);
}
Exemplo n.º 5
0
Arquivo: class.c Projeto: MSch/MacRuby
VALUE
rb_define_class_under(VALUE outer, const char *name, VALUE super)
{
    VALUE klass;
    ID id;

    id = rb_intern(name);
    if (rb_const_defined_at(outer, id)) {
	klass = rb_const_get_at(outer, id);
	if (TYPE(klass) != T_CLASS) {
	    rb_raise(rb_eTypeError, "%s is not a class", name);
	}
	if (RCLASS_RUBY(klass)) {
	    // Only for pure Ruby classes, as Objective-C classes
	    // might be returned from the dynamic resolver.
	    if (rb_class_real(RCLASS_SUPER(klass), true) != super) {
		rb_name_error(id, "%s is already defined", name);
	    }
	    return klass;
	}
    }
    if (!super) {
	rb_warn("no super class for `%s::%s', Object assumed",
		rb_class2name(outer), name);
    }
    klass = rb_define_class_id(id, super);
    rb_set_class_path(klass, outer, name);
    rb_const_set(outer, id, klass);
    rb_class_inherited(super, klass);

    return klass;
}
Exemplo n.º 6
0
/*!
 * Defines a top-level class.
 * \param name   name of the class
 * \param super  a class from which the new class will derive.
 *               NULL means \c Object class.
 * \return the created class
 * \throw TypeError if the constant name \a name is already taken but
 *                  the constant is not a \c Class.
 * \throw NameError if the class is already defined but the class can not
 *                  be reopened because its superclass is not \a super.
 * \post top-level constant named \a name refers the returned class.
 *
 * \note if a class named \a name is already defined and its superclass is
 *       \a super, the function just returns the defined class.
 */
VALUE
rb_define_class(const char *name, VALUE super)
{
    VALUE klass;
    ID id;

    id = rb_intern(name);
    if (rb_const_defined(rb_cObject, id)) {
	klass = rb_const_get(rb_cObject, id);
	if (!RB_TYPE_P(klass, T_CLASS)) {
	    rb_raise(rb_eTypeError, "%s is not a class", name);
	}
	if (rb_class_real(RCLASS_SUPER(klass)) != super) {
	    rb_raise(rb_eTypeError, "superclass mismatch for class %s", name);
	}
	return klass;
    }
    if (!super) {
	rb_warn("no super class for `%s', Object assumed", name);
    }
    klass = rb_define_class_id(id, super);
    rb_vm_add_root_module(id, klass);
    rb_name_class(klass, id);
    rb_const_set(rb_cObject, id, klass);
    rb_class_inherited(super, klass);

    return klass;
}
Exemplo n.º 7
0
void Init_rcovrt() {
  ID id_rcov = rb_intern("Rcov");
  ID id_coverage__ = rb_intern("RCOV__");
  ID id_script_lines__ = rb_intern("SCRIPT_LINES__");
 
  id_cover = rb_intern("COVER");
  
  if(rb_const_defined(rb_cObject, id_rcov)) 
    mRcov = rb_const_get(rb_cObject, id_rcov);
  else
    mRcov = rb_define_module("Rcov");
  
  if(rb_const_defined(mRcov, id_coverage__))
    mRCOV__ = rb_const_get_at(mRcov, id_coverage__);
  else
    mRCOV__ = rb_define_module_under(mRcov, "RCOV__");
  
  if(rb_const_defined(rb_cObject, id_script_lines__))
    oSCRIPT_LINES__ = rb_const_get(rb_cObject, rb_intern("SCRIPT_LINES__"));
  else {
    oSCRIPT_LINES__ = rb_hash_new();
    rb_const_set(rb_cObject, id_script_lines__, oSCRIPT_LINES__);
  }
  
  coverage_hook_set_p = 0;
  
  rb_define_singleton_method(mRCOV__, "install_coverage_hook", cov_install_coverage_hook, 0);
  rb_define_singleton_method(mRCOV__, "remove_coverage_hook",  cov_remove_coverage_hook, 0);
  rb_define_singleton_method(mRCOV__, "generate_coverage_info", cov_generate_coverage_info, 0);
  rb_define_singleton_method(mRCOV__, "reset_coverage", cov_reset_coverage, 0);
  rb_define_singleton_method(mRCOV__, "ABI", cov_ABI, 0);
  
  Init_rcov_callsite();
}
Exemplo n.º 8
0
Arquivo: class.c Projeto: fi8on/ruby
/*!
 * Defines a class under the namespace of \a outer.
 * \param outer  a class which contains the new class.
 * \param id     name of the new class
 * \param super  a class from which the new class will derive.
 *               NULL means \c Object class.
 * \return the created class
 * \throw TypeError if the constant name \a name is already taken but
 *                  the constant is not a \c Class.
 * \throw NameError if the class is already defined but the class can not
 *                  be reopened because its superclass is not \a super.
 * \post top-level constant named \a name refers the returned class.
 *
 * \note if a class named \a name is already defined and its superclass is
 *       \a super, the function just returns the defined class.
 */
VALUE
rb_define_class_id_under(VALUE outer, ID id, VALUE super)
{
    VALUE klass;

    if (rb_const_defined_at(outer, id)) {
	klass = rb_const_get_at(outer, id);
	if (TYPE(klass) != T_CLASS) {
	    rb_raise(rb_eTypeError, "%s is not a class", rb_id2name(id));
	}
	if (rb_class_real(RCLASS_SUPER(klass)) != super) {
	    rb_name_error(id, "%s is already defined", rb_id2name(id));
	}
	return klass;
    }
    if (!super) {
	rb_warn("no super class for `%s::%s', Object assumed",
		rb_class2name(outer), rb_id2name(id));
    }
    klass = rb_define_class_id(id, super);
    rb_set_class_path_string(klass, outer, rb_id2str(id));
    rb_const_set(outer, id, klass);
    rb_class_inherited(super, klass);
    rb_gc_register_mark_object(klass);

    return klass;
}
Exemplo n.º 9
0
VALUE
rb_define_class(const char *name, VALUE super)
{
    VALUE klass;
    ID id;

    id = rb_intern(name);
    if (rb_const_defined(rb_cObject, id)) {
	klass = rb_const_get(rb_cObject, id);
	if (TYPE(klass) != T_CLASS) {
	    rb_raise(rb_eTypeError, "%s is not a class", name);
	}
	if (rb_class_real(RCLASS_SUPER(klass)) != super) {
	    rb_name_error(id, "%s is already defined", name);
	}
	return klass;
    }
    if (!super) {
	rb_warn("no super class for `%s', Object assumed", name);
    }
    klass = rb_define_class_id(id, super);
    st_add_direct(rb_class_tbl, id, klass);
    rb_name_class(klass, id);
    rb_const_set(rb_cObject, id, klass);
    rb_class_inherited(super, klass);

    return klass;
}
Exemplo n.º 10
0
Arquivo: png.c Projeto: ender672/axon
void
Init_PNG()
{
    VALUE mAxon, mPNG, cPNGReader;

    mAxon = rb_define_module("Axon");
    mPNG = rb_define_module_under(mAxon, "PNG");
    rb_const_set(mPNG, rb_intern("LIB_VERSION"), INT2FIX(PNG_LIBPNG_VER));
    rb_define_singleton_method(mPNG, "write", write_png, 2);

    cPNGReader = rb_define_class_under(mPNG, "Reader", rb_cObject);
    rb_define_alloc_func(cPNGReader, allocate);
    rb_define_method(cPNGReader, "initialize", initialize, 1);
    rb_define_method(cPNGReader, "color_model", color_model, 0);
    rb_define_method(cPNGReader, "components", components, 0);
    rb_define_method(cPNGReader, "width", width, 0);
    rb_define_method(cPNGReader, "height", height, 0);
    rb_define_method(cPNGReader, "gets", p_gets, 0);
    rb_define_method(cPNGReader, "lineno", lineno, 0);

    id_GRAYSCALE = rb_intern("GRAYSCALE");
    id_RGB = rb_intern("RGB");
    id_GRAYSCALE = rb_intern("GRAYSCALE_ALPHA");
    id_RGB = rb_intern("RGB_ALPHA");
    id_write = rb_intern("write");
    id_read = rb_intern("read");
    id_gets = rb_intern("gets");
    id_width = rb_intern("width");
    id_height = rb_intern("height");
    id_color_model = rb_intern("color_model");
    id_components = rb_intern("components");
}
Exemplo n.º 11
0
void Init_native()
{
  mNokogiri = rb_const_get(rb_cObject, rb_intern("Nokogiri"));
  mNokogiriXml = rb_const_get(mNokogiri, rb_intern("XML"));
  mNokogiriHtml = rb_const_get(mNokogiri, rb_intern("HTML"));
  mNokogiriXslt = rb_const_get(mNokogiri, rb_intern("XSLT"));
  mNokogiriXmlSax = rb_const_get(mNokogiriXml, rb_intern("SAX"));
  mNokogiriHtmlSax = rb_const_get(mNokogiriHtml, rb_intern("SAX"));

  rb_const_set( mNokogiri,
                rb_intern("LIBXML_VERSION"),
                rb_str_new2(LIBXML_DOTTED_VERSION)
              );

  xmlSetStructuredErrorFunc(NULL, Nokogiri_error_handler);

  init_xml_document();
  init_html_document();
  init_xml_node();
  init_xml_text();
  init_xml_cdata();
  init_xml_node_set();
  init_xml_xpath_context();
  init_xml_xpath();
  init_xml_sax_parser();
  init_xml_reader();
  init_xml_dtd();
  init_html_sax_parser();
  init_xslt_stylesheet();
  init_xml_syntax_error();
}
Exemplo n.º 12
0
VALUE
rb_define_class_under(VALUE outer, const char *name, VALUE super)
{
    VALUE klass;
    ID id;

    id = rb_intern(name);
    if (rb_const_defined_at(outer, id)) {
	klass = rb_const_get_at(outer, id);
	if (TYPE(klass) != T_CLASS) {
	    rb_raise(rb_eTypeError, "%s is not a class", name);
	}
	if (rb_class_real(RCLASS_SUPER(klass)) != super) {
	    rb_name_error(id, "%s is already defined", name);
	}
	return klass;
    }
    if (!super) {
	rb_warn("no super class for `%s::%s', Object assumed",
		rb_class2name(outer), name);
    }
    klass = rb_define_class_id(id, super);
    rb_set_class_path(klass, outer, name);
    rb_const_set(outer, id, klass);
    rb_class_inherited(super, klass);

    return klass;
}
Exemplo n.º 13
0
void Init_request_parse(VALUE nyara) {
  str_accept = rb_enc_str_new("Accept", strlen("Accept"), u8_encoding);
  rb_gc_register_mark_object(str_accept);
  method_override_key = rb_enc_str_new("_method", strlen("_method"), u8_encoding);
  OBJ_FREEZE(method_override_key);
  rb_const_set(nyara, rb_intern("METHOD_OVERRIDE_KEY"), method_override_key);
  nyara_http_methods = rb_const_get(nyara, rb_intern("HTTP_METHODS"));
}
Exemplo n.º 14
0
/*
 *  Document-class: Rugged::Index
 *
 *  == Index Entries
 *
 *  Index entries are represented as Hash instances with the following key/value pairs:
 *
 *  path: ::
 *    The entry's path in the index.
 *
 *  oid: ::
 *    The oid of the entry's git object (blob / tree).
 *
 *  dev: ::
 *    The device for the index entry.
 *
 *  ino: ::
 *    The inode for the index entry.
 *
 *  mode: ::
 *    The current permissions of the index entry.
 *
 *  gid: ::
 *    Group ID of the index entry's owner.
 *
 *  uid: ::
 *    User ID of the index entry's owner.
 *
 *  file_size: ::
 *    The index entry's size, in bytes.
 *
 *  valid: ::
 *    +true+ if the index entry is valid, +false+ otherwise.
 *
 *  stage: ::
 *    The current stage of the index entry.
 *
 *  mtime: ::
 *    A Time instance representing the index entry's time of last modification.
 *
 *  mtime: ::
 *    A Time instance representing the index entry's time of last status change
 *    (ie. change of owner, group, mode, etc.).
 */
void Init_rugged_index(void)
{
	/*
	 * Index
	 */
	rb_cRuggedIndex = rb_define_class_under(rb_mRugged, "Index", rb_cObject);
	rb_define_singleton_method(rb_cRuggedIndex, "new", rb_git_index_new, -1);

	rb_define_method(rb_cRuggedIndex, "count", rb_git_index_count, 0);
	rb_define_method(rb_cRuggedIndex, "reload", rb_git_index_read, 0);
	rb_define_method(rb_cRuggedIndex, "clear", rb_git_index_clear, 0);
	rb_define_method(rb_cRuggedIndex, "write", rb_git_index_write, 0);
	rb_define_method(rb_cRuggedIndex, "get", rb_git_index_get, -1);
	rb_define_method(rb_cRuggedIndex, "[]", rb_git_index_get, -1);
	rb_define_method(rb_cRuggedIndex, "each", rb_git_index_each, 0);
	rb_define_private_method(rb_cRuggedIndex, "diff_tree_to_index", rb_git_diff_tree_to_index, 2);
	rb_define_private_method(rb_cRuggedIndex, "diff_index_to_workdir", rb_git_diff_index_to_workdir, 1);

	rb_define_method(rb_cRuggedIndex, "conflicts?", rb_git_index_conflicts_p, 0);
	rb_define_method(rb_cRuggedIndex, "conflicts", rb_git_index_conflicts, 0);
	rb_define_method(rb_cRuggedIndex, "conflict_get", rb_git_conflict_get, 1);
	rb_define_method(rb_cRuggedIndex, "conflict_add", rb_git_conflict_add, 1);
	rb_define_method(rb_cRuggedIndex, "conflict_remove", rb_git_conflict_remove, 1);
	rb_define_method(rb_cRuggedIndex, "conflict_cleanup", rb_git_conflict_cleanup, 0);

	rb_define_method(rb_cRuggedIndex, "merge_file", rb_git_merge_file, -1);

	rb_define_method(rb_cRuggedIndex, "add", rb_git_index_add, 1);
	rb_define_method(rb_cRuggedIndex, "update", rb_git_index_add, 1);
	rb_define_method(rb_cRuggedIndex, "<<", rb_git_index_add, 1);

	rb_define_method(rb_cRuggedIndex, "remove", rb_git_index_remove, -1);
	rb_define_method(rb_cRuggedIndex, "remove_dir", rb_git_index_remove_directory, -1);

	rb_define_method(rb_cRuggedIndex, "add_all", rb_git_index_add_all, -1);
	rb_define_method(rb_cRuggedIndex, "update_all", rb_git_index_update_all, -1);
	rb_define_method(rb_cRuggedIndex, "remove_all", rb_git_index_remove_all, -1);

	rb_define_method(rb_cRuggedIndex, "write_tree", rb_git_index_writetree, -1);
	rb_define_method(rb_cRuggedIndex, "read_tree", rb_git_index_readtree, 1);

	rb_const_set(rb_cRuggedIndex, rb_intern("ENTRY_FLAGS_STAGE"), INT2FIX(GIT_IDXENTRY_STAGEMASK));
	rb_const_set(rb_cRuggedIndex, rb_intern("ENTRY_FLAGS_STAGE_SHIFT"), INT2FIX(GIT_IDXENTRY_STAGESHIFT));
	rb_const_set(rb_cRuggedIndex, rb_intern("ENTRY_FLAGS_VALID"), INT2FIX(GIT_IDXENTRY_VALID));
}
Exemplo n.º 15
0
static VALUE
boot_defclass(const char *name, VALUE super)
{
    VALUE obj = rb_class_boot(super);
    ID id = rb_intern(name);

    rb_name_class(obj, id);
    rb_const_set((rb_cObject ? rb_cObject : obj), id, obj);
    return obj;
}
Exemplo n.º 16
0
void
Init_Symbol(void)
{
    // rb_cSymbol is defined earlier in Init_PreVM().
    rb_set_class_path(rb_cSymbol, rb_cObject, "Symbol");
    rb_const_set(rb_cObject, rb_intern("Symbol"), rb_cSymbol);

    rb_undef_alloc_func(rb_cSymbol);
    rb_undef_method(*(VALUE *)rb_cSymbol, "new");
    rb_objc_define_method(*(VALUE *)rb_cSymbol, "all_symbols",
	    rsym_all_symbols, 0);

    // Undefine methods defined on NSString.
    rb_undef_method(rb_cSymbol, "to_i");
    rb_undef_method(rb_cSymbol, "to_f");
    rb_undef_method(rb_cSymbol, "to_r");
    rb_undef_method(rb_cSymbol, "to_str");

    rb_objc_define_method(rb_cSymbol, "==", rsym_equal, 1);
    rb_objc_define_method(rb_cSymbol, "<=>", rsym_cmp, 1);
    rb_objc_define_method(rb_cSymbol, "casecmp", rsym_casecmp, 1);
    rb_objc_define_method(rb_cSymbol, "eql?", rsym_equal, 1);
    rb_objc_define_method(rb_cSymbol, "inspect", rsym_inspect, 0);
    rb_objc_define_method(rb_cSymbol, "to_proc", rsym_to_proc, 0);
    rb_objc_define_method(rb_cSymbol, "to_s", rsym_to_s, 0);
    rb_objc_define_method(rb_cSymbol, "id2name", rsym_to_s, 0);
    rb_objc_define_method(rb_cSymbol, "description", rsym_to_s, 0);
    rb_objc_define_method(rb_cSymbol, "intern", rsym_to_sym, 0);
    rb_objc_define_method(rb_cSymbol, "to_sym", rsym_to_sym, 0);
    rb_objc_define_method(rb_cSymbol, "empty?", rsym_empty, 0);
    rb_objc_define_method(rb_cSymbol, "[]", rsym_aref, -1);
    rb_objc_define_method(rb_cSymbol, "=~", rsym_match, 1);
    rb_objc_define_method(rb_cSymbol, "match", rsym_match, 1);
    rb_objc_define_method(rb_cSymbol, "upcase", rsym_upcase, 0);
    rb_objc_define_method(rb_cSymbol, "downcase", rsym_downcase, 0);
    rb_objc_define_method(rb_cSymbol, "swapcase", rsym_swapcase, 0);
    rb_objc_define_method(rb_cSymbol, "capitalize", rsym_capitalize, 0);
    rb_objc_define_method(rb_cSymbol, "succ", rsym_succ, 0);
    rb_objc_define_method(rb_cSymbol, "next", rsym_succ, 0);

    // Cocoa primitives.
    rb_objc_install_method2((Class)rb_cSymbol, "copy",
	    (IMP)rsym_imp_copy);
    rb_objc_install_method2((Class)rb_cSymbol, "length",
	    (IMP)rsym_imp_length);
    rb_objc_install_method2((Class)rb_cSymbol, "characterAtIndex:",
	    (IMP)rsym_imp_characterAtIndex);
    rb_objc_install_method2((Class)rb_cSymbol, "encodeWithCoder:",
	    (IMP)rsym_imp_encodeWithCoder);
    rb_objc_install_method2((Class)rb_cSymbol, "initWithCoder:",
	    (IMP)rsym_imp_initWithCoder);
    rb_objc_install_method2((Class)rb_cSymbol, "classForKeyedArchiver",
	    (IMP)rsym_imp_classForKeyedArchiver);
}
Exemplo n.º 17
0
Arquivo: class.c Projeto: fi8on/ruby
static VALUE
boot_defclass(const char *name, VALUE super)
{
    extern st_table *rb_class_tbl;
    VALUE obj = rb_class_boot(super);
    ID id = rb_intern(name);

    rb_name_class(obj, id);
    st_add_direct(rb_class_tbl, id, obj);
    rb_const_set((rb_cObject ? rb_cObject : obj), id, obj);
    return obj;
}
Exemplo n.º 18
0
/*
 * Initialize methods for BufferedFile
 */
void Init_buffered_file(void)
{
  id_ivar_buffer = rb_intern("@buffer");
  id_ivar_buffer_index = rb_intern("@buffer_index");
  id_method_clear = rb_intern("clear");
  id_method_slice_bang = rb_intern("slice!");
  id_method_to_s = rb_intern("to_s");
  id_method_pos = rb_intern("pos");
  id_const_BUFFER_SIZE = rb_intern("BUFFER_SIZE");
  id_const_ALL_RANGE = rb_intern("ALL_RANGE");
  BUFFERED_FILE_SEEK_SET = rb_const_get(rb_cIO, rb_intern("SEEK_SET"));
  BUFFERED_FILE_SEEK_CUR = rb_const_get(rb_cIO, rb_intern("SEEK_CUR"));

  mCosmos = rb_define_module("Cosmos");
  cBufferedFile = rb_define_class_under(mCosmos, "BufferedFile", rb_cFile);
  rb_const_set(cBufferedFile, id_const_BUFFER_SIZE, INT2FIX(BUFFER_SIZE));
  rb_const_set(cBufferedFile, id_const_ALL_RANGE, rb_range_new(INT2FIX(0), INT2FIX(-1), Qfalse));

  rb_define_method(cBufferedFile, "initialize", buffered_file_initialize, -1);
  rb_define_method(cBufferedFile, "read", buffered_file_read, 1);
  rb_define_method(cBufferedFile, "seek", buffered_file_seek, -1);
  rb_define_method(cBufferedFile, "pos", buffered_file_pos, 0);
}
Exemplo n.º 19
0
void
Init_class_hierarchy(void)
{
    rb_cBasicObject = boot_defclass("BasicObject", 0);
    rb_cObject = boot_defclass("Object", rb_cBasicObject);
    rb_cModule = boot_defclass("Module", rb_cObject);
    rb_cClass =  boot_defclass("Class",  rb_cModule);

    rb_const_set(rb_cObject, rb_intern("BasicObject"), rb_cBasicObject);
    RBASIC_SET_CLASS(rb_cClass, rb_cClass);
    RBASIC_SET_CLASS(rb_cModule, rb_cClass);
    RBASIC_SET_CLASS(rb_cObject, rb_cClass);
    RBASIC_SET_CLASS(rb_cBasicObject, rb_cClass);
}
Exemplo n.º 20
0
PRIMITIVE void 
vm_set_const(VALUE outer, ID id, VALUE obj, unsigned char dynamic_class, void *outer_stack_p)
{
    if (dynamic_class) {
	rb_vm_outer_t *o = (rb_vm_outer_t *)outer_stack_p;
	while (o != NULL && o->pushed_by_eval) {
	    o = o->outer;
	}
	if (o != NULL) {
	    outer = (VALUE)o->klass;
	}
    }
    rb_const_set(outer, id, obj);
}
Exemplo n.º 21
0
void Init_ExtSprite() {
  VALUE cOldSprite = rb_const_get(rb_cObject, rb_intern("Sprite"));
  VALUE cSprite = rb_define_class_under(mExtRgss, "Sprite", rb_cObject);
  rb_const_set(rb_cObject, rb_intern("OldSprite"), cOldSprite);
  rb_const_set(rb_cObject, rb_intern("Sprite"), cSprite);

  rb_define_alloc_func(cSprite, Sprite_s_alloc);
  rb_define_method(cSprite, "initialize", Sprite_initialize, -1);
  rb_define_method(cSprite, "bitmap=", Sprite_bitmap_set, 1);
  rb_define_method(cSprite, "bitmap", Sprite_bitmap, 0);
  rb_define_method(cSprite, "dispose", Sprite_dispose, 0);
  rb_define_method(cSprite, "src_rect=", Sprite_src_rect_set, 1);
  rb_define_method(cSprite, "src_rect", Sprite_src_rect, 0);
  rb_define_method(cSprite, "x=", Sprite_x_set, 1);
  rb_define_method(cSprite, "x", Sprite_x, 0);
  rb_define_method(cSprite, "y=", Sprite_y_set, 1);
  rb_define_method(cSprite, "y", Sprite_y, 0);
  rb_define_method(cSprite, "ox=", Sprite_ox_set, 1);
  rb_define_method(cSprite, "ox", Sprite_ox, 0);
  rb_define_method(cSprite, "oy=", Sprite_oy_set, 1);
  rb_define_method(cSprite, "oy", Sprite_oy, 0);
  rb_define_method(cSprite, "visible=", Sprite_visible_set, 1);
  rb_define_method(cSprite, "visible", Sprite_visible, 0);
}
Exemplo n.º 22
0
void Init_with_ext()
{
  VALUE super = rb_class_boot(0);
  rb_cCallWith = rb_class_boot(super);
  rb_name_class(rb_cCallWith, rb_intern("CallWith"));
  rb_const_set(rb_cObject, rb_intern("CallWith"), rb_cCallWith);
  rb_global_variable(&rb_cCallWith);

  rb_undef_alloc_func(rb_cCallWith);
  rb_define_singleton_method(rb_cCallWith, "create", callwith_s_create, 2);
  rb_define_method(rb_cCallWith, "__instance_eval__", rb_obj_instance_eval, -1);
  rb_define_method(rb_cCallWith, "__callwith__obj__", callwith_obj, 0);
  rb_define_method(rb_cCallWith, "__callwith__self_obj__", callwith_self_obj, 0);
  rb_define_method(rb_cCallWith, "__callwith__cleanup__", callwith_cleanup, 0);
}
Exemplo n.º 23
0
void
Init_Encoding(void)
{
    // rb_cEncoding is defined earlier in Init_PreVM().
    rb_set_class_path(rb_cEncoding, rb_cObject, "Encoding");
    rb_const_set(rb_cObject, rb_intern("Encoding"), rb_cEncoding);

    rb_undef_alloc_func(rb_cEncoding);

    rb_objc_define_method(rb_cEncoding, "to_s", mr_enc_name, 0);
    rb_objc_define_method(rb_cEncoding, "inspect", mr_enc_inspect, 0);
    rb_objc_define_method(rb_cEncoding, "name", mr_enc_name, 0);
    rb_objc_define_method(rb_cEncoding, "names", mr_enc_names, 0);
    rb_objc_define_method(rb_cEncoding, "dummy?", mr_enc_dummy_p, 0);
    rb_objc_define_method(rb_cEncoding, "ascii_compatible?",
	    mr_enc_ascii_compatible_p, 0);
    rb_objc_define_method(*(VALUE *)rb_cEncoding, "list", mr_enc_s_list, 0);
    rb_objc_define_method(*(VALUE *)rb_cEncoding, "name_list",
	    mr_enc_s_name_list, 0);
    rb_objc_define_method(*(VALUE *)rb_cEncoding, "aliases",
	    mr_enc_s_aliases, 0);
    rb_objc_define_method(*(VALUE *)rb_cEncoding, "find", mr_enc_s_find, 1);
    rb_objc_define_method(*(VALUE *)rb_cEncoding, "compatible?",
	    mr_enc_s_is_compatible, 2); // in string.c

    //rb_define_method(rb_cEncoding, "_dump", enc_dump, -1);
    //rb_define_singleton_method(rb_cEncoding, "_load", enc_load, 1);

    rb_objc_define_method(*(VALUE *)rb_cEncoding, "default_external",
	    mr_enc_s_default_external, 0);
    rb_objc_define_method(*(VALUE *)rb_cEncoding, "default_external=",
	    mr_enc_set_default_external, 1);
    rb_objc_define_method(*(VALUE *)rb_cEncoding, "default_internal",
	    mr_enc_s_default_internal, 0);
    rb_objc_define_method(*(VALUE *)rb_cEncoding, "default_internal=",
	    mr_enc_set_default_internal, 1);
    //rb_define_singleton_method(rb_cEncoding, "locale_charmap", rb_locale_charmap, 0);

    // Create constants.
    for (unsigned int i = 0; i < ENCODINGS_COUNT; i++) {
	rb_encoding_t *enc = rb_encodings[i];
	define_encoding_constant(enc->public_name, enc);
	for (unsigned int j = 0; j < enc->aliases_count; j++) {
	    define_encoding_constant(enc->aliases[j], enc);
	}
    }
}
Exemplo n.º 24
0
void
Init_class_hierarchy(void)
{
    id_attached = rb_intern("__attached__");

    rb_cBasicObject = boot_defclass("BasicObject", 0);
    rb_cObject = boot_defclass("Object", rb_cBasicObject);
    rb_cModule = boot_defclass("Module", rb_cObject);
    rb_cClass =  boot_defclass("Class",  rb_cModule);

    rb_const_set(rb_cObject, rb_intern("BasicObject"), rb_cBasicObject);
    RBASIC(rb_cClass)->klass
	= RBASIC(rb_cModule)->klass
	= RBASIC(rb_cObject)->klass
	= RBASIC(rb_cBasicObject)->klass
	= rb_cClass;
}
Exemplo n.º 25
0
VALUE
rb_define_module_under(VALUE outer, const char *name)
{
    ID id = rb_intern(name);
    if (rb_const_defined_at(outer, id)) {
	VALUE module = rb_const_get_at(outer, id);
	if (TYPE(module) == T_MODULE) {
	    return module;
	}
	rb_raise(rb_eTypeError, "%s::%s:%s is not a module",
		 rb_class2name(outer), name, rb_obj_classname(module));
    }
    VALUE module = rb_define_module_id(id);
    rb_const_set(outer, id, module);
    rb_set_class_path(module, outer, name);
    return module;
}
Exemplo n.º 26
0
/*
 * Initialize all Packet methods
 */
void Init_packet (void)
{
  Init_structure();

  id_method_class = rb_intern("class");
  id_method_target_name_equals = rb_intern("target_name=");
  id_method_packet_name_equals = rb_intern("packet_name=");
  id_method_description_equals = rb_intern("description=");
  id_method_upcase = rb_intern("upcase");
  id_method_clone = rb_intern("clone");

  id_const_ASCII_8BIT_STRING = rb_intern("ASCII_8BIT_STRING");

  id_ivar_id_items = rb_intern("@id_items");
  id_ivar_id_value = rb_intern("@id_value");
  id_ivar_received_time = rb_intern("@received_time");
  id_ivar_received_count = rb_intern("@received_count");
  id_ivar_hazardous = rb_intern("@hazardous");
  id_ivar_hazardous_description = rb_intern("@hazardous_description");
  id_ivar_given_values = rb_intern("@given_values");
  id_ivar_limits_items = rb_intern("@limits_items");
  id_ivar_processors = rb_intern("@processors");
  id_ivar_stale = rb_intern("@stale");
  id_ivar_limits_change_callback = rb_intern("@limits_change_callback");
  id_ivar_read_conversion_cache = rb_intern("@read_conversion_cache");
  id_ivar_raw = rb_intern("@raw");
  id_ivar_messages_disabled = rb_intern("@messages_disabled");
  id_ivar_meta = rb_intern("@meta");
  id_ivar_hidden = rb_intern("@hidden");
  id_ivar_disabled = rb_intern("@disabled");
  id_ivar_target_name = rb_intern("@target_name");
  id_ivar_packet_name = rb_intern("@packet_name");
  id_ivar_description = rb_intern("@description");

  cPacket = rb_define_class_under(mCosmos, "Packet", cStructure);
  rb_const_set(cPacket, id_const_ASCII_8BIT_STRING, ASCII_8BIT_STRING);
  rb_define_method(cPacket, "initialize", packet_initialize, -1);
  rb_define_method(cPacket, "identify?", identify, 1);
  rb_define_method(cPacket, "packet_name=", packet_name_equals, 1);
  rb_define_method(cPacket, "target_name=", target_name_equals, 1);
  rb_define_method(cPacket, "description=", description_equals, 1);
  rb_define_method(cPacket, "received_time=", received_time_equals, 1);
  rb_define_method(cPacket, "received_count=", received_count_equals, 1);

  cPacketItem = rb_define_class_under(mCosmos, "PacketItem", cStructureItem);
}
Exemplo n.º 27
0
Arquivo: world.c Projeto: Klokka/Lumi
lumi_code
lumi_init(LUMI_INIT_ARGS)
{
#ifdef LUMI_SIGNAL
  signal(SIGINT,  lumi_sigint);
  signal(SIGQUIT, lumi_sigint);
#endif
  lumi_ruby_embed();
  lumi_ruby_init();
  lumi_world = lumi_world_alloc();
#ifdef LUMI_WIN32
  lumi_world->os.instance = inst;
  lumi_world->os.style = style;
#endif
  lumi_native_init();
  rb_const_set(cLumi, rb_intern("FONTS"), lumi_font_list());
  return LUMI_OK;
}
Exemplo n.º 28
0
shoes_code
shoes_init(SHOES_INIT_ARGS)
{
#ifdef SHOES_SIGNAL
    signal(SIGINT,  shoes_sigint);
    signal(SIGQUIT, shoes_sigint);
#endif
    shoes_ruby_embed();
    shoes_ruby_init();
    shoes_world = shoes_world_alloc();
#ifdef SHOES_WIN32
    shoes_world->os.instance = inst;
    shoes_world->os.style = style;
#endif
    shoes_native_init();
    rb_const_set(cShoes, rb_intern("FONTS"), shoes_font_list());
    return SHOES_OK;
}
Exemplo n.º 29
0
VALUE
rb_define_module(const char *name)
{
    VALUE module;
    ID id;

    id = rb_intern(name);
    if (rb_const_defined(rb_cObject, id)) {
	module = rb_const_get(rb_cObject, id);
	if (TYPE(module) == T_MODULE)
	    return module;
	rb_raise(rb_eTypeError, "%s is not a module", rb_obj_classname(module));
    }
    module = rb_define_module_id(id);
    st_add_direct(rb_class_tbl, id, module);
    rb_const_set(rb_cObject, id, module);

    return module;
}
Exemplo n.º 30
0
Arquivo: class.c Projeto: fi8on/ruby
VALUE
rb_define_module_id_under(VALUE outer, ID id)
{
    VALUE module;

    if (rb_const_defined_at(outer, id)) {
	module = rb_const_get_at(outer, id);
	if (TYPE(module) == T_MODULE)
	    return module;
	rb_raise(rb_eTypeError, "%s::%s is not a module",
		 rb_class2name(outer), rb_obj_classname(module));
    }
    module = rb_define_module_id(id);
    rb_const_set(outer, id, module);
    rb_set_class_path_string(module, outer, rb_id2str(id));
    rb_gc_register_mark_object(module);

    return module;
}