1 package net.sf.tomp.xtcl.command;
2
3 import net.sf.tomp.xtcl.Context;
4
5 /***
6 * Returns from a function, giving the results back to parent (calling) Context
7 *
8 * @author tomp
9 */
10 public class Ret extends AbstractCommand {
11
12 /*** variables to be returned (copied) to parent Context */
13 protected String[] returns;
14
15 /***
16 * set variables to be returned (copied) to parent Context
17 *
18 * @param r
19 * variables to be returned (copied) to parent Context
20 */
21 public void setReturns(String[] r) {
22 returns = r;
23 }
24
25 /***
26 * Returns from a function, giving the results back to parent (calling)
27 * Context under names $1 .. $n (for n-params)
28 *
29 * @param c
30 * DOCUMENT ME!
31 * @return DOCUMENT ME!
32 * @throws Exception
33 * DOCUMENT ME!
34 */
35 public int execute(Context c) throws Exception {
36 Context prev = c.getPrevious();
37
38 for (int i = 0; i < returns.length; i++) {
39 String k = returns[i];
40 Object v = c.get(k);
41
42 prev.put("$" + (i + 1), v);
43 }
44 return done(c, 0);
45 }
46
47 /***
48 * @return "RETURN (" + listArray(returns) + ")";
49 */
50 public String toString() {
51 return "RETURN (" + listArray(returns) + ")";
52 }
53 }
54
55
56
57
58
59
60
61
62
63
64