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)
mrb->exc = (struct RObject*)mrb_object(exc);
exc_debug_info(mrb, mrb->exc);
if (!mrb->jmp) {
#ifdef ENABLE_STDIO
mrb_p(mrb, exc);
#endif
abort();
}
longjmp(*(jmp_buf*)mrb->jmp, 1);
......
......@@ -5,12 +5,12 @@
*/
#include "mruby.h"
#ifdef ENABLE_STDIO
#include "mruby/string.h"
static void
printstr(mrb_state *mrb, mrb_value obj)
{
#ifdef ENABLE_STDIO
struct RString *str;
char *s;
int len;
......@@ -21,14 +21,17 @@ printstr(mrb_state *mrb, mrb_value obj)
len = str->len;
fwrite(s, len, 1, stdout);
}
#endif
}
void
mrb_p(mrb_state *mrb, mrb_value obj)
{
#ifdef ENABLE_STDIO
obj = mrb_funcall(mrb, obj, "inspect", 0);
printstr(mrb, obj);
putc('\n', stdout);
#endif
}
/* 15.3.1.2.9 */
......@@ -54,31 +57,22 @@ mrb_init_print(mrb_state *mrb)
mrb_define_method(mrb, krn, "__printstr__", mrb_printstr, ARGS_REQ(1));
}
void
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
mrb_show_copyright(mrb_state *mrb)
{
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)
{
msg = mrb_str_new(mrb, version_msg, sizeof(version_msg) - 1);
printstr(mrb, msg);
}
void
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