当前位置: 首页>>代码示例>>C++>>正文


C++ rb_obj_as_string函数代码示例

本文整理汇总了C++中rb_obj_as_string函数的典型用法代码示例。如果您正苦于以下问题:C++ rb_obj_as_string函数的具体用法?C++ rb_obj_as_string怎么用?C++ rb_obj_as_string使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了rb_obj_as_string函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: rb_check_type

void
rb_check_type(VALUE x, int t)
{
    const struct types *type = builtin_types;
    const struct types *const typeend = builtin_types +
	sizeof(builtin_types) / sizeof(builtin_types[0]);
    int xt;

    if (x == Qundef) {
	rb_bug("undef leaked to the Ruby space");
    }

    xt = TYPE(x);
    if (xt != t || (xt == T_DATA && RTYPEDDATA_P(x))) {
	while (type < typeend) {
	    if (type->type == t) {
		const char *etype;

		if (NIL_P(x)) {
		    etype = "nil";
		}
		else if (FIXNUM_P(x)) {
		    etype = "Fixnum";
		}
		else if (SYMBOL_P(x)) {
		    etype = "Symbol";
		}
		else if (rb_special_const_p(x)) {
		    etype = RSTRING_PTR(rb_obj_as_string(x));
		}
		else {
		    etype = rb_obj_classname(x);
		}
		rb_raise(rb_eTypeError, "wrong argument type %s (expected %s)",
			 etype, type->name);
	    }
	    type++;
	}
	if (xt > T_MASK && xt <= 0x3f) {
	    rb_fatal("unknown type 0x%x (0x%x given, probably comes from extension library for ruby 1.8)", t, xt);
	}
	rb_bug("unknown type 0x%x (0x%x given)", t, xt);
    }
}
开发者ID:nurse,项目名称:ruby,代码行数:44,代码来源:error.c

示例2: ora_number_initialize

/*
=begin
--- OraNumber.new()
=end
*/
static VALUE ora_number_initialize(int argc, VALUE *argv, VALUE self)
{
  ora_vnumber_t *ovn = get_ora_number(self);
  volatile VALUE arg;

  rb_scan_args(argc, argv, "01", &arg);
  ovn->size = 1;
  ovn->num.exponent = 0x80;
  memset(ovn->num.mantissa, 0, sizeof(ovn->num.mantissa));
  if (argc == 1) {
    if (TYPE(arg) != T_STRING) {
      arg = rb_obj_as_string(arg);
    }
    if (ora_number_from_str(ovn, RSTRING_ORATEXT(arg), RSTRING_LEN(arg)) != 0) {
      rb_raise(rb_eArgError, "could not convert '%s' to OraNumber", RSTRING_PTR(arg));
    }
  }
  return Qnil;
}
开发者ID:kevincolyar,项目名称:ruby_oracle_libs,代码行数:24,代码来源:oranumber.c

示例3: oci8_lob_write

static VALUE oci8_lob_write(VALUE self, VALUE data)
{
    oci8_lob_t *lob = DATA_PTR(self);
    oci8_svcctx_t *svcctx = oci8_get_svcctx(lob->svc);
    ub4 amt;

    lob_open(lob);
    if (TYPE(data) != T_STRING) {
        data = rb_obj_as_string(data);
    }
    if (lob->lobtype == OCI_TEMP_CLOB) {
        data = rb_str_export_to_enc(data, oci8_encoding);
    }
    RB_GC_GUARD(data);
    amt = RSTRING_LEN(data);
    oci_lc(OCILobWrite_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, lob->base.hp.lob, &amt, lob->pos + 1, RSTRING_PTR(data), amt, OCI_ONE_PIECE, NULL, NULL, 0, lob->csfrm));
    lob->pos += amt;
    return UINT2NUM(amt);
}
开发者ID:aq1018,项目名称:ruby-oci8,代码行数:19,代码来源:lob.c

示例4: rg_write

