Пример #1
0
        internal void SubspaceReceive(string channel, string type, string data)
        {
            string hook = (string)(VarString)channel;

            foreach (KeyValuePair <int, Language.Program> kv in programs)
            {
                var their_net = kv.Value.scope.globals.meta.string_vars["_parent"].string_vars["net"].string_vars;
                if (their_net["connections"].string_vars.ContainsKey(hook))
                {
                    VarList args   = new VarList();
                    Var     bc_dat = Var.nil;
                    if (type == "text")
                    {
                        bc_dat = new VarString(data);
                    }
                    else if (type == "num")
                    {
                        bc_dat = new VarNumber(double.Parse(data));
                    }
                    else
                    {
                        bc_dat = new VarList();
                        (bc_dat as VarList).privateVariables["subspace_ref"] = data;
                    }
                    args.number_vars[0]         = bc_dat;
                    args.string_vars["message"] = bc_dat;
                    their_net["connections"].string_vars[hook].Call(kv.Value.scope, new Dictionary <int, Var>(), 0, args);
                }
            }
        }
Пример #2
0
 public NumericValueContext(ScriptRunner scriptRunner, double value) : base(scriptRunner)
 {
     _variable = new VarNumber(value);
 }
Пример #3
0
 public bool Equals(VarNumber other)
 {
     if (ReferenceEquals(null, other)) return false;
       if (ReferenceEquals(this, other)) return true;
       return base.Equals(other) && Equals(other.pRECISIONField, pRECISIONField) && Equals(other.sCALEField, sCALEField);
 }
