title: How to use local scope variables in Groovy Script Engine?
body: <p>All variables seem to be global in my groovy scripts I run on groovy script engine. I made some groovy class but when I make variables, they can be accessed from everywhere. for exaple.</p>
  
  <pre><code>class test{
    void func1{ a=4 }
    void func2{ print(a) }
  }
  </code></pre>
  
  <p>When I invoke this class function func1 from scala then invoke func2, it results "4". Weird thing is if I declare variables like "def a=0" in the function, the scope of the variable will be limited with in the function.      </p>
  
  <p>I'm loading my groovy scripts from GroovyScriptEngine like this(using scala)</p>
  
  <pre><code>var gse = new GroovyScriptEngine(pathList.toArray)  
  var scriptClass = gse.loadScriptByName(file.getName())
  var i = scriptClass.newInstance().asInstanceOf[GroovyObject] 
  </code></pre>
  
  <p>then using invokeMethod to invoke functions in the groove script class. Is there anyway to make variable scopes limited with in functions by default?</p>