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());
        }