public void ModifierStackWithArray() { ProtoScript.Runners.ProtoScriptRunner fsr = new ProtoScript.Runners.ProtoScriptRunner(); ExecutionMirror mirror = fsr.Execute( @" a; a@init; a@first; [Associative] { a = { {3, 2, 1} => a@init; 1 => a@first; } } ", core, out runtimeCore); Obj o = mirror.GetValue("a@init"); List <Obj> os = mirror.GetArrayElements(o); Assert.IsTrue(os.Count == 3); Assert.IsTrue((Int64)os[0].Payload == 3); Assert.IsTrue((Int64)os[1].Payload == 2); Assert.IsTrue((Int64)os[2].Payload == 1); Assert.IsTrue((Int64)mirror.GetValue("a@first", 0).Payload == 1); }
public void ModifierStackWithArrayAndFunctionReplication() { ProtoScript.Runners.ProtoScriptTestRunner fsr = new ProtoScript.Runners.ProtoScriptTestRunner(); ExecutionMirror mirror = fsr.Execute( @"a@init;a@first;b; [Associative] { def foo : int(x : int) { a = x+2; return = a; } b = { {1,2,3} => a@init; foo(a@init) => a@first; } } ", core); Obj o = mirror.GetValue("a@init"); List <Obj> os = mirror.GetArrayElements(o); Assert.IsTrue(os.Count == 3); Assert.IsTrue((Int64)os[0].Payload == 1); Assert.IsTrue((Int64)os[1].Payload == 2); Assert.IsTrue((Int64)os[2].Payload == 3); o = mirror.GetValue("a@first"); os = mirror.GetArrayElements(o); Assert.IsTrue(os.Count == 3); Assert.IsTrue((Int64)os[0].Payload == 3); Assert.IsTrue((Int64)os[1].Payload == 4); Assert.IsTrue((Int64)os[2].Payload == 5); o = mirror.GetValue("b"); os = mirror.GetArrayElements(o); Assert.IsTrue(os.Count == 3); Assert.IsTrue((Int64)os[0].Payload == 3); Assert.IsTrue((Int64)os[1].Payload == 4); Assert.IsTrue((Int64)os[2].Payload == 5); }
internal bool GetArrayElements(ProtoCore.Lang.Obj stackValue, out List <ProtoCore.Lang.Obj> elements) { elements = null; // Invalidate output argument. if ((null != internalWorker) && internalWorker.IsBusy) { return(false); // Sorry but we're kinda busy right now. } try { if (null != currentWatchedMirror) { elements = currentWatchedMirror.GetArrayElements(stackValue); } } catch (Exception exception) { HandleException(exception); return(false); } return(true); // Call is successful. }