From 72a6e90d83c28370502e2c681074e617b3788f6c Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Mon, 21 Oct 2013 14:13:08 +0900 Subject: [PATCH] exit functions take an optional argument --- src/system.c | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/src/system.c b/src/system.c index 471ba565..2a469440 100644 --- a/src/system.c +++ b/src/system.c @@ -24,17 +24,41 @@ pic_system_cmdline(pic_state *pic) static pic_value pic_system_exit(pic_state *pic) { - pic_get_args(pic, ""); + pic_value v; + int argc, status = EXIT_SUCCESS; - exit(EXIT_SUCCESS); + argc = pic_get_args(pic, "|o", &v); + if (argc == 1) { + switch (pic_type(v)) { + case PIC_TT_FLOAT: + status = (int)pic_float(v); + break; + default: + break; + } + } + + exit(status); } static pic_value pic_system_emergency_exit(pic_state *pic) { - pic_get_args(pic, ""); + pic_value v; + int argc, status = EXIT_FAILURE; - _Exit(EXIT_FAILURE); + argc = pic_get_args(pic, "|o", &v); + if (argc == 1) { + switch (pic_type(v)) { + case PIC_TT_FLOAT: + status = (int)pic_float(v); + break; + default: + break; + } + } + + _Exit(status); } static pic_value