public static Value Eval(RuntimeInstance inst, string s) { using (new InstanceScope(inst)) { return CodeUnit.GetExpression(s).Eval(); } }
public InstanceScope(RuntimeInstance inst, bool enterFrame) { Instance = inst; Other = ExecutionContext.Current; ExecutionContext.Current = inst; if (enterFrame) Scope = new ExecutionScope(); }
public InstanceScope(RuntimeInstance inst) : this(inst, true) { }
public static IEnumerable<RuntimeInstance> WithInstance(Value v) { if (!v.IsReal) throw new ProgramError(Error.ExpectedObjectId); // Save the last instances being used var c = Current; var o = Other; Other = c; try { switch ((InstanceTarget)(int)v) { case InstanceTarget.Self: yield return c; break; case InstanceTarget.Other: if (o != null) yield return o; break; case InstanceTarget.All: foreach (var i in ExecutionContext.Instances) yield return i; break; case InstanceTarget.Global: throw new ProgramError(Error.GlobalWith); default: if (ExecutionContext.Instances.Any(e => e.id == v)) yield return LibraryContext.Current.InstanceFactory.Instances[v] as RuntimeInstance; else foreach (var i in ExecutionContext.Instances.Where(ii => ii.object_index == v)) yield return i; break; } } finally { // Restore current and other instances Current = c; Other = o; } }
public static IEnumerable <RuntimeInstance> WithInstance(Value v) { if (!v.IsReal) { throw new ProgramError(Error.ExpectedObjectId); } // Save the last instances being used var c = Current; var o = Other; Other = c; try { switch ((InstanceTarget)(int)v) { case InstanceTarget.Self: yield return(c); break; case InstanceTarget.Other: if (o != null) { yield return(o); } break; case InstanceTarget.All: foreach (var i in ExecutionContext.Instances) { yield return(i); } break; case InstanceTarget.Global: throw new ProgramError(Error.GlobalWith); default: if (ExecutionContext.Instances.Any(e => e.id == v)) { yield return(LibraryContext.Current.InstanceFactory.Instances[v] as RuntimeInstance); } else { foreach (var i in ExecutionContext.Instances.Where(ii => ii.object_index == v)) { yield return(i); } } break; } } finally { // Restore current and other instances Current = c; Other = o; } }