# -*- e -*- # hello world # print a simple string on stdout println("Hello World") # argv # access command line parameters (no segmentation fault accepted, nor silent exception, so some languages must explicitly check the presence of the argument) println(interp.getArgs()[0]) # env # access environment variable # Only when run on Java1.5 println(.getenv("HOME")) # test file exists # return exit code error (non zero) if a file does not exist require(.exists()) # test file readable # return exit code error (non zero) if a file is not readable require(.canRead()) # formatting # print integers in a simple formatted string def a := 1 def b := 2 println(`$a + $b = ${a + b}`) # system # call an external program and check the return value def runFalse := makeCommand("/bin/false") def runEcho := makeCommand("/bin/echo") def ok := try { runFalse() true } catch ex { stderr.println("false failed") false } if (ok) { println(runEcho("done")[0]) } # sed in place # remove #-comments from a file (modifying the file, i.e. in place) def f := var text := "" for line in f { if (line =~ `@left#@right`) { text += left + "\n" } else { text += line } } f.setText(text) # compile what must be # find and compile .c files into .o when the .o is old or absent def runGcc := makeCommand("c:/cygwin/bin/gcc.exe") def leaves := for c in leaves() { if (c.getPath() =~ `@base.c`) { def tmp := if (!tmp.exists() || tmp.lastModified() < c.lastModified()) { println(`compiling $base.c to $base.o`) try { runGcc("-c", `$base.c`, "-o", `$base.o`) } catch ex { stderr.println(`$base.c failed with $ex`) } } } }