title: Using LuaJ with Scala
body: <p>I am attempting to use LuaJ with Scala. Most things work (actually all things work if you do them correctly!) but the simple task of setting object values has become incredibly complicated thanks to Scala's setter implementation.</p>
  
  <p>Scala:</p>
  
  <pre><code>class TestObject {
    var x: Int = 0
  }
  </code></pre>
  
  <p>Lua:</p>
  
  <pre><code>function myTestFunction(testObject) 
    testObject.x = 3
  end
  </code></pre>
  
  <p>If I execute the script or line containing this Lua function and pass a coerced instance of TestObject to myTestFunction this causes an error in LuaJ. LuaJ is trying to direct-write the value, and Scala requires you to go through the implicitly-defined setter (with the horrible name x_=, which is not valid Lua so even attempting to call that as a function makes your Lua not parse).</p>
  
  <p>As I said, there are workarounds for this, such as defining your own setter or using the @BeanProperty markup. They just make code that should be easy to write much more complicated:</p>
  
  <p>Lua:</p>
  
  <pre><code>function myTestFunction(testObject) 
    testObject.setX(testObject, 3)
  end
  </code></pre>
  
  <p>Does anybody know of a way to get luaj to implicitly call the setter for such assignments? Or where I might look in the luaj source code to perhaps implement such a thing?</p>
  
  <p>Thanks!</p>