public bool SetFunc(string name, string source, bool originator = true) { if (originator) { name = name.ToLower(); } if (!Funcs.TryGetValue(name, out Exline func)) { // if any parent scope has the func, set it there // pass originator as false so that if they don't have the func, // we won't try to define it in a parent scope. if (ParentScope != null && ParentScope.SetFunc(name, source, false)) { return(true); } // if we are the calling scope, just define the func if (originator) { DefineFunc(name, source); } return(false); } func.ChangeLine(source); CompileLine(func); return(true); }
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 SetFunc(string funcname, string line, InputContext context) { context.SetFunc(funcname, line); return(0); }