문서의 선택한 두 판 사이의 차이를 보여줍니다.
다음 판 | 이전 판 | ||
groovy:script [2013/07/11 15:55] kwon37xi 새로 만듦 |
groovy:script [2013/07/12 00:51] (현재) kwon37xi [include functions] |
||
---|---|---|---|
줄 3: | 줄 3: | ||
* [[http:// | * [[http:// | ||
* [[http:// | * [[http:// | ||
+ | |||
+ | ===== include functions ===== | ||
+ | * 하나의 스크립트에서 다른 스크립트에 정의된 변수, | ||
+ | * 호출측 '' | ||
+ | // 부모 스크립트에 바인딩된 객체를 include 되는 측에서 사용가능한지 테스트 | ||
+ | myprint = { arg -> | ||
+ | println("# | ||
+ | } | ||
+ | |||
+ | // include 측에서 main.groovy의 def 설정 변수와 메소드를 사용하기위해 | ||
+ | parent = this | ||
+ | def defprint() { | ||
+ | println("# | ||
+ | } | ||
+ | |||
+ | // GroovyShell을 사용할 수도 있음. 명시적 Binding 객체로 현재 스크립트의 값들을 넘겨줘야함 | ||
+ | //def includeBinding = new Binding(this.binding.variables) | ||
+ | //new GroovyShell(includeBinding).evaluate(new File(' | ||
+ | |||
+ | // Script.evaluate 사용. 현재 스크립트의 바인딩이 자동으로 넘어감. | ||
+ | evaluate(new File(' | ||
+ | |||
+ | // import.groovy에 선언된 클로저를 그냥 바로 호출할 수 있다. | ||
+ | whoami(" | ||
+ | calldefprint() | ||
+ | </ | ||
+ | * include 대상 스크립트 '' | ||
+ | whoami = { arg -> | ||
+ | | ||
+ | } | ||
+ | calldefprint = { | ||
+ | parent.defprint() | ||
+ | } | ||
+ | </ | ||
+ | * 결과< | ||
+ | # MyPrint : # from who am i : from script1 한글 | ||
+ | # defprint | ||
+ | </ |