Exemplo n.º 1
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.º 2
0
int load_constants() {
	if(!rb_const_defined(rb_cObject, id_GPS)) return 0;
	mGPS = rb_const_get(rb_cObject, rb_intern("GPS"));
	if(!rb_const_defined(mGPS, id_Latitude)) return 0;
	cLatitude = rb_const_get(mGPS, rb_intern("Latitude"));
	if(!rb_const_defined(mGPS, id_Longitude)) return 0;
	cLongitude = rb_const_get(mGPS, rb_intern("Longitude"));
	return 1;
}
Exemplo n.º 3
0
static VALUE
handler_for_tag(rb_yaml_parser_t *parser, yaml_char_t *tag)
{
    if (tag == NULL) {
	return Qnil;
    }

    const void *h =
	CFDictionaryGetValue(RYAMLResolver(parser->resolver)->tags,
		(const void *)rb_intern((const char *)tag));

    if (h != NULL) {
	return (VALUE)h;
    }

    // Dynamic handler, only for pure objects.
    VALUE outer = Qnil;
    if (strncmp((const char *)tag, "!ruby/object:", 13) == 0) {
	outer = rb_cObject;
    }
    else if (strncmp((const char *)tag, "!ruby/struct:", 13) == 0) {
	outer = rb_cStruct;
    }
    if (outer != Qnil) {
	char *path = (char *)tag + 13;
	assert(strlen(path) < 100);

	char *p;
	while ((p = strstr(path, "::")) != NULL) {	    
	    char buf[100];
	    strncpy(buf, path, p - path);
	    buf[p - path] = '\0';
	    ID id = rb_intern(buf);
	    if (rb_const_defined(outer, id)) {
		outer = rb_const_get(outer, id);
	    }
	    else {
		return Qnil;
	    }
	    path = p + 2;
	}

	ID pathid = rb_intern(path);
	if (rb_const_defined(outer, pathid)) {
	    return rb_const_get(outer, pathid);
	}
    }
    return Qnil;
}
Exemplo n.º 4
0
void Init_instruction(void)
{
#ifdef RUBY_VM
  VALUE rb_cRubyVM;
  VALUE rb_cInstruction;

  if(!rb_const_defined(rb_cObject, rb_intern("RubyVM")))
  {
    rb_define_const(
        rb_cObject,
        "RubyVM",
        rb_const_get(rb_cObject, rb_intern("VM")));
  }

  rb_cRubyVM = rb_define_class("RubyVM", rb_cObject);

  rb_cInstruction = rb_define_class_under(rb_cRubyVM, "Instruction", rb_cObject);
  rb_define_method(rb_cInstruction, "initialize", instruction_initialize, -1);
  rb_define_method(rb_cInstruction, "operands", instruction_operands, 0);
  rb_undef_method(rb_cInstruction, "new");

  define_instruction_subclasses(rb_cInstruction);

  /* Silence compiler warnings about unused static functions */
  insn_name(0);
  insn_op_type(0, 0);
  insn_op_types(0);
#endif
}
Exemplo n.º 5
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.º 6
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.º 7
0
VALUE
rb_path2class(const char *path)
{
    const char *pbeg, *p;
    ID id;
    VALUE c = rb_cObject;

    if (path[0] == '#') {
	rb_raise(rb_eArgError, "can't retrieve anonymous class %s", path);
    }
    pbeg = p = path;
    while (*p) {
	while (*p && *p != ':') p++;
	id = rb_intern2(pbeg, p-pbeg);
	if (p[0] == ':') {
	    if (p[1] != ':') goto undefined_class;
	    p += 2;
	    pbeg = p;
	}
	if (!rb_const_defined(c, id)) {
	  undefined_class:
	    rb_raise(rb_eArgError, "undefined class/module %.*s", (int)(p-path), path);
	}
	c = rb_const_get_at(c, id);
	switch (TYPE(c)) {
	  case T_MODULE:
	  case T_CLASS:
	    break;
	  default:
	    rb_raise(rb_eTypeError, "%s does not refer class/module", path);
	}
    }

    return c;
}
Exemplo n.º 8
0
void Init_constants(void)
{
#ifdef RUBY_VM
  VALUE rb_cRubyVM;

  if(!rb_const_defined(rb_cObject, rb_intern("RubyVM")))
  {
    rb_define_const(
        rb_cObject,
        "RubyVM",
        rb_const_get(rb_cObject, rb_intern("VM")));
  }

  rb_cRubyVM = rb_define_class("RubyVM", rb_cObject);
  rb_define_const(rb_cRubyVM, "CALL_ARGS_SPLAT_BIT", INT2NUM(VM_CALL_ARGS_SPLAT_BIT));
  rb_define_const(rb_cRubyVM, "CALL_ARGS_BLOCKARG_BIT", INT2NUM(VM_CALL_ARGS_BLOCKARG_BIT));
  rb_define_const(rb_cRubyVM, "CALL_FCALL_BIT", INT2NUM(VM_CALL_FCALL_BIT));
  rb_define_const(rb_cRubyVM, "CALL_VCALL_BIT", INT2NUM(VM_CALL_VCALL_BIT));
  rb_define_const(rb_cRubyVM, "CALL_TAILCALL_BIT", INT2NUM(VM_CALL_TAILCALL_BIT));
  rb_define_const(rb_cRubyVM, "CALL_TAILRECURSION_BIT", INT2NUM(VM_CALL_TAILRECURSION_BIT));
  rb_define_const(rb_cRubyVM, "CALL_SUPER_BIT", INT2NUM(VM_CALL_SUPER_BIT));
#ifdef HAVE_RUBY_CALL_SEND_BIT
  rb_define_const(rb_cRubyVM, "CALL_SEND_BIT", INT2NUM(VM_CALL_SEND_BIT));
#endif
  rb_define_const(rb_cRubyVM, "SPECIAL_OBJECT_VMCORE", INT2NUM(VM_SPECIAL_OBJECT_VMCORE));
  rb_define_const(rb_cRubyVM, "SPECIAL_OBJECT_CBASE", INT2NUM(VM_SPECIAL_OBJECT_CBASE));
#endif
}
Exemplo n.º 9
0
/*
 * call-seq:
 *   inspect -> String
 * 
 * Human-readable description. 
 * ===Return value
 * String
*/
VALUE _inspect(VALUE self)
{
	if(wrap< RubyWindowHolder* >(self)->window==NULL){
		VALUE array[2];
		array[0]=rb_str_new2("#<%s:(destroyed)>");
		array[1]=rb_class_of(self);
		return rb_f_sprintf(2,array);
	}else{
		if(rb_const_defined(rb_class_of(self),rb_intern("WidgetTypeName")))
			if(_self->getType() == wrap<CEGUI::String>(rb_const_get(rb_class_of(self),rb_intern("WidgetTypeName"))))
			{
				VALUE array[3];
				array[0]=rb_str_new2("#<%s:%s>");
				array[1]=rb_class_of(self);
				array[2]=rb_funcall(self,rb_intern("name"),0);
				return rb_f_sprintf(3,array);
			}
		VALUE array[4];
		array[0]=rb_str_new2("#<%s(%s):%s>");
		array[1]=rb_class_of(self);
		array[2]=_getType(self);
		array[3]=rb_funcall(self,rb_intern("name"),0);
		return rb_f_sprintf(4,array);
	}
}
Exemplo n.º 10
0
void init_kgio_tryopen(void)
{
	VALUE mKgio = rb_define_module("Kgio");
	VALUE mPipeMethods = rb_const_get(mKgio, rb_intern("PipeMethods"));
	VALUE cFile;
	VALUE tmp;
	VALUE *ptr;
	long len;

	id_path = rb_intern("path");
	id_for_fd = rb_intern("for_fd");
	id_to_path = rb_intern("to_path");

	/*
	 * Document-class: Kgio::File
	 *
	 * This subclass of the core File class adds the "tryopen" singleton
	 * method for opening files.  A single "tryopen" and check for the
	 * return value may be used to avoid unnecessary stat(2) syscalls
	 * or File.open exceptions when checking for the existence of a file
	 * and opening it.
	 */
	cFile = rb_define_class_under(mKgio, "File", rb_cFile);
	rb_define_singleton_method(cFile, "tryopen", s_tryopen, -1);
	rb_include_module(cFile, mPipeMethods);

	if (!rb_funcall(cFile, rb_intern("method_defined?"), 1,
	                ID2SYM(id_to_path)))
		rb_define_alias(cFile, "to_path", "path");

	errno2sym = st_init_numtable();
	tmp = rb_funcall(rb_mErrno, rb_intern("constants"), 0);
	ptr = RARRAY_PTR(tmp);
	len = RARRAY_LEN(tmp);
	for (; --len >= 0; ptr++) {
		VALUE error;
		ID const_id;

		switch (TYPE(*ptr)) {
		case T_SYMBOL: const_id = SYM2ID(*ptr); break;
		case T_STRING: const_id = rb_intern(RSTRING_PTR(*ptr)); break;
		default: rb_bug("constant not a symbol or string");
		}

		error = rb_const_get(rb_mErrno, const_id);
		if ((TYPE(error) != T_CLASS) ||
		    !rb_const_defined(error, rb_intern("Errno")))
			continue;

		error = rb_const_get(error, rb_intern("Errno"));
		switch (TYPE(error)) {
		case T_FIXNUM:
		case T_BIGNUM:
			st_insert(errno2sym, (st_data_t)NUM2INT(error),
			          ID2SYM(const_id));
		}
	}
}
Exemplo n.º 11
0
Arquivo: cparse.c Projeto: hsbt/racc
void
Init_cparse(void)
{
    VALUE Racc, Parser;
    ID id_racc = rb_intern("Racc");

    if (rb_const_defined(rb_cObject, id_racc)) {
        Racc = rb_const_get(rb_cObject, id_racc);
        Parser = rb_const_get_at(Racc, rb_intern("Parser"));
    }
    else {
        Racc = rb_define_module("Racc");
        Parser = rb_define_class_under(Racc, "Parser", rb_cObject);
    }

    rb_define_method(Parser, "initialize", (VALUE(*)(ANYARGS))initialize, 0);

    rb_define_private_method(Parser, "_racc_do_parse_c", racc_cparse, 0);
    rb_define_private_method(Parser, "_racc_yyparse_c", racc_yyparse, 2);
    rb_define_const(Parser, "Racc_Runtime_Core_Version_C",
                    rb_str_new2(RACC_VERSION));
    rb_define_const(Parser, "Racc_Runtime_Core_Id_C",
        rb_str_new2("$originalId: cparse.c,v 1.8 2006/07/06 11:39:46 aamine Exp $"));

    CparseParams = rb_define_class_under(Racc, "CparseParams", rb_cObject);

    RaccBug = rb_eRuntimeError;

    id_yydebug      = rb_intern("@yydebug");
    id_nexttoken    = rb_intern("next_token");
    id_onerror      = rb_intern("on_error");
    id_noreduce     = rb_intern("_reduce_none");
    id_errstatus    = rb_intern("@racc_error_status");

    id_d_shift       = rb_intern("racc_shift");
    id_d_reduce      = rb_intern("racc_reduce");
    id_d_accept      = rb_intern("racc_accept");
    id_d_read_token  = rb_intern("racc_read_token");
    id_d_next_state  = rb_intern("racc_next_state");
    id_d_e_pop       = rb_intern("racc_e_pop");

    id_action_table   = rb_intern("@action_table");
    id_action_check   = rb_intern("@action_check");
    id_action_default = rb_intern("@action_default");
    id_action_pointer = rb_intern("@action_pointer");
    id_goto_table     = rb_intern("@goto_table");
    id_goto_check     = rb_intern("@goto_check");
    id_goto_default   = rb_intern("@goto_default");
    id_goto_pointer   = rb_intern("@goto_pointer");
    id_nt_base        = rb_intern("@nt_base");
    id_reduce_table   = rb_intern("@reduce_table");
    id_token_table    = rb_intern("@token_table");
    id_shift_n        = rb_intern("@shift_n");
    id_reduce_n       = rb_intern("@reduce_n");
    id_use_result     = rb_intern("@use_result");
}
Exemplo n.º 12
0
VALUE Cegui_method_missing(int argc,VALUE *argv,VALUE self)
{
    VALUE methID,args;
    rb_scan_args(argc, argv, "1*",&methID,&args);
    if(rb_const_defined(self,SYM2ID(methID))) {
        return rb_funcall2(rb_const_get(self,SYM2ID(methID)),rb_intern("new"),argc-1,RARRAY_PTR(args));
    } else {
        return rb_call_super(argc,argv);
    }
}
Exemplo n.º 13
0
void init_StringScanner_UTF8() {
  ID intern_string_scanner = rb_intern("StringScanner");
  VALUE rb_cStringScanner, rb_cStringScanner_UTF8;

  if (!rb_const_defined(rb_cObject, intern_string_scanner)) {
    rb_require("strscan");
  }
  rb_cStringScanner = rb_const_get(rb_cObject, intern_string_scanner);
  rb_cStringScanner_UTF8 = rb_define_class_under(rb_cStringScanner, "UTF8", rb_cStringScanner);

  rb_define_method(rb_cStringScanner_UTF8, "getch", rb_cStringScanner_UTF8_getch, 0);
}
Exemplo n.º 14
0
void Init_charguess()
{
  ID id;
  
  id = rb_intern("CharGuess");
  if (rb_const_defined(rb_cObject, id)) {
    mCharGuess = rb_const_get(rb_cObject, id);
  } else {
    mCharGuess = rb_define_module("CharGuess");
  }
  rb_define_singleton_method(mCharGuess, "guess", cg_s_guess, 1);
}
Exemplo n.º 15
0
void
pg_coder_init_decoder( VALUE self )
{
	t_pg_coder *this = DATA_PTR( self );
	VALUE klass = rb_class_of(self);
	this->enc_func = NULL;
	if( rb_const_defined( klass, s_id_CFUNC ) ){
		VALUE cfunc = rb_const_get( klass, s_id_CFUNC );
		this->dec_func = DATA_PTR(cfunc);
	} else {
		this->dec_func = NULL;
	}
	this->coder_obj = self;
	this->oid = 0;
	this->format = 0;
	rb_iv_set( self, "@name", Qnil );
}
Exemplo n.º 16
0
long double 
rbffi_num2longdouble(VALUE value)
{
    if (TYPE(value) == T_FLOAT) {
        return rb_num2dbl(value);
    }
    
    if (!RTEST(rb_cBigDecimal) && rb_const_defined(rb_cObject, rb_intern("BigDecimal"))) {
        rb_cBigDecimal = rb_const_get(rb_cObject, rb_intern("BigDecimal"));
    }

    if (RTEST(rb_cBigDecimal) && rb_cBigDecimal != rb_cObject && RTEST(rb_obj_is_kind_of(value, rb_cBigDecimal))) {
        VALUE s = rb_funcall(value, rb_intern("to_s"), 1, rb_str_new2("E"));
        return strtold(RSTRING_PTR(s), NULL);
    }

    /* Fall through to handling as a float */
    return rb_num2dbl(value);
}
Exemplo n.º 17
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.º 18
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 (RB_TYPE_P(module, T_MODULE))
	    return module;
	rb_raise(rb_eTypeError, "%s is not a module", rb_obj_classname(module));
    }
    module = rb_define_module_id(id);
    rb_vm_add_root_module(id, module);
    rb_const_set(rb_cObject, id, module);

    return module;
}
Exemplo n.º 19
0
static int getButtonArg(VALUE self, int argc, VALUE *argv)
{
	int num;

#ifdef RGSS3
	ID sym;
	rb_get_args(argc, argv, "n", &sym RB_ARG_END);

	if (rb_const_defined(self, sym))
		num = FIX2INT(rb_const_get(self, sym));
	else
		num = 0;
#else
	(void) self;
	rb_get_args(argc, argv, "i", &num RB_ARG_END);
#endif

	return num;
}
Exemplo n.º 20
0
void InitReader(VALUE mod) {
    klass_reader = rb_define_class_under(mod, "Reader", rb_cObject);
    rb_global_variable(&klass_reader);
    rb_define_alloc_func(klass_reader, reader_allocate);
    rb_define_method(klass_reader, "feed", reader_feed, 1);
    rb_define_method(klass_reader, "gets", reader_gets, 0);

    /* If the Encoding class is present, #default_external should be used to
     * determine the encoding for new strings. The "enc_default_external"
     * ID is non-zero when encoding should be set on new strings. */
    if (rb_const_defined(rb_cObject, rb_intern("Encoding"))) {
        enc_klass = rb_const_get(rb_cObject, rb_intern("Encoding"));
        enc_default_external = rb_intern("default_external");
        str_force_encoding = rb_intern("force_encoding");
        rb_global_variable(&enc_klass);
    } else {
        enc_default_external = 0;
    }
}
Exemplo n.º 21
0
void rxml_init_schema_type(void)
{
  /* Add in infinity support for ruby 1.8.7 */
  #if !defined(RUBY_VM) && defined(INFINITY)
  ID infinityId = rb_intern("INFINITY");
  if (rb_const_defined(rb_cFloat, infinityId) == Qfalse)
    rb_define_const(rb_cFloat, "INFINITY", rb_float_new(INFINITY));
  #endif

  cXMLSchemaType = rb_define_class_under(cXMLSchema, "Type", rb_cObject);

  rb_define_method(cXMLSchemaType, "namespace", rxml_schema_type_namespace, 0);
  rb_define_method(cXMLSchemaType, "name", rxml_schema_type_name, 0);
  rb_define_method(cXMLSchemaType, "elements", rxml_schema_type_elements, 0);
  rb_define_method(cXMLSchemaType, "attributes", rxml_schema_type_attributes, 0);
  rb_define_method(cXMLSchemaType, "base", rxml_schema_type_base, 0);
  rb_define_method(cXMLSchemaType, "kind", rxml_schema_type_kind, 0);
  rb_define_method(cXMLSchemaType, "node", rxml_schema_type_node, 0);
  rb_define_method(cXMLSchemaType, "facets", rxml_schema_type_facets, 0);
  rb_define_method(cXMLSchemaType, "annotation", rxml_schema_type_annot, 0);
}
Exemplo n.º 22
0
VALUE
rb_path_to_class(VALUE pathname)
{
    rb_encoding *enc = rb_enc_get(pathname);
    const char *pbeg, *p, *path = RSTRING_PTR(pathname);
    ID id;
    VALUE c = rb_cObject;

    if (!rb_enc_asciicompat(enc)) {
	rb_raise(rb_eArgError, "invalid class path encoding (non ASCII)");
    }
    pbeg = p = path;
    if (path[0] == '#') {
	rb_raise(rb_eArgError, "can't retrieve anonymous class %s", path);
    }
    while (*p) {
	while (*p && *p != ':') p++;
	id = rb_intern3(pbeg, p-pbeg, enc);
	if (p[0] == ':') {
	    if (p[1] != ':') goto undefined_class;
	    p += 2;
	    pbeg = p;
	}
	if (!rb_const_defined(c, id)) {
	  undefined_class:
	    rb_raise(rb_eArgError, "undefined class/module %.*s", (int)(p-path), path);
	}
	c = rb_const_get_at(c, id);
	switch (TYPE(c)) {
	  case T_MODULE:
	  case T_CLASS:
	    break;
	  default:
	    rb_raise(rb_eTypeError, "%s does not refer to class/module", path);
	}
    }

    return c;
}
Exemplo n.º 23
0
void rbTransform::Init( VALUE SFML )
{
    rbTransform::Class = rb_define_class_under( SFML, "Transform", rb_cObject );
	
	rb_define_alloc_func( rbTransform::Class, rbMacros::Allocate< sf::Transform > );

    // Instance methods
    ext_define_method( rbTransform::Class, "initialize",             rbTransform::Initialize,          -1 );
    ext_define_method( rbTransform::Class, "initialize_copy",        rbTransform::InitializeCopy,       1 );
	ext_define_method( rbTransform::Class, "matrix",                 rbTransform::GetMatrix,            0 );
	ext_define_method( rbTransform::Class, "inverse",                rbTransform::GetInverse,           0 );
	ext_define_method( rbTransform::Class, "transform_point",        rbTransform::TransformPoint,      -1 );
	ext_define_method( rbTransform::Class, "transform_rect",         rbTransform::TransformRect,        1 );
	ext_define_method( rbTransform::Class, "combine",                rbTransform::Combine,              1 );
	ext_define_method( rbTransform::Class, "translate",              rbTransform::Translate,           -1 );
	ext_define_method( rbTransform::Class, "rotate",                 rbTransform::Rotate,              -1 );
	ext_define_method( rbTransform::Class, "scale",                  rbTransform::Scale,               -1 );
	ext_define_method( rbTransform::Class, "*",                      rbTransform::MultiplyOperator,     1 );
    ext_define_method( rbTransform::Class, "marshal_dump",           rbTransform::MarshalDump,          0 );
	ext_define_method( rbTransform::Class, "marshal_load",           rbTransform::MarshalLoad,          1 );
    ext_define_method( rbTransform::Class, "==",                     rbTransform::Equal,                1 );
    ext_define_method( rbTransform::Class, "inspect",                rbTransform::Inspect,              0 );

    // Instance aliases
    rb_define_alias( rbTransform::Class, "to_s",           "inspect"         );
	rb_define_alias( rbTransform::Class, "get_matrix",     "matrix"          );
	rb_define_alias( rbTransform::Class, "getMatrix",      "matrix"          );
	rb_define_alias( rbTransform::Class, "to_a",           "matrix"          );
	rb_define_alias( rbTransform::Class, "get_inverse",    "inverse"         );
	rb_define_alias( rbTransform::Class, "getInverse",     "inverse"         );
	rb_define_alias( rbTransform::Class, "transformPoint", "transform_point" );
	rb_define_alias( rbTransform::Class, "transformRect",  "transform_rect"  );
	
	if( rb_const_defined( rbTransform::Class, rb_intern( "Identity" ) ) == Qfalse )
		rb_define_const( rbTransform::Class, "Identity", rbMacros::ToConstRuby( &sf::Transform::Identity, rbTransform::Class ) );
}
Exemplo n.º 24
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;
}
Exemplo n.º 25
0
/*
 * call-seq:
 *   IO.console      -> #<File:/dev/tty>
 *   IO.console(sym, *args)
 *
 * Returns an File instance opened console.
 *
 * If +sym+ is given, it will be sent to the opened console with
 * +args+ and the result will be returned instead of the console IO
 * itself.
 *
 * You must require 'io/console' to use this method.
 */
