Calling with array

Jun 24, 2013 at 12:38 PM
I would call one Javascript function passing one or more arrays

I try this but don't work ; can you help me ?
       private void btnRun7_Click(object sender, EventArgs e)
        {
            String MyCode = @"function run(LstIdx,LstData) {

  var i = 0;  
  for(var n=0;n<LstData.length;n++)
  {
     i += LstData[n];
  }

  return i;
}";

            List<Object> LstIdx = new List<Object>() { 11, 12, 13 };
            List<Object> LstData = new List<Object>() { 1, 2, 3, 4, 5 };
            var myLstIdx = GetArray(engine, LstIdx);
            var myLstData = GetArray(engine, LstData);

            TxtCode.Text = MyCode;
            engine.Run(MyCode);
            LblResult.Text = engine.CallFunction("run", myLstIdx, myLstData).ToString();
        }

        /// <summary>
        /// Funzione che ritorna un certo array a partire da una lista di Object
        /// </summary>
        /// <returns></returns>
        private Jint.Native.JsArray GetArray(Jint.JintEngine eng, List<Object> LstObj)
        {
            Jint.Native.JsArray RetVal = eng.Global.ArrayClass.New();
            Jint.Native.JsNumberConstructor xx;

            for (int i = 0; i < LstObj.Count; i++)
            {
                xx = new Jint.Native.JsNumberConstructor(eng.Global);

                xx.New();
                xx.Value = LstObj[i];

                RetVal.put(i, xx);
            }

            return RetVal;
        }
It returns Always 5 (the number of elements ....