Commit 6ae3a1b8 authored by Masaki Muranaka's avatar Masaki Muranaka

Modify API configuration.

  C API mrb_p() is always callable.
  - But it will do nothing when ENABLE_STDIO is not defined.

  Kernel#__printstr__ is always callable.
  - But it will do nothing when ENABLE_STDIO is not defined.
parent 5a025813
...@@ -208,9 +208,7 @@ mrb_exc_raise(mrb_state *mrb, mrb_value exc) ...@@ -208,9 +208,7 @@ mrb_exc_raise(mrb_state *mrb, mrb_value exc)
mrb->exc = (struct RObject*)mrb_object(exc); mrb->exc = (struct RObject*)mrb_object(exc);
exc_debug_info(mrb, mrb->exc); exc_debug_info(mrb, mrb->exc);
if (!mrb->jmp) { if (!mrb->jmp) {
#ifdef ENABLE_STDIO
mrb_p(mrb, exc); mrb_p(mrb, exc);
#endif
abort(); abort();
} }
longjmp(*(jmp_buf*)mrb->jmp, 1); longjmp(*(jmp_buf*)mrb->jmp, 1);
......
...@@ -5,12 +5,12 @@ ...@@ -5,12 +5,12 @@
*/ */
#include "mruby.h" #include "mruby.h"
#ifdef ENABLE_STDIO
#include "mruby/string.h" #include "mruby/string.h"
static void static void
printstr(mrb_state *mrb, mrb_value obj) printstr(mrb_state *mrb, mrb_value obj)
{ {
#ifdef ENABLE_STDIO
struct RString *str; struct RString *str;
char *s; char *s;
int len; int len;
...@@ -21,14 +21,17 @@ printstr(mrb_state *mrb, mrb_value obj) ...@@ -21,14 +21,17 @@ printstr(mrb_state *mrb, mrb_value obj)
len = str->len; len = str->len;
fwrite(s, len, 1, stdout); fwrite(s, len, 1, stdout);
} }
#endif
} }
void void
mrb_p(mrb_state *mrb, mrb_value obj) mrb_p(mrb_state *mrb, mrb_value obj)
{ {
#ifdef ENABLE_STDIO
obj = mrb_funcall(mrb, obj, "inspect", 0); obj = mrb_funcall(mrb, obj, "inspect", 0);
printstr(mrb, obj); printstr(mrb, obj);
putc('\n', stdout); putc('\n', stdout);
#endif
} }
/* 15.3.1.2.9 */ /* 15.3.1.2.9 */
...@@ -54,31 +57,22 @@ mrb_init_print(mrb_state *mrb) ...@@ -54,31 +57,22 @@ mrb_init_print(mrb_state *mrb)
mrb_define_method(mrb, krn, "__printstr__", mrb_printstr, ARGS_REQ(1)); mrb_define_method(mrb, krn, "__printstr__", mrb_printstr, ARGS_REQ(1));
} }
void void
mrb_show_version(mrb_state *mrb) mrb_show_version(mrb_state *mrb)
{ {
printf("mruby - Embeddable Ruby Copyright (c) 2010-2013 mruby developers\n"); static const char version_msg[] = "mruby - Embeddable Ruby Copyright (c) 2010-2013 mruby developers\n";
} mrb_value msg;
void msg = mrb_str_new(mrb, version_msg, sizeof(version_msg) - 1);
mrb_show_copyright(mrb_state *mrb) printstr(mrb, msg);
{
printf("mruby - Copyright (c) 2010-2013 mruby developers\n");
}
#else
void
mrb_p(mrb_state *mrb, mrb_value obj)
{
}
void
mrb_show_version(mrb_state *mrb)
{
} }
void void
mrb_show_copyright(mrb_state *mrb) mrb_show_copyright(mrb_state *mrb)
{ {
static const char copyright_msg[] = "mruby - Copyright (c) 2010-2013 mruby developers\n";
mrb_value msg;
msg = mrb_str_new(mrb, copyright_msg, sizeof(copyright_msg) - 1);
printstr(mrb, msg);
} }
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment