01: /*
02: * @(#)exit.java 1.2 04/12/06
03: *
04: * Copyright (c) 1997-2004 Sun Microsystems, Inc. All Rights Reserved.
05: *
06: * See the file "LICENSE.txt" for information on usage and redistribution
07: * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
08: */
09: package org.pnuts.lib;
10:
11: import pnuts.lang.*;
12:
13: public class exit extends PnutsFunction {
14:
15: public exit() {
16: super ("exit");
17: }
18:
19: public boolean defined(int narg) {
20: return (narg == 0 || narg == 1);
21: }
22:
23: protected Object exec(Object args[], Context context) {
24: int nargs = args.length;
25: if (nargs > 1) {
26: undefined(args, context);
27: return null;
28: }
29: int exitStatus = 0;
30: if (nargs == 1) {
31: exitStatus = ((Integer) args[0]).intValue();
32: }
33: System.exit(exitStatus);
34: return null;
35: }
36:
37: public String toString() {
38: return "function exit( { exitCode } )";
39: }
40: }
|