Skip to content

Commit d81e4d7

Browse files
committed
Allow true/false argument to Kernel#exit
1 parent 1bb1df1 commit d81e4d7

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

mrbgems/mruby-exit/src/mruby-exit.c

+9-4
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,17 @@
44
static mrb_value
55
f_exit(mrb_state *mrb, mrb_value self)
66
{
7-
mrb_int i = EXIT_SUCCESS;
7+
mrb_value status = mrb_true_value();
8+
int istatus;
9+
10+
mrb_get_args(mrb, "|o", &status);
11+
istatus = mrb_true_p(status) ? EXIT_SUCCESS :
12+
mrb_false_p(status) ? EXIT_FAILURE :
13+
(int)mrb_int(mrb, status);
14+
exit(istatus);
815

9-
mrb_get_args(mrb, "|i", &i);
10-
exit((int)i);
1116
/* not reached */
12-
return mrb_nil_value();
17+
return status;
1318
}
1419

1520
void

0 commit comments

Comments
 (0)