static VALUE
rg_write(VALUE self, VALUE buf)
{
    gssize count;
    gsize bytes_written;
    GIOStatus status;
    GError* err = NULL;

    buf = rb_obj_as_string(buf);

    StringValue(buf);

    count = RSTRING_LEN(buf);

    status = g_io_channel_write_chars(_SELF(self), RVAL2CSTR(buf), count, &bytes_written, &err);

    ioc_error(status, err);
    return UINT2NUM(bytes_written);
}
开发者ID:htrb,项目名称:ruby-gnome2,代码行数:19,代码来源:rbglib_iochannel.c

示例5: load_script

static int
load_script(int argc, char **argv)
{
  VALUE r_argv, fname;
  int state, i;

  if (argc < 1) {
    return 0;
  }

  r_argv = rb_const_get(rb_mKernel, rb_intern("ARGV"));
  rb_ary_clear(r_argv);
  for (i = 1; i < argc; i++) {
    rb_ary_push(r_argv, rb_tainted_str_new2(argv[i]));
  }

  fname = rb_funcall(rb_cFile, ExpandPath, 1, rb_str_new2(argv[0]));
  rb_load_protect(fname, 1, &state);
  if (state) {
    VALUE errinfo, errstr, errat;
    int n, i;
    const char *cstr;

    errinfo = rb_errinfo();
    errstr = rb_obj_as_string(errinfo);
    cstr = StringValueCStr(errstr);
    if (strcmp(cstr, "exit")) {
      ngraph_err_puts(cstr);
      errat = rb_funcall(errinfo, rb_intern("backtrace"), 0);
      if (! NIL_P(errat)) {
	n = RARRAY_LEN(errat);
	for (i = 0; i < n; i ++) {
	  errstr = rb_str_new2("\tfrom ");
	  rb_str_append(errstr, rb_ary_entry(errat, i));
	  ngraph_err_puts(StringValueCStr(errstr));
	}
      }
    }
  }
  rb_gc_start();

  return 0;
}
开发者ID:htrb,项目名称:ngraph-gtk,代码行数:43,代码来源:ngraph.c

示例6: rxml_xpath_context_register_namespace

/*
 * call-seq:
 *    context.register_namespace(prefix, uri) -> (true|false)
 *
 * Register the specified namespace URI with the specified prefix
 * in this context.

 *   context.register_namespace('xi', 'http://www.w3.org/2001/XInclude')
 */
static VALUE rxml_xpath_context_register_namespace(VALUE self, VALUE prefix, VALUE uri)
{
  xmlXPathContextPtr ctxt;
  Data_Get_Struct(self, xmlXPathContext, ctxt);

  /* Prefix could be a symbol. */
  prefix = rb_obj_as_string(prefix);
  
  if (xmlXPathRegisterNs(ctxt, (xmlChar*) StringValuePtr(prefix),
      (xmlChar*) StringValuePtr(uri)) == 0)
  {
    return (Qtrue);
  }
  else
  {
    /* Should raise an exception, IMHO (whose?, why shouldnt it? -danj)*/
    rb_warning("register namespace failed");
    return (Qfalse);
  }
}
开发者ID:tekwiz,项目名称:libxml-ruby,代码行数:29,代码来源:ruby_xml_xpath_context.c

示例7: fastopen

/*
 * call-seq:
 *
 *	s = Kgio::Socket.new(:INET, :STREAM)
 *	addr = Socket.pack_sockaddr_in(80, "example.com")
 *	s.kgio_fastopen("hello world", addr) -> nil
 *
 * Starts a TCP connection using TCP Fast Open.  This uses a blocking
 * sendto() syscall and is only available on Ruby 1.9 or later.
 * This raises exceptions (including Errno::EINPROGRESS/Errno::EAGAIN)
 * on errors.  Using this is only recommended for blocking sockets.
 *
 * Timeouts may be set with setsockopt:
 *
 *	s.setsockopt(:SOCKET, :SNDTIMEO, [1,0].pack("l_l_"))
 */
