本文整理汇总了C++中RBASIC函数的典型用法代码示例。如果您正苦于以下问题:C++ RBASIC函数的具体用法?C++ RBASIC怎么用?C++ RBASIC使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RBASIC函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: rb_mod_init_copy
/* :nodoc: */
VALUE
rb_mod_init_copy(VALUE clone, VALUE orig)
{
if (RB_TYPE_P(clone, T_CLASS)) {
class_init_copy_check(clone, orig);
}
rb_obj_init_copy(clone, orig);
if (!FL_TEST(CLASS_OF(clone), FL_SINGLETON)) {
RBASIC(clone)->klass = rb_singleton_class_clone(orig);
rb_singleton_class_attached(RBASIC(clone)->klass, (VALUE)clone);
}
RCLASS_SUPER(clone) = RCLASS_SUPER(orig);
if (RCLASS_IV_TBL(orig)) {
st_data_t id;
if (RCLASS_IV_TBL(clone)) {
st_free_table(RCLASS_IV_TBL(clone));
}
RCLASS_IV_TBL(clone) = st_copy(RCLASS_IV_TBL(orig));
CONST_ID(id, "__classpath__");
st_delete(RCLASS_IV_TBL(clone), &id, 0);
CONST_ID(id, "__classid__");
st_delete(RCLASS_IV_TBL(clone), &id, 0);
}
if (RCLASS_CONST_TBL(orig)) {
if (RCLASS_CONST_TBL(clone)) {
rb_free_const_table(RCLASS_CONST_TBL(clone));
}
RCLASS_CONST_TBL(clone) = st_init_numtable();
st_foreach(RCLASS_CONST_TBL(orig), clone_const_i, (st_data_t)RCLASS_CONST_TBL(clone));
}
if (RCLASS_M_TBL(orig)) {
struct clone_method_data data;
if (RCLASS_M_TBL(clone)) {
rb_free_m_table(RCLASS_M_TBL(clone));
}
data.tbl = RCLASS_M_TBL(clone) = st_init_numtable();
data.klass = clone;
st_foreach(RCLASS_M_TBL(orig), clone_method,
(st_data_t)&data);
}
return clone;
}
示例2: rb_ool_conmin_gencan_parameters_default
static VALUE rb_ool_conmin_gencan_parameters_default(VALUE klass)
{
ool_conmin_gencan_parameters P;
VALUE ary;
ool_conmin_parameters_default(ool_conmin_minimizer_gencan, (void*) &P);
ary = create_parameters_ary_gencan(&P);
RBASIC(ary)->klass = cool_conmin_gencan_parameters;
return ary;
}
示例3: ruby__sfvextra
static const char *
ruby__sfvextra(rb_printf_buffer *fp, size_t valsize, void *valp, long *sz, int sign)
{
VALUE value, result = (VALUE)fp->_bf._base;
rb_encoding *enc;
char *cp;
if (valsize != sizeof(VALUE)) return 0;
value = *(VALUE *)valp;
if (RBASIC(result)->klass) {
rb_raise(rb_eRuntimeError, "rb_vsprintf reentered");
}
if (sign == '+') {
if (RB_TYPE_P(value, T_CLASS)) {
# define LITERAL(str) (*sz = rb_strlen_lit(str), str)
if (value == rb_cNilClass) {
return LITERAL("nil");
}
else if (value == rb_cFixnum) {
return LITERAL("Fixnum");
}
else if (value == rb_cSymbol) {
return LITERAL("Symbol");
}
else if (value == rb_cTrueClass) {
return LITERAL("true");
}
else if (value == rb_cFalseClass) {
return LITERAL("false");
}
# undef LITERAL
}
value = rb_inspect(value);
}
else {
value = rb_obj_as_string(value);
if (sign == ' ') value = QUOTE(value);
}
enc = rb_enc_compatible(result, value);
if (enc) {
rb_enc_associate(result, enc);
}
else {
enc = rb_enc_get(result);
value = rb_str_conv_enc_opts(value, rb_enc_get(value), enc,
ECONV_UNDEF_REPLACE|ECONV_INVALID_REPLACE,
Qnil);
*(volatile VALUE *)valp = value;
}
StringValueCStr(value);
RSTRING_GETMEM(value, cp, *sz);
((rb_printf_buffer_extra *)fp)->value = value;
OBJ_INFECT(result, value);
return cp;
}
示例4: anonymous_struct
static VALUE
anonymous_struct(VALUE klass)
{
VALUE nstr;
nstr = rb_class_new(klass);
rb_make_metaclass(nstr, RBASIC(klass)->klass);
rb_class_inherited(klass, nstr);
return nstr;
}
示例5: make_gdkevent
VALUE
make_gdkevent(GdkEvent *ev)
{
VALUE obj;
if (ev == NULL) return Qnil;
obj = BOXED2RVAL(ev, GDK_TYPE_EVENT);
RBASIC(obj)->klass = gdkevents[ev->type]; /* hack */
return obj;
}
示例6: gdkevent_initialize
static VALUE
gdkevent_initialize(VALUE self, VALUE type)
{
GdkEventType gtype = RVAL2GENUM(type, GDK_TYPE_EVENT_TYPE);
if (RBASIC(self)->klass != gdkevents[gtype])
rb_raise(rb_eArgError, "Wrong event type for this class.");
G_INITIALIZE(self, gdk_event_new(gtype));
return Qnil;
}
示例7: proc_new
static VALUE
proc_new(VALUE klass, int is_lambda)
{
VALUE procval = Qnil;
rb_thread_t *th = GET_THREAD();
rb_control_frame_t *cfp = th->cfp;
rb_block_t *block;
if ((GC_GUARDED_PTR_REF(cfp->lfp[0])) != 0 &&
!RUBY_VM_CLASS_SPECIAL_P(cfp->lfp[0])) {
block = GC_GUARDED_PTR_REF(cfp->lfp[0]);
cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
}
else {
cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
if ((GC_GUARDED_PTR_REF(cfp->lfp[0])) != 0 &&
!RUBY_VM_CLASS_SPECIAL_P(cfp->lfp[0])) {
block = GC_GUARDED_PTR_REF(cfp->lfp[0]);
if (block->proc) {
return block->proc;
}
/* TODO: check more (cfp limit, called via cfunc, etc) */
while (cfp->dfp != block->dfp) {
cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
}
if (is_lambda) {
rb_warn("tried to create Proc object without a block");
}
}
else {
rb_raise(rb_eArgError,
"tried to create Proc object without a block");
}
}
procval = block->proc;
if (procval && RBASIC(procval)->klass == klass) {
return procval;
}
procval = vm_make_proc(th, cfp, block, klass);
if (is_lambda) {
rb_proc_t *proc;
GetProcPtr(procval, proc);
proc->is_lambda = Qtrue;
}
return procval;
}
示例8: rb_objc_newobj
void *
rb_objc_newobj(size_t size)
{
void *obj;
obj = auto_zone_allocate_object(__auto_zone, size, AUTO_OBJECT_SCANNED,
0, 0);
assert(obj != NULL);
RBASIC(obj)->klass = (VALUE)__nsobject;
return obj;
}
示例9: rb_define_class_id
VALUE
rb_define_class_id(ID id, VALUE super)
{
VALUE klass;
if (!super) super = rb_cObject;
klass = rb_class_new(super);
rb_make_metaclass(klass, RBASIC(super)->klass);
return klass;
}
示例10: syserr_initialize
static VALUE
syserr_initialize(int argc, VALUE *argv, VALUE self)
{
#if !defined(_WIN32)
char *strerror();
#endif
const char *err;
VALUE mesg, error;
VALUE klass = rb_obj_class(self);
if (klass == rb_eSystemCallError) {
st_data_t data = (st_data_t)klass;
rb_scan_args(argc, argv, "11", &mesg, &error);
if (argc == 1 && FIXNUM_P(mesg)) {
error = mesg; mesg = Qnil;
}
if (!NIL_P(error) && st_lookup(syserr_tbl, NUM2LONG(error), &data)) {
klass = (VALUE)data;
/* change class */
if (TYPE(self) != T_OBJECT) { /* insurance to avoid type crash */
rb_raise(rb_eTypeError, "invalid instance type");
}
RBASIC(self)->klass = klass;
}
}
else {
rb_scan_args(argc, argv, "01", &mesg);
error = rb_const_get(klass, rb_intern("Errno"));
}
if (!NIL_P(error)) err = strerror(NUM2INT(error));
else err = "unknown error";
if (!NIL_P(mesg)) {
rb_encoding *le = rb_locale_encoding();
VALUE str = mesg;
StringValue(str);
mesg = rb_sprintf("%s - %.*s", err,
(int)RSTRING_LEN(str), RSTRING_PTR(str));
if (le == rb_usascii_encoding()) {
rb_encoding *me = rb_enc_get(mesg);
if (le != me && rb_enc_asciicompat(me))
le = me;
}/* else assume err is non ASCII string. */
OBJ_INFECT(mesg, str);
rb_enc_associate(mesg, le);
}
else {
mesg = rb_str_new2(err);
rb_enc_associate(mesg, rb_locale_encoding());
}
rb_call_super(1, &mesg);
rb_iv_set(self, "errno", error);
return self;
}
示例11: w_nbyte
static void
w_nbyte(const char *s, long n, struct dump_arg *arg)
{
VALUE buf = arg->str;
rb_str_buf_cat(buf, s, n);
RBASIC(buf)->flags |= arg->infection;
if (arg->dest && RSTRING_LEN(buf) >= BUFSIZ) {
rb_io_write(arg->dest, buf);
rb_str_resize(buf, 0);
}
}
示例12: rb_check_inheritable
/*!
* Ensures a class can be derived from super.
*
* \param super a reference to an object.
* \exception TypeError if \a super is not a Class or \a super is a singleton class.
*/
void
rb_check_inheritable(VALUE super)
{
if (TYPE(super) != T_CLASS) {
rb_raise(rb_eTypeError, "superclass must be a Class (%s given)",
rb_obj_classname(super));
}
if (RBASIC(super)->flags & FL_SINGLETON) {
rb_raise(rb_eTypeError, "can't make subclass of singleton class");
}
}
示例13: Looksee_internal_class_to_module
/*
* Return the class or module that the given internal class
* represents.
*
* If a class is given, this is the class. If an iclass is given,
* this is the module it represents in the lookup chain.
*/
VALUE Looksee_internal_class_to_module(VALUE self, VALUE internal_class) {
if (!SPECIAL_CONST_P(internal_class)) {
switch (BUILTIN_TYPE(internal_class)) {
case T_ICLASS:
return RBASIC(internal_class)->klass;
case T_CLASS:
return internal_class;
}
}
rb_raise(rb_eArgError, "not an internal class: %s", RSTRING_PTR(rb_inspect(internal_class)));
}
示例14: fragment_byteno
static int
fragment_byteno(VALUE fragment)
{
VALUE val;
Check_Type(fragment, T_STRUCT);
if (RBASIC(fragment)->klass != Fragment) {
rb_raise(rb_eTypeError, "not fragment");
}
val = RSTRUCT(fragment)->ptr[3];
return NUM2INT(val);
}
示例15: add_modules
static void
add_modules(struct cmdline_options *opt, const char *mod)
{
VALUE list = opt->req_list;
if (!list) {
opt->req_list = list = rb_ary_new();
RBASIC(list)->klass = 0;
}
rb_ary_push(list, rb_obj_freeze(rb_str_new2(mod)));
}