summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYukihiro Matsumoto <[email protected]>2012-07-17 23:46:48 +0900
committerYukihiro Matsumoto <[email protected]>2012-07-17 23:46:48 +0900
commit6ea5c6b5172eebd0937710418ad99f82fbcf28e7 (patch)
tree66d05003c6cf57b2fafa650732b000dfb3e008bf
parentcb8fe4400fc2424a71d58411fb720e4507287167 (diff)
downloadmruby-6ea5c6b5172eebd0937710418ad99f82fbcf28e7.tar.gz
mruby-6ea5c6b5172eebd0937710418ad99f82fbcf28e7.zip
make mirb work even when DISABLE_STDIO is set
-rw-r--r--tools/mirb/mirb.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/tools/mirb/mirb.c b/tools/mirb/mirb.c
index 8b36cb5a6..4159f12bd 100644
--- a/tools/mirb/mirb.c
+++ b/tools/mirb/mirb.c
@@ -13,6 +13,19 @@
#include <mruby/data.h>
#include <mruby/compile.h>
+#ifndef ENABLE_STDIO
+#include <mruby/string.h>
+static void
+p(mrb_state *mrb, mrb_value obj)
+{
+ obj = mrb_funcall(mrb, obj, "inspect", 0);
+ fwrite(RSTRING_PTR(obj), RSTRING_LEN(obj), 1, stdout);
+ putc('\n', stdout);
+}
+#else
+#define p(mrb,obj) mrb_p(mrb,obj)
+#endif
+
/* Guess if the user might want to enter more
* or if he wants an evaluation of his code now */
int
@@ -219,13 +232,13 @@ main(void)
mrb_top_self(mrb));
/* did an exception occur? */
if (mrb->exc) {
- mrb_p(mrb, mrb_obj_value(mrb->exc));
+ p(mrb, mrb_obj_value(mrb->exc));
mrb->exc = 0;
}
else {
/* no */
printf(" => ");
- mrb_p(mrb, result);
+ p(mrb, result);
}
}
memset(ruby_code, 0, sizeof(*ruby_code));