====== Groovy Script ====== * [[http://groovy.codehaus.org/Scripts+and+Classes|Groovy - Scripts and Classes]] * [[http://groovy.codehaus.org/Groovy+as+script|Groovy - Groovy as script]] * [[http://groovy.codehaus.org/gapi/groovy/lang/Script.html|groovy.lang.Script]] ===== include functions ===== * 하나의 스크립트에서 다른 스크립트에 정의된 변수,함수들을 사용하려면 [[http://groovy.codehaus.org/gapi/groovy/lang/Script.html#evaluate%28java.lang.String%29|evaluate]]를 사용한다. * 호출측 ''main.groovy'' // 부모 스크립트에 바인딩된 객체를 include 되는 측에서 사용가능한지 테스트 myprint = { arg -> println("# MyPrint : " + arg) } // include 측에서 main.groovy의 def 설정 변수와 메소드를 사용하기위해 parent = this def defprint() { println("# defprint") } // GroovyShell을 사용할 수도 있음. 명시적 Binding 객체로 현재 스크립트의 값들을 넘겨줘야함 //def includeBinding = new Binding(this.binding.variables) //new GroovyShell(includeBinding).evaluate(new File('include.groovy').text) // Script.evaluate 사용. 현재 스크립트의 바인딩이 자동으로 넘어감. evaluate(new File('include.groovy').text) // import.groovy에 선언된 클로저를 그냥 바로 호출할 수 있다. whoami("from script1 한글") calldefprint() * include 대상 스크립트 ''include.groovy'' whoami = { arg -> myprint("# from who am i : " + arg) } calldefprint = { parent.defprint() } * 결과 # MyPrint : # from who am i : from script1 한글 # defprint