static VALUE fastopen(VALUE sock, VALUE buf, VALUE addr)
{
	struct tfo_args a;
	VALUE str = (TYPE(buf) == T_STRING) ? buf : rb_obj_as_string(buf);
	ssize_t w;

	a.fd = my_fileno(sock);
	a.buf = RSTRING_PTR(str);
	a.buflen = (size_t)RSTRING_LEN(str);
	a.addr = sockaddr_from(&a.addrlen, addr);

	/* n.b. rb_thread_blocking_region preserves errno */
	w = (ssize_t)rb_thread_io_blocking_region(tfo_sendto, &a, a.fd);
	if (w < 0)
		rb_sys_fail("sendto");
	if ((size_t)w == a.buflen)
		return Qnil;

	return rb_str_subseq(str, w, a.buflen - w);
}
开发者ID:LegalHackers,项目名称:takemyphotodown,代码行数:36,代码来源:connect.c

示例8: exc_inspect

static VALUE
exc_inspect(VALUE exc)
{
    VALUE str, klass;

    klass = CLASS_OF(exc);
    exc = rb_obj_as_string(exc);
    if (RSTRING_LEN(exc) == 0) {
	return rb_str_dup(rb_class_name(klass));
    }

    str = rb_str_buf_new2("#<");
    klass = rb_class_name(klass);
    rb_str_buf_append(str, klass);
    rb_str_buf_cat(str, ": ", 2);
    rb_str_buf_append(str, exc);
    rb_str_buf_cat(str, ">", 1);

    return str;
}
开发者ID:knugie,项目名称:ruby,代码行数:20,代码来源:error.c

示例9: err_append

static void
err_append(const char *s)
{
  rb_thread_t *th = GET_THREAD();
  if (th->parse_in_eval) {
    if (NIL_P(th->errinfo)) {
      th->errinfo = rb_exc_new2(rb_eSyntaxError, s);
    }
    else {
      VALUE str = rb_obj_as_string(GET_THREAD()->errinfo);

      rb_str_cat2(str, "\n");
      rb_str_cat2(str, s);
      th->errinfo = rb_exc_new3(rb_eSyntaxError, str);
    }
  }
  else {
    rb_write_error(s);
    rb_write_error("\n");
  }
}
开发者ID:RWB01,项目名称:Code-Translator,代码行数:21,代码来源:error.c

示例10: ruby_xml_node_content_add

/*
 * call-seq:
 *    node << ("string" | node) -> XML::Node
 * 
 * Add the specified string or XML::Node to this node's
 * content.  The returned node is the node that was
 * added and not self, thereby allowing << calls to
 * be chained.
 */
VALUE
ruby_xml_node_content_add(VALUE self, VALUE obj) {
  xmlNodePtr xnode;
  VALUE str;

  Data_Get_Struct(self, xmlNode, xnode);
  /* XXX This should only be legal for a CDATA type node, I think,
   * resulting in a merge of content, as if a string were passed
   * danj 070827
   */
  if (rb_obj_is_kind_of(obj, cXMLNode)) {
    ruby_xml_node_child_set(self, obj);
  } else {
    str = rb_obj_as_string(obj);
    if (NIL_P(str) || TYPE(str) != T_STRING)
      rb_raise(rb_eTypeError, "invalid argument: must be string or XML::Node");

		xmlNodeAddContent(xnode, (xmlChar*)StringValuePtr(str));
  }
  return(self);
}
开发者ID:dvdplm,项目名称:libxml-ruby,代码行数:30,代码来源:ruby_xml_node.c

示例11: frt_qp_parse

/*
 *  call-seq:
 *     query_parser.parse(query_string) -> Query
 *
 *  Parse a query string returning a Query object if parsing was successful.
 *  Will raise a QueryParseException if unsuccessful. 
 */
static VALUE
frt_qp_parse(VALUE self, VALUE rstr)
{
    const char *msg = NULL;
    volatile VALUE rq;
    GET_QP;
    rstr = rb_obj_as_string(rstr);
    TRY
        rq = frt_get_q(qp_parse(qp, RSTRING(rstr)->ptr));
        break;
    default:
        msg = xcontext.msg;
        HANDLED();
    XENDTRY

    if (msg) {
        rb_raise(cQueryParseException, msg);
    }

    return rq;
}
开发者ID:BusProject,项目名称:theballot,代码行数:28,代码来源:r_qparser.c

