// Execute a string. The string is cached, and subsequent calls of Exec() with the same code string // execute code that is already compiled and cached. Code that is executed from a known location, i.e., a script, // is recommended to have its own local code unit, so it does not have to be looked up in a table. public static void Exec(this RuntimeInstance i, string s) { using (new InstanceScope(i)) { CodeUnit.Get(s).Run(); } }
public static Value Eval(RuntimeInstance inst, string s) { using (new InstanceScope(inst)) { return(CodeUnit.GetExpression(s).Eval()); } }
public static void Init(this Room room) { if (room.CreationCode != null) { using (new InstanceScope(LibraryContext.Current.InstanceFactory.CreatePrivateInstance() as RuntimeInstance)) { CodeUnit.Get(room).Run(); } } }
static CodeUnit Get(object obj, bool isExpression) { if (!(obj is string || obj is IGml)) { throw new InvalidOperationException(); } CodeUnit unit; if (!CodeUnits.TryGetValue(obj, out unit)) { unit = new CodeUnit(obj, isExpression); CodeUnits.Add(obj, unit); } return(unit); }
public static Value EvalCode(this IGml codeObject) { return(CodeUnit.GetExpression(codeObject).Eval()); }
public static void ExecuteCode(this IGml codeObject) { CodeUnit.Get(codeObject).Run(); }
public ScriptFunction(string name, string code) : base(name, -1) { Code = code; Unit = CodeUnit.Get(this); }
static CodeUnit Get(object obj, bool isExpression) { if (!(obj is string || obj is IGml)) throw new InvalidOperationException(); CodeUnit unit; if (!CodeUnits.TryGetValue(obj, out unit)) { unit = new CodeUnit(obj, isExpression); CodeUnits.Add(obj, unit); } return unit; }
public static void Run(this CodeUnit unit) { (unit.ParseTree as Statement).Execute(); }
public static Value Eval(this CodeUnit unit) { return((unit.ParseTree as Expression).Eval()); }
public ScriptFunction(string name, string code) : base(name, -1) { Code = code; Unit = CodeUnit.Get(this); }