mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
change mrb_warn to get mrb_state and %S formatter
This commit is contained in:
+1
-1
@@ -299,7 +299,7 @@ void mrb_exc_raise(mrb_state *mrb, mrb_value exc);
|
||||
void mrb_raise(mrb_state *mrb, struct RClass *c, const char *msg);
|
||||
void mrb_raisef(mrb_state *mrb, struct RClass *c, const char *fmt, ...);
|
||||
void mrb_name_error(mrb_state *mrb, mrb_sym id, const char *fmt, ...);
|
||||
void mrb_warn(const char *fmt, ...);
|
||||
void mrb_warn(mrb_state *mrb, const char *fmt, ...);
|
||||
void mrb_bug(const char *fmt, ...);
|
||||
|
||||
/* macros to get typical exception objects
|
||||
|
||||
@@ -1070,7 +1070,7 @@ retry:
|
||||
if (posarg >= 0 && nextarg < argc) {
|
||||
const char *mesg = "too many arguments for format string";
|
||||
if (mrb_test(ruby_debug)) mrb_raise(mrb, E_ARGUMENT_ERROR, mesg);
|
||||
if (mrb_test(ruby_verbose)) mrb_warn("%s", mesg);
|
||||
if (mrb_test(ruby_verbose)) mrb_warn(mrb, "%S", mrb_str_new_cstr(mrb, mesg));
|
||||
}
|
||||
#endif
|
||||
mrb_str_resize(mrb, result, blen);
|
||||
|
||||
@@ -252,7 +252,7 @@ make_struct(mrb_state *mrb, mrb_value name, mrb_value members, struct RClass * k
|
||||
mrb_name_error(mrb, id, "identifier %S needs to be constant", name);
|
||||
}
|
||||
if (mrb_const_defined_at(mrb, klass, id)) {
|
||||
mrb_warn("redefining constant Struct::%s", mrb_string_value_ptr(mrb, name));
|
||||
mrb_warn(mrb, "redefining constant Struct::%S", name);
|
||||
//?rb_mod_remove_const(klass, mrb_sym2name(mrb, id));
|
||||
}
|
||||
c = mrb_define_class_under(mrb, klass, RSTRING_PTR(name), klass);
|
||||
|
||||
+2
-3
@@ -255,13 +255,12 @@ mrb_define_class_under(mrb_state *mrb, struct RClass *outer, const char *name, s
|
||||
if (mrb_const_defined_at(mrb, outer, id)) {
|
||||
c = class_from_sym(mrb, outer, id);
|
||||
if (mrb_class_real(c->super) != super) {
|
||||
mrb_name_error(mrb, id, "%S is already defined", mrb_sym2str(mrb, id));
|
||||
mrb_name_error(mrb, id, "%S is already defined", name);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
if (!super) {
|
||||
mrb_warn("no super class for `%S::%S', Object assumed",
|
||||
mrb_obj_value(outer), mrb_sym2str(mrb, id));
|
||||
mrb_warn(mrb, "no super class for `%S::%S', Object assumed", outer, name);
|
||||
}
|
||||
c = mrb_class_new(mrb, super);
|
||||
setup_class(mrb, mrb_obj_value(outer), c, id);
|
||||
|
||||
+8
-6
@@ -312,15 +312,17 @@ mrb_name_error(mrb_state *mrb, mrb_sym id, const char *fmt, ...)
|
||||
}
|
||||
|
||||
void
|
||||
mrb_warn(const char *fmt, ...)
|
||||
mrb_warn(mrb_state *mrb, const char *fmt, ...)
|
||||
{
|
||||
#ifdef ENABLE_STDIO
|
||||
va_list args;
|
||||
va_list ap;
|
||||
mrb_value str;
|
||||
|
||||
va_start(args, fmt);
|
||||
printf("warning: ");
|
||||
vprintf(fmt, args);
|
||||
va_end(args);
|
||||
va_start(ap, fmt);
|
||||
str = mrb_vformat(mrb, fmt, ap);
|
||||
fputs("warning: ", stderr);
|
||||
fwrite(RSTRING_PTR(str), RSTRING_LEN(str), 1, stderr);
|
||||
va_end(ap);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user