本文整理汇总了C++中rb_name_error函数的典型用法代码示例。如果您正苦于以下问题:C++ rb_name_error函数的具体用法?C++ rb_name_error怎么用?C++ rb_name_error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rb_name_error函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: mnew
static inline VALUE
mnew(VALUE klass, VALUE obj, ID id, VALUE mclass, int scope)
{
rb_vm_method_t *m = rb_vm_get_method(klass, obj, id, scope);
assert(m != NULL);
if (m->node) {
const int flag = m->node->flags & NOEX_MASK;
if (scope && flag != NOEX_PUBLIC) {
const char *v = "";
switch (flag) {
case NOEX_PRIVATE:
v = "private";
break;
case NOEX_PROTECTED:
v = "protected";
break;
}
rb_name_error(id, "method `%s' for %s `%s' is %s",
rb_id2name(id),
(TYPE(klass) == T_MODULE) ? "module" : "class",
rb_class2name(klass),
v);
}
}
return Data_Wrap_Struct(mclass, NULL, NULL, m);
}
示例2: remove_method
static void
remove_method(VALUE klass, ID mid)
{
st_data_t key, data;
rb_method_entry_t *me = 0;
if (klass == rb_cObject) {
rb_secure(4);
}
if (rb_safe_level() >= 4 && !OBJ_UNTRUSTED(klass)) {
rb_raise(rb_eSecurityError, "Insecure: can't remove method");
}
rb_check_frozen(klass);
if (mid == object_id || mid == id__send__ || mid == idInitialize) {
rb_warn("removing `%s' may cause serious problems", rb_id2name(mid));
}
if (!st_lookup(RCLASS_M_TBL(klass), mid, &data) ||
!(me = (rb_method_entry_t *)data) ||
(!me->def || me->def->type == VM_METHOD_TYPE_UNDEF)) {
rb_name_error(mid, "method `%s' not defined in %s",
rb_id2name(mid), rb_class2name(klass));
}
key = (st_data_t)mid;
st_delete(RCLASS_M_TBL(klass), &key, &data);
rb_vm_check_redefinition_opt_method(me, klass);
rb_clear_cache_for_undef(klass, mid);
rb_unlink_method_entry(me);
CALL_METHOD_HOOK(klass, removed, mid);
}
示例3: step_initialize
static VALUE
step_initialize( int argc, VALUE *argv, VALUE self )
{
VALUE a, b=Qnil, c=Qnil, d=Qnil, e=Qnil;
rb_scan_args(argc, argv, "13", &a, &b, &c, &d);
/* Selfs are immutable, so that they should be initialized only once. */
if (rb_ivar_defined(self, id_beg)) {
rb_name_error(rb_intern("initialize"), "`initialize' called twice");
}
if (rb_obj_is_kind_of(a,rb_cRange)) {
if (argc>3) {
rb_raise(rb_eArgError, "extra argument");
}
d = c;
c = b;
e = rb_funcall(a, rb_intern("exclude_end?"), 0);
//b = rb_ivar_get(a, id_end);
b = rb_funcall(a, id_end, 0);
//a = rb_ivar_get(a, id_beg);
a = rb_funcall(a, id_beg, 0);
}
step_init(self, a, b, c, d, e);
return Qnil;
}
示例4: rb_attr
void
rb_attr(VALUE klass, ID id, int read, int write, int ex)
{
const char *name;
int noex;
if (!ex) {
noex = NOEX_PUBLIC;
}
else {
// TODO honor current scope ex
noex = NOEX_PUBLIC;
}
if (!rb_is_local_id(id) && !rb_is_const_id(id)) {
rb_name_error(id, "invalid attribute name `%s'", rb_id2name(id));
}
name = rb_id2name(id);
if (!name) {
rb_raise(rb_eArgError, "argument needs to be symbol or string");
}
rb_vm_define_attr((Class)klass, name, read, write, noex);
if (write) {
rb_objc_define_kvo_setter(klass, id);
}
}
示例5: rb_define_class_under
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;
}
示例6: rb_define_class_under
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;
}
示例7: rb_define_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 (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;
}
示例8: rb_define_class_id_under
/*!
* 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;
}
示例9: nst_s_new
/*
Foo = Numo::Struct.new {
int8 :byte
float64 :float, [2,2]
dcomplex :compl
}
*/
static VALUE
nst_s_new(int argc, VALUE *argv, VALUE klass)
{
VALUE name=Qnil, rest, size;
VALUE st, members;
ID id;
rb_scan_args(argc, argv, "0*", &rest);
if (RARRAY_LEN(rest)>0) {
name = RARRAY_AREF(rest,0);
if (!NIL_P(name)) {
VALUE tmp = rb_check_string_type(name);
if (!NIL_P(tmp)) {
rb_ary_shift(rest);
} else {
name = Qnil;
}
}
}
if (NIL_P(name)) {
st = rb_define_class_id(name, klass);
rb_funcall(klass, rb_intern("inherited"), 1, st);
}
else {
char *cname = StringValuePtr(name);
id = rb_intern(cname);
if (!rb_is_const_id(id)) {
rb_name_error(id, "identifier %s needs to be constant", cname);
}
if (rb_const_defined_at(klass, id)) {
rb_warn("redefining constant Struct::%s", cname);
rb_mod_remove_const(klass, ID2SYM(id));
}
st = rb_define_class_under(klass, rb_id2name(id), klass);
}
rb_iv_set(st, "__members__", rb_ary_new());
rb_iv_set(st, "__offset__", INT2FIX(0));
if (rb_block_given_p()) {
rb_mod_module_eval(0, 0, st);
}
size = rb_iv_get(st, "__offset__");
members = rb_iv_get(st, "__members__");
//printf("size=%d\n",NUM2INT(size));
rb_define_const(st, CONTIGUOUS_STRIDE, size);
rb_define_const(st, ELEMENT_BYTE_SIZE, size);
rb_define_const(st, ELEMENT_BIT_SIZE, rb_funcall(size,'*',1,INT2FIX(8)));
OBJ_FREEZE(members);
rb_define_const(st, "DEFINITIONS", members);
rb_define_singleton_method(st, "new", rb_class_new_instance, -1);
//rb_define_singleton_method(st, "[]", rb_class_new_instance, -1);
rb_define_method(st, "allocate", nst_allocate, 0);
return st;
}
示例10: rb_struct_aset_id
static VALUE
rb_struct_aset_id(VALUE s, ID id, VALUE val)
{
VALUE members, *ptr, *ptr_members;
long i, len;
members = rb_struct_members(s);
len = RARRAY_LEN(members);
rb_struct_modify(s);
if (RSTRUCT_LEN(s) != len) {
rb_raise(rb_eTypeError, "struct size differs (%ld required %ld given)",
len, RSTRUCT_LEN(s));
}
ptr = RSTRUCT_PTR(s);
ptr_members = RARRAY_PTR(members);
for (i=0; i<len; i++) {
if (SYM2ID(ptr_members[i]) == id) {
ptr[i] = val;
return val;
}
}
rb_name_error(id, "no member '%s' in struct", rb_id2name(id));
UNREACHABLE;
}
示例11: range_modify
static void
range_modify(VALUE range)
{
/* Ranges are immutable, so that they should be initialized only once. */
if (RANGE_EXCL(range) != Qnil) {
rb_name_error(idInitialize, "`initialize' called twice");
}
}
示例12: rb_print_undef
void
rb_print_undef(VALUE klass, ID id, int scope)
{
const char *v = method_scope_name(scope);
rb_name_error(id, "undefined%s method `%"PRIsVALUE"' for %s `% "PRIsVALUE"'", v,
QUOTE_ID(id),
(RB_TYPE_P(klass, T_MODULE)) ? "module" : "class",
rb_class_name(klass));
}
示例13: rb_undef
void
rb_undef(VALUE klass, ID id)
{
// TODO
#if 0
VALUE origin;
NODE *body;
#if 0 // TODO
if (rb_vm_cbase() == rb_cObject && klass == rb_cObject) {
rb_secure(4);
}
#endif
if (rb_safe_level() >= 4 && !OBJ_TAINTED(klass)) {
rb_raise(rb_eSecurityError, "Insecure: can't undef `%s'",
rb_id2name(id));
}
rb_frozen_class_p(klass);
if (id == object_id || id == __send__ || id == idInitialize) {
rb_warn("undefining `%s' may cause serious problem", rb_id2name(id));
}
/* TODO: warn if a very important method of NSObject is undefined
* by default, pure objc methods are not exposed by introspections API
*/
body = search_method(klass, id, &origin);
if (!body || !body->nd_body) {
const char *s0 = " class";
VALUE c = klass;
if (RCLASS_SINGLETON(c)) {
VALUE obj = rb_iv_get(klass, "__attached__");
switch (TYPE(obj)) {
case T_MODULE:
case T_CLASS:
c = obj;
s0 = "";
}
}
else if (TYPE(c) == T_MODULE) {
s0 = " module";
}
rb_name_error(id, "undefined method `%s' for%s `%s'",
rb_id2name(id), s0, rb_class2name(c));
}
rb_add_method(klass, id, 0, NOEX_PUBLIC);
if (RCLASS_SINGLETON(klass)) {
rb_funcall(rb_iv_get(klass, "__attached__"),
singleton_undefined, 1, ID2SYM(id));
}
else {
rb_funcall(klass, undefined, 1, ID2SYM(id));
}
#endif
}
示例14: rb_print_inaccessible
void
rb_print_inaccessible(VALUE klass, ID id, int scope)
{
const char *v = method_scope_name(scope);
rb_name_error(id, "method `%"PRIsVALUE"' for %s `% "PRIsVALUE"' is %s",
QUOTE_ID(id),
(RB_TYPE_P(klass, T_MODULE)) ? "module" : "class",
rb_class_name(klass),
v);
}
示例15: make_struct
static VALUE
make_struct(VALUE name, VALUE members, VALUE klass)
{
VALUE nstr;
ID id;
long i, len;
OBJ_FREEZE(members);
if (NIL_P(name)) {
nstr = rb_class_new(klass);
#if !WITH_OBJC
rb_make_metaclass(nstr, RBASIC(klass)->klass);
#endif
rb_class_inherited(klass, nstr);
}
else {
/* old style: should we warn? */
name = rb_str_to_str(name);
id = rb_to_id(name);
if (!rb_is_const_id(id)) {
rb_name_error(id, "identifier %s needs to be constant",
StringValuePtr(name));
}
if (rb_const_defined_at(klass, id)) {
rb_warn("redefining constant Struct::%s", StringValuePtr(name));
rb_mod_remove_const(klass, ID2SYM(id));
}
nstr = rb_define_class_under(klass, rb_id2name(id), klass);
}
rb_ivar_set(nstr, id_members, members);
rb_objc_define_method(*(VALUE *)nstr, "alloc", struct_alloc, 0);
rb_objc_define_method(*(VALUE *)nstr, "new", rb_class_new_instance_imp, -1);
rb_objc_define_method(*(VALUE *)nstr, "[]", rb_class_new_instance_imp, -1);
rb_objc_define_method(*(VALUE *)nstr, "members", rb_struct_s_members_m, 0);
len = RARRAY_LEN(members);
for (i=0; i< len; i++) {
ID id = SYM2ID(RARRAY_AT(members, i));
if (rb_is_local_id(id) || rb_is_const_id(id)) {
long j = i; /* Needed for block data reference. */
/* Struct attribute reader */
rb_objc_define_method(nstr, rb_id2name(id),
pl_imp_implementationWithBlock(^(VALUE obj) {
return RSTRUCT_PTR(obj)[j];
}), 0);
/* Struct attribute writer */
rb_objc_define_method(nstr, rb_id2name(rb_id_attrset(id)),
pl_imp_implementationWithBlock(^(VALUE obj, VALUE val) {
VALUE *ptr = RSTRUCT_PTR(obj);
rb_struct_modify(obj);
GC_WB(&ptr[i], val);
return val;
}), 1);