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() + "'."); }
public static object SetFuncCompiled(string funcname, CompileContext precompile, InputContext context) { context.SetFuncCompiled(funcname, precompile); return(0); }