static VALUE
console_dev(int argc, VALUE *argv, VALUE klass)
{
    VALUE con = 0;
    rb_io_t *fptr;
    VALUE sym = 0;

    rb_check_arity(argc, 0, UNLIMITED_ARGUMENTS);
    if (argc) {
	Check_Type(sym = argv[0], T_SYMBOL);
    }
    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) ||
	    (!(fptr = RFILE(con)->fptr) || GetReadFD(fptr) == -1)) {
	    rb_const_remove(klass, id_console);
	    con = 0;
	}
    }
    if (sym) {
	if (sym == ID2SYM(id_close) && argc == 1) {
	    if (con) {
		rb_io_close(con);
		rb_const_remove(klass, id_console);
		con = 0;
	    }
	    return Qnil;
	}
    }
    if (!con) {
	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_RDWR, 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);
	fptr->pathv = rb_obj_freeze(rb_str_new2(CONSOLE_DEVICE));
#ifdef CONSOLE_DEVICE_FOR_WRITING
	GetOpenFile(out, ofptr);
	ofptr->pathv = fptr->pathv;
	fptr->tied_io_for_writing = out;
	ofptr->mode |= FMODE_SYNC;
#endif
	fptr->mode |= FMODE_SYNC;
	rb_const_set(klass, id_console, con);
    }
    if (sym) {
	return rb_f_send(argc, argv, con);
    }
    return con;
}
Exemplo n.º 26
0
VALUE
bpObjectToRuby(const bp::Object * obj,
               unsigned int tid)
{
    if (obj == NULL) return Qnil;

    VALUE v = Qnil;

    switch (obj->type()) {
        case BPTNull:
            v = Qnil;
            break;
        case BPTBoolean:
        {
            if (((bp::Bool *) obj)->value()) v = Qtrue;
            else v = Qfalse;
            break;
        }
        case BPTInteger:
            v = rb_ull2inum(((bp::Integer *) obj)->value());
            break;
        case BPTCallBack: {
            VALUE args[2];
            args[0] = rb_uint2inum(tid);
            args[1] = rb_ull2inum(((bp::Integer *) obj)->value());
            v = rb_class_new_instance(2, args, bp_rb_cCallback);
            break;
        }           
        case BPTDouble:
            v = rb_float_new(((bp::Double *) obj)->value());
            break;
        case BPTString:
            v = rb_str_new2(((bp::String *) obj)->value());
            break;
        case BPTNativePath: {
            VALUE id = rb_intern("Pathname");
            VALUE klass = 0;
            if (rb_const_defined(rb_cObject, id) &&
                (klass = rb_const_get(rb_cObject, id)) &&
                TYPE(klass) == T_CLASS)
            {
				std::string path = convert::toUTF8(((bp::Path *) obj)->value());
                VALUE p = rb_str_new2(path.c_str());
                v = rb_class_new_instance(1, &p, klass);
            }
            break;
        }
        case BPTMap: 
        {
            bp::Map * m = (bp::Map *) obj;
            v = rb_hash_new();
            bp::Map::Iterator i(*m);
            const char * key;
            while (NULL != (key = i.nextKey())) {
                rb_hash_aset(v,ID2SYM(rb_intern(key)), 
                             bpObjectToRuby(m->value(key), tid));
            }
            
            break;
        }
        
        case BPTList: 
        {
            bp::List * l = (bp::List *) obj;

            v = rb_ary_new();
            
            unsigned int i;
            for (i=0; i < l->size(); i++) {
                rb_ary_push(v, bpObjectToRuby(l->value(i), tid));
            }
            
            break;
        }
        case BPTAny: 
            // invalid
            break;
    }
    
    return v;
}
Exemplo n.º 27
0
static VALUE module_specs_const_defined(VALUE self, VALUE klass, VALUE id) {
  return rb_const_defined(klass, SYM2ID(id)) ? Qtrue : Qfalse;
}
Exemplo n.º 28
0
bp::Object *
rubyToBPObject(VALUE v)
{
    bp::Object * obj = NULL;
    
    switch (TYPE(v)) {
        case T_FLOAT:
            obj = new bp::Double(rb_num2dbl(v));
            break;
        case T_STRING:
            obj = new bp::String(RSTRING_PTR(v));
            break;
        case T_FIXNUM:
            obj = new bp::Integer(rb_num2ull(v));
            break;
        case T_TRUE:
            obj = new bp::Bool(true);
            break;
        case T_FALSE:
            obj = new bp::Bool(false);
            break;
        case T_HASH:
            obj = new bp::Map;
            rb_hash_foreach(v,
                            (int (*)(ANYARGS)) hashPopulator,
                            (VALUE) obj);
            break;
        case T_ARRAY:
        {
            long i;
            bp::List * l = new bp::List;
            for (i=0; i < RARRAY_LEN(v); i++) {
                l->append(rubyToBPObject(rb_ary_entry(v, i)));
            }
            obj = l;
        }
        break;
        case T_OBJECT: {
            // map Pathname objects into BPTPath types
            VALUE id = rb_intern("Pathname");
            VALUE klass = 0;
            if (rb_const_defined(rb_cObject, id) &&
                (klass = rb_const_get(rb_cObject, id)) &&
                TYPE(klass) == T_CLASS)
            {
                VALUE r = rb_obj_is_kind_of(v, klass);
                if (RTEST(r)) {
                    // convert to abs path
                    int error = 0;
                    VALUE absPath =
                        ruby::invokeFunction(v, "realpath", &error, 0);
                    VALUE pathString =
                        ruby::invokeFunction(absPath, "to_s", &error, 0);
                    if (!error && TYPE(pathString) == T_STRING) {
						obj = new bp::Path((const BPPath) convert::fromUTF8(RSTRING_PTR(pathString)).c_str());
                    }
                    break;
                }
            }
        }
        case T_NIL:
        default:
            obj = new bp::Null();
            break;
    }
    
    return obj;
}
Exemplo n.º 29
0
VALUE sm_const_defined(VALUE self, VALUE klass, VALUE id) {
  return rb_const_defined(klass, SYM2ID(id)) ? Qtrue : Qfalse;
}