Update runcmd to actually run comands from input
[clnl] / bin / runcmd.scala
1 #!/bin/sh
2 exec scalas "$0" -q "$@"
3 !#
4
5 /***
6   logLevel := Level.Error
7
8   logLevel in Global := Level.Error
9
10   scalaVersion := "2.10.3"
11
12   libraryDependencies ++= Seq(
13     "asm" % "asm-all" % "3.3.1",
14     "org.picocontainer" % "picocontainer" % "2.13.6",
15     "org.nlogo" % "NetLogo" % "6.0.0-M3" from "http://ccl.northwestern.edu/devel/6.0.0-M3/NetLogo.jar",
16     "org.nlogo" % "NetLogoHeadless" % "6.0.0-M3" from "http://ccl.northwestern.edu/devel/6.0.0-M3/NetLogoHeadless.jar"
17   )
18 */
19
20 import org.nlogo.headless.HeadlessWorkspace
21 import org.nlogo.mirror
22 import org.nlogo.api
23 import org.nlogo.nvm
24 import org.nlogo.util.Utils.url2String
25
26 System.out.println("----")
27 val workspace = HeadlessWorkspace.newInstance
28 workspace.silent = true
29 workspace.openFromSource(url2String("file:resources/empty.nlogo"))
30
31 val commands = io.Source.stdin.getLines.mkString("\n")
32
33 workspace.runCompiledCommands(new api.SimpleJobOwner("test", workspace.world.mainRNG, api.AgentKind.Observer), workspace.compileCommands(commands, api.AgentKind.Observer))
34 mirror.Mirrorables.allMirrorables(workspace.world).map( x => {
35   System.out.print("(")
36   System.out.print(":" + x.kind)
37   System.out.print(" ")
38   System.out.print(x.agentKey.id)
39   System.out.print(" (")
40   x.kind.Variables.values.toSeq.map( k => {
41     System.out.print("(:" + k + " ")
42     System.out.print(x.getVariable(k.id) match {
43       case s: java.lang.String => "\"s\""
44       case d: java.lang.Double => d + "d0"
45       case b: java.lang.Boolean => if(b)"T" else "NIL"
46       case _: org.nlogo.api.ShapeList => ":SHAPELIST"
47       case v => v
48     })
49     System.out.print(") ")
50   })
51   System.out.println(")")
52   
53   })
54
55 /*
56 workspace.runCompiledCommands(new api.SimpleJobOwner("test", workspace.world.mainRNG, api.AgentKind.Observer), workspace.compileCommands("random-seed 15", api.AgentKind.Observer))
57 for(_ <- 1 to 40)
58   System.out.println(workspace.runCompiledReporter(new api.SimpleJobOwner("test", workspace.world.mainRNG, api.AgentKind.Observer), workspace.compileReporter("random-float 30")))
59
60 val m = new org.nlogo.util.MersenneTwisterFast();
61 m.setSeed(15);
62 for(_ <- 1 to 40)
63   System.out.println(30d * m.nextDouble())*/
64
65 workspace.dispose