コード例 #1
0
 public VarEvent() : base(){
     type = "event";
     callbacks = new List<Var>();
     string_vars["hook"] = new VarFunction(delegate(Scope scope, Dictionary<int, Var> returnTarget, int returnID, VarList arguments){
         returnTarget[returnID] = nil;
         if(arguments.number_vars.Count > 0){
             Hook(arguments.number_vars[0]);
             returnTarget[returnID] = arguments.number_vars[0];
         }
     });
     string_vars["call"] = new VarFunction(delegate(Scope scope, Dictionary<int, Var> returnTarget, int returnID, VarList arguments){
         Call(scope, returnTarget, returnID, arguments);
     });
 }
コード例 #2
0
        public void Get(Scope scope, Dictionary<int, Var> returnTarget, int returnID, Var key, bool force, bool curry){
            if(curry){
                scope.callstack.Push(new DoLater(delegate{
                    Var val = returnTarget[returnID];
                    returnTarget[returnID] = new VarFunction(delegate(Scope sub_scope, Dictionary<int, Var> sub_returnTarget, int sub_returnID, VarList arguments){
                        int max_arg = 0;
                        while(arguments.number_vars.ContainsKey(max_arg))
                            max_arg++;
                        for(int i=max_arg; i>0; i--)
                            arguments.number_vars[i] = arguments.number_vars[i-1];
                        arguments.number_vars[0] = this;
                        val.Call(scope, sub_returnTarget, sub_returnID, arguments);
                    });
                }));
            }
            if(this == nil){
                returnTarget[returnID] = nil;
                return;
            }

            if(key is VarNumber){
                double k = ((VarNumber)key).data;
                if(number_vars.ContainsKey(k)){
                    returnTarget[returnID] = number_vars[k];
                    return;
                }
            }else if(key is VarString){
                string k = ((VarString)key).data;
                if(string_vars.ContainsKey(k)){
                    returnTarget[returnID] = string_vars[k];
                    return;
                }
            }else{
                if(other_vars.ContainsKey(key)){
                    returnTarget[returnID] = other_vars[key];
                    return;
                }
            }

            if(!force){
                Var parent = GetMeta(scope, "_parent");
                if(parent != nil){
                    scope.callstack.Push(new DoLater(delegate{
                        parent.Get(scope, returnTarget, returnID, key);
                    }));
                    return;
                }
                Var index = GetMeta(scope, "_index");
                if(index != nil){
                    scope.callstack.Push(new DoLater(delegate{
                        if(index is VarList)
                            index.Get(scope, returnTarget, returnID, key);
                        else
                            index.Call(scope, returnTarget, returnID, this, key);
                    }));
                    return;
                }
            }

            returnTarget[returnID] = nil;
            return;
        }