コード例 #1
0
        private static InputVar GetVarAtRuntime(InputContext context, object o, string errtype)
        {
            InputVar var = null;

            if (o is InputVar)
            {
                var = o as InputVar;
            }
            else if (o is AccessorResult)
            {
                AccessorResult a = o as AccessorResult;
                if (!a.IsVar)
                {
                    throw new Exception(errtype + " not supported for non-var types.");
                }
                var = a.Var;
            }
            else if (o is string)
            {
                var = context.GetVar(o as string);
                if (var == null)
                {
                    throw new Exception("Var " + o.ToString() + " not found at runtime.");
                }
            }
            if (var == null)
            {
                throw new Exception("Could not parse '" + o.ToString() + "' as var for " + errtype + ".");
            }
            return(var);
        }
コード例 #2
0
ファイル: ExFuncs.cs プロジェクト: n0n4/RelaScript
 public static object AssignAtRuntime(InputContext context, object o, object v, CompileContext precompile)
 {
     if (o is InputVar)
     {
         (o as InputVar).Value = v;
         return(o);
     }
     if (o is AccessorResult)
     {
         AccessorResult a = o as AccessorResult;
         if (a.IsVar)
         {
             a.Var.Value = v;
             return(a.Var.Value);
         }
         if (a.IsFunc)
         {
             // this is why we had to pass in the compile context
             if (v is string)
             {
                 // setting func equal to string decl
                 a.Func.ChangeLine(v as string);
                 context.CompileLine(a.Func);
             }
             else
             {
                 // setting func equal to compile context
                 a.Func.ChangeLine("COMPILED");
                 a.Func.Compile(precompile);
             }
             return(0);
         }
         if (a.IsObject)
         {
             throw new Exception("at-runtime object assignment not supported yet.");
         }
     }
     if (o is string)
     {
         string s = o as string;
         if (s[0] == 'v')
         {
             return(context.SetAndReturnVar(s, v));
         }
         else if (s[0] == 'f')
         {
             if (v is string)
             {
                 context.SetFunc(s, v as string);
                 return(0);
             }
             else
             {
                 context.SetFuncCompiled(s, precompile);
                 return(0);
             }
         }
         else if (s[0] == 'o')
         {
             throw new Exception("at-runtime object assignment not supported yet.");
         }
         throw new Exception("Unrecognized at-runtime assigment: '" + s + "'.");
     }
     throw new Exception("Attempted to assign to unsupported type '" + o.GetType().ToString() + "':'" + o.ToString() + "'.");
 }