Instantiating Rhinoscript Native Objects from Java/Scala

喜欢而已 提交于 2019-11-29 16:39:53

So after much fiddling I've come up with an adequate solution although it did not yield the performance increase I had hoped for (only 10% faster).

The solution is specific to Scala / Lift / Json and is contained in the ScriptingUtil.scala file.

To summarise:

  1. Context.javaToJs() does not seem to work in all cases. (java.lang.RuntimeException: No Context associated with current Thread)
  2. A 'scope' object of type Scriptable is needed. The solution I came up with isn't pretty but it works.
  3. To create a NativeArray:

    val na = new NativeArray(arr)
    na.setPrototype(ScriptableObject.getClassPrototype(scope, "Array"))
    
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!