DynamicVariable.cs 670 B

1234567891011121314151617181920212223242526
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace NTERA.Engine.Runtime
  7. {
  8. public class DynamicVariable : Variable
  9. {
  10. protected EraRuntime Runtime { get; }
  11. protected Func<EraRuntime, int[], Value> Predicate { get; }
  12. public DynamicVariable(string name, ValueType type, EraRuntime runtime, Func<EraRuntime, int[], Value> predicate) : base(name, type)
  13. {
  14. Runtime = runtime;
  15. Predicate = predicate;
  16. }
  17. public override Value this[params int[] index]
  18. {
  19. get => Predicate(Runtime, index);
  20. set => throw new EraRuntimeException("Cannot assign to a dynamic variable");
  21. }
  22. }
  23. }