28. public IntThing(int i) { val = i; } public IntThing(String s) { val = Integer.parseInt(s); } public static int get(Thing thing) throws HeclException { setIntFromAny(thing); IntThing getint = (IntThing)thing.val; return getint.val; }
29.
30.
31. The Stack proc one {} { set a 2 puts "one $a" two puts "one $a" } proc two {} { set a 4 puts "two $a" three puts "two $a" } proc three {} { set a 6 puts "three $a" } set a 1 set b 2 puts $a one puts $a 1 one 2 two 4 three 6 two 4 one 2 1
32.
33.
34.
35. Embedding Hecl import org.hecl.*; ... Interp interp = new Interp(); new HeclFile().loadModule(interp); new org.hecl.fp.HeclFloat().loadModule(interp); new org.hecl.load.HeclLoad().loadModule(interp); HeclFile.sourceFile(interp, “a_hecl_file.hcl”); ... public void someEventHandler(Event ev) { Eval.eval(eventscript); }
36. Extending Hecl class IncrCmd implements Command { public void cmdCode(Interp interp, Thing[] argv) throws HeclException { int m = IntThing.get(argv[1]); int n = 1; if (argv.length > 2) { n = IntThing.get(argv[2]); } ((IntThing) argv[1].val).set(m + n); return argv[1]; } }