title: How can I pass objects to an exposed luaj function?
body: <p>I am trying to build a controller using Luaj + java. I have the following java classes</p>
  
  <pre><code>public class Duck {
    public void talk() { System.out.println("Duck quacks!"); }
    public void walk() { System.out.println("Duck walks!"); }
  }
  
  public class Person {
    public void talk() { System.out.println("Person talks!"); }
    public void walk() { System.out.println("Person walks!"); }
  }
  </code></pre>
  
  <p>and the following lua script for the controller:</p>
  
  <pre><code>onTalk(obj) 
    obj:talk();
  end
  
  onWalk(obj)
     obj:walk();
  end
  </code></pre>
  
  <p>I would ideally like to define one controller (written in lua) where I will keep all of the program's logic, and I would like to expose API from that controller to my java code. I was trying to use the following approach:</p>
  
  <pre><code>ScriptEngineManager sem     = new ScriptEngineManager();
  ScriptEngine        engine  = sem.getEngineByExtension(".lua");
  ScriptEngineFactory factory = engine.getFactory();
  
  // Script defined above
  CompiledScript cs = ((Compilable)engine).compile(MY_LUA_SCRIPT);
  SimpleBindings b = new SimpleBindings();
  
  b = newSimpletBindings();
  
  LuaValue onWalkHandler = (LuaValue)b.get("onWalk");
  //func.call(LuaValue.valueOf(duck)); // Passing duck object does not work ???
  </code></pre>
  
  <p>I am not able to pass the object to the LuaValue. How can I pass a java object to the lua script?</p>
  
  <p>PS: In general, when using Java and embedded scripting, do people bundle functions in one script, or is there a separate script for every callback?</p>