Пример #4
0
        public static VarList Number(VarList globals)
        {
            VarList outp = new VarList();
            Dictionary <string, Var> number = outp.string_vars;

            number["_add[number]"] = new VarFunction(delegate(Scope scope, Dictionary <int, Var> returnTarget, int returnID, VarList arguments){
                VarNumber left         = (VarNumber)arguments.number_vars[0];
                VarNumber right        = (VarNumber)arguments.number_vars[1];
                returnTarget[returnID] = left.data + right.data;
            });
            number["_sub[number]"] = new VarFunction(delegate(Scope scope, Dictionary <int, Var> returnTarget, int returnID, VarList arguments){
                VarNumber left         = (VarNumber)arguments.number_vars[0];
                VarNumber right        = (VarNumber)arguments.number_vars[1];
                returnTarget[returnID] = left.data - right.data;
            });
            number["_mult[number]"] = new VarFunction(delegate(Scope scope, Dictionary <int, Var> returnTarget, int returnID, VarList arguments){
                VarNumber left         = (VarNumber)arguments.number_vars[0];
                VarNumber right        = (VarNumber)arguments.number_vars[1];
                returnTarget[returnID] = left.data * right.data;
            });
            number["_intdiv[number]"] = new VarFunction(delegate(Scope scope, Dictionary <int, Var> returnTarget, int returnID, VarList arguments){
                VarNumber left         = (VarNumber)arguments.number_vars[0];
                VarNumber right        = (VarNumber)arguments.number_vars[1];
                returnTarget[returnID] = (int)(left.data / right.data);
            });
            number["_div[number]"] = new VarFunction(delegate(Scope scope, Dictionary <int, Var> returnTarget, int returnID, VarList arguments){
                VarNumber left         = (VarNumber)arguments.number_vars[0];
                VarNumber right        = (VarNumber)arguments.number_vars[1];
                returnTarget[returnID] = left.data / right.data;
            });
            number["_pow[number]"] = new VarFunction(delegate(Scope scope, Dictionary <int, Var> returnTarget, int returnID, VarList arguments){
                VarNumber left         = (VarNumber)arguments.number_vars[0];
                VarNumber right        = (VarNumber)arguments.number_vars[1];
                returnTarget[returnID] = Math.Pow(left.data, right.data);
            });
            number["_mod[number]"] = new VarFunction(delegate(Scope scope, Dictionary <int, Var> returnTarget, int returnID, VarList arguments){
                VarNumber left         = (VarNumber)arguments.number_vars[0];
                VarNumber right        = (VarNumber)arguments.number_vars[1];
                returnTarget[returnID] = left.data % right.data;
            });
            number["_bitor[number]"] = new VarFunction(delegate(Scope scope, Dictionary <int, Var> returnTarget, int returnID, VarList arguments){
                VarNumber left         = (VarNumber)arguments.number_vars[0];
                VarNumber right        = (VarNumber)arguments.number_vars[1];
                returnTarget[returnID] = ((int)left) | ((int)right);
            });
            number["_bitand[number]"] = new VarFunction(delegate(Scope scope, Dictionary <int, Var> returnTarget, int returnID, VarList arguments){
                VarNumber left         = (VarNumber)arguments.number_vars[0];
                VarNumber right        = (VarNumber)arguments.number_vars[1];
                returnTarget[returnID] = ((int)left) & ((int)right);
            });
            number["_bitxor[number]"] = new VarFunction(delegate(Scope scope, Dictionary <int, Var> returnTarget, int returnID, VarList arguments){
                VarNumber left         = (VarNumber)arguments.number_vars[0];
                VarNumber right        = (VarNumber)arguments.number_vars[1];
                returnTarget[returnID] = ((int)left) ^ ((int)right);
            });
            number["_bitshiftl[number]"] = new VarFunction(delegate(Scope scope, Dictionary <int, Var> returnTarget, int returnID, VarList arguments){
                VarNumber left         = (VarNumber)arguments.number_vars[0];
                VarNumber right        = (VarNumber)arguments.number_vars[1];
                returnTarget[returnID] = ((int)left) << ((int)right);
            });
            number["_bitshiftr[number]"] = new VarFunction(delegate(Scope scope, Dictionary <int, Var> returnTarget, int returnID, VarList arguments){
                VarNumber left         = (VarNumber)arguments.number_vars[0];
                VarNumber right        = (VarNumber)arguments.number_vars[1];
                returnTarget[returnID] = ((int)left) >> ((int)right);
            });
            number["_concat"]     = GenericConcat;
            number["_le[number]"] = new VarFunction(delegate(Scope scope, Dictionary <int, Var> returnTarget, int returnID, VarList arguments){
                VarNumber left         = (VarNumber)arguments.number_vars[0];
                VarNumber right        = (VarNumber)arguments.number_vars[1];
                returnTarget[returnID] = left.data <= right.data ? 1 : 0;
            });
            number["_lt[number]"] = new VarFunction(delegate(Scope scope, Dictionary <int, Var> returnTarget, int returnID, VarList arguments){
                VarNumber left         = (VarNumber)arguments.number_vars[0];
                VarNumber right        = (VarNumber)arguments.number_vars[1];
                returnTarget[returnID] = left.data < right.data ? 1 : 0;
            });
            number["_ge[number]"] = new VarFunction(delegate(Scope scope, Dictionary <int, Var> returnTarget, int returnID, VarList arguments){
                VarNumber left         = (VarNumber)arguments.number_vars[0];
                VarNumber right        = (VarNumber)arguments.number_vars[1];
                returnTarget[returnID] = left.data >= right.data ? 1 : 0;
            });
            number["_gt[number]"] = new VarFunction(delegate(Scope scope, Dictionary <int, Var> returnTarget, int returnID, VarList arguments){
                VarNumber left         = (VarNumber)arguments.number_vars[0];
                VarNumber right        = (VarNumber)arguments.number_vars[1];
                returnTarget[returnID] = left.data > right.data ? 1 : 0;
            });
            number["_eq[number]"] = new VarFunction(delegate(Scope scope, Dictionary <int, Var> returnTarget, int returnID, VarList arguments){
                VarNumber left         = (VarNumber)arguments.number_vars[0];
                VarNumber right        = (VarNumber)arguments.number_vars[1];
                returnTarget[returnID] = left.data == right.data ? 1 : 0;
            });
            number["_ne[number]"] = new VarFunction(delegate(Scope scope, Dictionary <int, Var> returnTarget, int returnID, VarList arguments){
                VarNumber left         = (VarNumber)arguments.number_vars[0];
                VarNumber right        = (VarNumber)arguments.number_vars[1];
                returnTarget[returnID] = left.data != right.data ? 1 : 0;
            });
            number["_eq"] = ReturnZero;
            number["_ne"] = ReturnOne;

            number["_not"] = new VarFunction(delegate(Scope scope, Dictionary <int, Var> returnTarget, int returnID, VarList arguments){
                VarNumber left         = (VarNumber)arguments.number_vars[0];
                returnTarget[returnID] = left.data == 0?1:0;
            });
            number["_unm"] = new VarFunction(delegate(Scope scope, Dictionary <int, Var> returnTarget, int returnID, VarList arguments){
                VarNumber left         = (VarNumber)arguments.number_vars[0];
                returnTarget[returnID] = -left.data;
            });
            number["_len"] = new VarFunction(delegate(Scope scope, Dictionary <int, Var> returnTarget, int returnID, VarList arguments){
                VarNumber left         = (VarNumber)arguments.number_vars[0];
                returnTarget[returnID] = left.data;
            });
            number["_bitnot"] = new VarFunction(delegate(Scope scope, Dictionary <int, Var> returnTarget, int returnID, VarList arguments){
                VarNumber left         = (VarNumber)arguments.number_vars[0];
                returnTarget[returnID] = ~(int)left.data;
            });

            number["_and"] = And;
            number["_or"]  = Or;

            number["_tostring"] = new VarFunction(delegate(Scope scope, Dictionary <int, Var> returnTarget, int returnID, VarList arguments){
                returnTarget[returnID] = new VarString("" + (double)(VarNumber)arguments.number_vars[0]);
            });

            number["_tonumber"] = new VarFunction(delegate(Scope scope, Dictionary <int, Var> returnTarget, int returnID, VarList arguments){
                returnTarget[returnID] = arguments.number_vars[0];
            });
            return(outp);
        }