示例12: rb_check_type

void
rb_check_type(VALUE x, int t)
{
    const struct types *type = builtin_types;
    const struct types *const typeend = builtin_types +
	sizeof(builtin_types) / sizeof(builtin_types[0]);

    if (x == Qundef) {
	rb_bug("undef leaked to the Ruby space");
    }

    if (TYPE(x) != t) {
	while (type < typeend) {
	    if (type->type == t) {
		const char *etype;

		if (NIL_P(x)) {
		    etype = "nil";
		}
		else if (FIXNUM_P(x)) {
		    etype = "Fixnum";
		}
		else if (SYMBOL_P(x)) {
		    etype = "Symbol";
		}
		else if (rb_special_const_p(x)) {
		    etype = RSTRING_PTR(rb_obj_as_string(x));
		}
		else {
		    etype = rb_obj_classname(x);
		}
		rb_raise(rb_eTypeError, "wrong argument type %s (expected %s)",
			 etype, type->name);
	    }
	    type++;
	}
	rb_bug("unknown type 0x%x (0x%x given)", t, TYPE(x));
    }
}
开发者ID:1nueve,项目名称:MacRuby,代码行数:39,代码来源:error.c

示例13: err_append

static void
err_append(const char *s)
{
    extern VALUE ruby_errinfo;

    if (ruby_in_eval) {
	if (NIL_P(ruby_errinfo)) {
	    ruby_errinfo = rb_exc_new2(rb_eSyntaxError, s);
	}
	else {
	    VALUE str = rb_obj_as_string(ruby_errinfo);

	    rb_str_cat2(str, "\n");
	    rb_str_cat2(str, s);
	    ruby_errinfo = rb_exc_new3(rb_eSyntaxError, str);
	}
    }
    else {
	rb_write_error(s);
	rb_write_error("\n");
    }
}
开发者ID:asimoov,项目名称:emscripted-ruby,代码行数:22,代码来源:error.c

示例14: rxml_node_new_comment

/*
 * call-seq:
 *    XML::Node.new_comment(content = nil) -> XML::Node
 *
 * Create a new comment node, optionally setting
 * the node's content.
 *
 */
static VALUE rxml_node_new_comment(int argc, VALUE *argv, VALUE klass)
{
  VALUE content = Qnil;
  xmlNodePtr xnode;

  rb_scan_args(argc, argv, "01", &content);

  if (NIL_P(content))
  {
    xnode = xmlNewComment(NULL);
  }
  else
  {
    content = rb_obj_as_string(content);
    xnode = xmlNewComment((xmlChar*) StringValueCStr(content));
  }

  if (xnode == NULL)
    rxml_raise(&xmlLastError);

  return rxml_node_wrap(xnode);
}
开发者ID:nikitug,项目名称:libxml-ruby,代码行数:30,代码来源:ruby_xml_node.c

示例15: initFunc

static void * initFunc(xsltTransformContextPtr ctxt, const xmlChar *uri)
{
    VALUE modules = rb_iv_get(xslt, "@modules");
    VALUE obj = rb_hash_aref(modules, rb_str_new2((const char *)uri));
    VALUE args = { Qfalse };
    VALUE methods = rb_funcall(obj, rb_intern("instance_methods"), 1, args);
    VALUE inst;
    nokogiriXsltStylesheetTuple *wrapper;
    int i;

    for(i = 0; i < RARRAY_LEN(methods); i++) {
	VALUE method_name = rb_obj_as_string(RARRAY_PTR(methods)[i]);
	xsltRegisterExtFunction(ctxt,
          (unsigned char *)StringValuePtr(method_name), uri, method_caller);
    }

    Data_Get_Struct(ctxt->style->_private, nokogiriXsltStylesheetTuple,
                    wrapper);
    inst = rb_class_new_instance(0, NULL, obj);
    rb_ary_push(wrapper->func_instances, inst);

    return (void *)inst;
}
开发者ID:127lh,项目名称:metasploit-framework,代码行数:23,代码来源:xslt_stylesheet.c


注:本文中的rb_obj_as_string函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。