Skip to content

Commit

Permalink
Modify API configuration.
Browse files Browse the repository at this point in the history
  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.
  • Loading branch information
monaka committed Mar 4, 2013
1 parent 5a02581 commit 6ae3a1b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 21 deletions.
2 changes: 0 additions & 2 deletions src/error.c
Expand Up @@ -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);
Expand Down
32 changes: 13 additions & 19 deletions src/print.c
Expand Up @@ -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;
Expand All @@ -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 */
Expand All @@ -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

0 comments on commit 6ae3a1b

Please sign in to comment.