사용자 도구

사이트 도구


groovy:script

차이

문서의 선택한 두 판 사이의 차이를 보여줍니다.

차이 보기로 링크

다음 판
이전 판
groovy:script [2013/07/11 15:55]
kwon37xi 새로 만듦
groovy:script [2013/07/12 00:51]
kwon37xi [include functions]
줄 3: 줄 3:
   * [[http://groovy.codehaus.org/Groovy+as+script|Groovy - Groovy as script]]   * [[http://groovy.codehaus.org/Groovy+as+script|Groovy - Groovy as script]]
   * [[http://groovy.codehaus.org/gapi/groovy/lang/Script.html|groovy.lang.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''<code 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()
 +</code>
 +  * include 대상 스크립트 ''include.groovy''<code groovy>
 +whoami = { arg ->
 +   myprint("# from who am i : " + arg)
 +}
 +calldefprint = {
 +    parent.defprint()
 +}
 +</code>
 +  * 결과<code>
 +# MyPrint : # from who am i : from script1 한글
 +# defprint
 +</code>
groovy/script.txt · 마지막으로 수정됨: 2013/07/12 00:51 저자 kwon37xi