Java eval javascript不会运行公共方法

时间:2015-01-11 02:30:50

标签: java javascript eval

创建和设置值有效,但每当我尝试使用Triangle.add()或说t.add()将其添加到列表(当没有通过javascript完成时它工作)它不起作用。继承了eval的javascript代码

    public String code = "" +
        "" +
        "var v = vector;" +
        "v.x = 0;" +
        "v.y = 0;" +
        "v.z = 0;" +
        "var v1 = vector;" +
        "v1.x = 100;" +
        "v1.y = 100;" +
        "v1.z = 100;" +
        "var v2 = vector;" +
        "v2.x = 200;" +
        "v2.y = 200;" +
        "v2.z = 200;" +
        "" +
        "var t = triangle;" +
        "t.a = v;" +
        "t.b = v1;" +
        "t.c = v2;" +
        "t.add();" +
        "print('hey');" +
        "print(t.b.x);" +
        "t.add();" +
        "";

并且是继承它的java代码

public void run() {
    try { 
        ScriptEngine engine = new ScriptEngineManager().getEngineByName ("rhino");
        engine.put("vector", new Vector3f());
        engine.put("triangle", new Triangle(0,0,0,0,0,0,0,0,0,TextureHandler.getHeldTexture(),false));
        engine.eval(code);
    } 
    catch (Exception e) { 
        e.printStackTrace(); 
    } 
}

0 个答案:

没有答案