// 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();
     }
 }
示例#2
0
 public static Value Eval(RuntimeInstance inst, string s)
 {
     using (new InstanceScope(inst))
     {
         return(CodeUnit.GetExpression(s).Eval());
     }
 }
示例#3
0
 public static void Init(this Room room)
 {
     if (room.CreationCode != null)
     {
         using (new InstanceScope(LibraryContext.Current.InstanceFactory.CreatePrivateInstance() as RuntimeInstance))
         {
             CodeUnit.Get(room).Run();
         }
     }
 }
示例#4
0
        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);
        }
示例#5
0
 public static Value EvalCode(this IGml codeObject)
 {
     return(CodeUnit.GetExpression(codeObject).Eval());
 }
示例#6
0
 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);
 }
示例#8
0
        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;
        }
示例#9
0
 public static void Run(this CodeUnit unit)
 {
     (unit.ParseTree as Statement).Execute();
 }
示例#10
0
 public static Value Eval(this CodeUnit unit)
 {
     return((unit.ParseTree as Expression).Eval());
 }
示例#11
0
 public ScriptFunction(string name, string code) : base(name, -1)
 {
     Code = code;
     Unit = CodeUnit.Get(this);
 }