public override object Run(Context ctx, List <object> args) { RAWTable ctx_tbl = set_ctx == null ? new RAWTable(): set_ctx; bool self_is_table = false; if (self_reference != null) { self_is_table = self_reference is RAWTable; if (self_is_table) { ((RAWTable)self_reference).IgnoreGetSelf = true; } ctx_tbl["this"] = self_reference; } else { ctx_tbl["this"] = new RAWNull(); } //ctx_tbl["this"] = self_reference == null ? new RAWNull() : self_reference; RAWTable argstbl = new RAWTable(); for (double i = 0; i < args.Count; i++) { argstbl[i] = args[(int)i]; } ctx_tbl["__args__"] = argstbl; for (int i = 0; i < arg_names.Count; i++) { ctx_tbl[arg_names[i]] = i >= args.Count ? new RAWNull() : args[i]; } ctx.Push(ctx_tbl); try { code.evaluate(ctx); } catch (ReturnError e) { ctx.Pop(); if (self_is_table) { ((RAWTable)self_reference).IgnoreGetSelf = false; } return(e.ReturnValue); } ctx.Pop(); if (self_is_table) { ((RAWTable)self_reference).IgnoreGetSelf = false; } return(new RAWNull()); }
public override object evaluate(Context ctx) { object val = assignval.evaluate(ctx); if (!(val is RAWTable)) { throw new RuntimeError("Tried assinging a property to a non table value"); } RAWTable tbl_val = ((RAWTable)val); if (tbl_val[set_name.lexeme] is GetterSetter g && g.setter != null) { g.Set(val, ctx, value.evaluate(ctx)); }
public void Push(RAWTable ctx = null) { context.Add(ctx == null ? new RAWTable() : ctx); }
public Context(RAWTable global = null) { Push(global); }