Calling this function in Android using Rhino -


i working on project need download javascript , use calculate values. working on ios javascript seems fine.

here stripped down javascript (i have removed content not own script):

var resultarray = [];  function calculateremainingamountforforecastweeks(numberofweeks, weeklydisposable, easing, safetyzone, safetyzoneeasing, overspentthisweek) {   // calculations...   resultarray[numberofweeks] = spentbeyondforecast; }

i using rhino , here do:

org.mozilla.javascript.context rhino = org.mozilla.javascript.context.enter(); rhino.setoptimizationlevel(-1); try {   scriptable scope = rhino.initstandardobjects();   rhino.evaluatestring(scope, weeklyapplication.getcalculatorjs(), "javascript", 0, null);   object obj = scope.get("calculateremainingamountforforecastweeks", scope);   if (obj instanceof function) {     function jsfunction = (function) obj;     // call function params     object[] params = new object[]{numberofweeks, weeklydisposable, easing, safetyzone, safetyzoneeasing, overspentthisweek};     object jsresult = jsfunction.call(rhino, scope, scope, params);     // parse jsresult object string     string result = org.mozilla.javascript.context.tostring(jsresult);     log.d(tag, "skn-calculate3=" + result);   } } {   org.mozilla.javascript.context.exit(); }

i know not optimized use of scope here, need working first. keep getting "undefined" in result string, doing wrong here?

and when working, how values stored in "resultarray"?

thank you
søren

from code posted, looks function calculateremainingamountforforecastweeks() doesn't return anything, it's ok undefined it.

getting value resultarray easy, it's field in scope scriptable object:

object[] params = new object[]{numberofweeks, weeklydisposable, easing, safetyzone, safetyzoneeasing, overspentthisweek}; // function doesn't return jsfunction.call(rhino, scope, scope, params); nativearray resultarray = (nativearray) scope.get("resultarray", scope); double result = ((number) resultarray.get(numberofweeks)).getdoublevalue(); log.d(tag, "skn-calculate3=" + result); 

note: of course, don't know types are, you'd have update snippet make work you.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -