Ejemplo n.º 1
0
        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());
        }
Ejemplo n.º 2
0
        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));
            }
Ejemplo n.º 3
0
 public void Push(RAWTable ctx = null)
 {
     context.Add(ctx == null ? new RAWTable() : ctx);
 }
Ejemplo n.º 4
0
 public Context(RAWTable global = null)
 {
     Push(global);
 }