예제 #1
0
 public FuncInst(ScriptEngine engine, DeclInstance decl)
     : base(engine)
 {
     _decl = decl;
     base.DefineProperty("class", new PropertyDescriptor("function", PropertyAttributes.Enumerable), true);
     this.PopulateFunctions();
 }
예제 #2
0
      public TopicSetter(ScriptEngine engine, FuncInst funcInst, DeclInstance.PinDecl pinDecl)
        : base(engine) {
        _owner = funcInst;
        _decl = pinDecl;

        if((_decl.flags & DeclInstance.Flags.optional)!=DeclInstance.Flags.optional) {
          _ref=_owner._owner.Get(_decl.name);
        } else {
          _owner._owner.Exist(_decl.name, out _ref);
        }

      }
예제 #3
0
 public FuncInst(ScriptEngine engine, DeclInstance decl)
   : base(engine) {
   _decl=decl;
   base.DefineProperty("class", new PropertyDescriptor("function", PropertyAttributes.Enumerable), true);
   this.PopulateFunctions();
 }
예제 #4
0
 public object Parse(Topic dst, string json) {
   object o=JSONObject.Parse(Engine, json);
   ObjectInstance jo=o as ObjectInstance;
   string jo_class;
   if(jo!=null && (jo_class=jo.GetPropertyValue("class") as string)!=null) {
     switch(jo_class) {
     #region declarer
     case "declarer": {
         DeclInstance di=new DeclInstance();
         di._name=dst.name;
         foreach(var pr in jo.Properties) {
           switch(pr.Name) {
           case "Init": {
               string body=pr.Value as string;
               if(!string.IsNullOrEmpty(body)) {
                 di.InitFunc=Engine.Function.Construct("path", body);
               }
             }
             break;
           case "Calc": {
               string body=pr.Value as string;
               if(!string.IsNullOrEmpty(body)) {
                 di.CalcFunc=Engine.Function.Construct("sender", body);
               }
             }
             break;
           case "Deinit": {
               string body=pr.Value as string;
               if(!string.IsNullOrEmpty(body)) {
                 di.DeinitFunc=Engine.Function.Construct(body);
               }
             }
             break;
           case "class":
             break;
           default: {
               ObjectInstance p=pr.Value as ObjectInstance;
               if(p!=null && p.HasProperty("type")) {
                 var pin =new DeclInstance.PinDecl();
                 pin.name=pr.Name;
                 if(p!=null) {
                   foreach(var pi in p.Properties) {
                     switch(pi.Name) {
                     case "pos":
                       pin.pos=Convert.ToInt32(pi.Value);
                       break;
                     case "type":
                       pin.flags=(DeclInstance.Flags)Convert.ToInt32(pi.Value);
                       break;
                     }
                   }
                 }
                 di._pins.Add(pin);
               }
             }
             break;
           }
         }
         DeclInstance.funcs[di._name]=di;
         return di;
       }
     #endregion declarer
     #region function
     case "function": {
         string jo_decl;
         if((jo_decl=jo.GetPropertyValue("declarer") as string)!=null) {
           DeclInstance decl;
           if(DeclInstance.funcs.TryGetValue(jo_decl, out decl) && decl!=null){
             return new FuncInst(Engine, decl);
           } else {
             Log.Warning("{0}[{1}] - unknown declarer", dst.path, jo_decl);
           }
         }
       }
       break;
     #endregion function
     }
   }
   return o;
 }
예제 #5
0
        public object Parse(Topic dst, string json)
        {
            object         o  = JSONObject.Parse(Engine, json);
            ObjectInstance jo = o as ObjectInstance;
            string         jo_class;

            if (jo != null && (jo_class = jo.GetPropertyValue("class") as string) != null)
            {
                switch (jo_class)
                {
                    #region declarer
                case "declarer": {
                    DeclInstance di = new DeclInstance();
                    di._name = dst.name;
                    foreach (var pr in jo.Properties)
                    {
                        switch (pr.Name)
                        {
                        case "Init": {
                            string body = pr.Value as string;
                            if (!string.IsNullOrEmpty(body))
                            {
                                di.InitFunc = Engine.Function.Construct("path", body);
                            }
                        }
                        break;

                        case "Calc": {
                            string body = pr.Value as string;
                            if (!string.IsNullOrEmpty(body))
                            {
                                di.CalcFunc = Engine.Function.Construct("sender", body);
                            }
                        }
                        break;

                        case "Deinit": {
                            string body = pr.Value as string;
                            if (!string.IsNullOrEmpty(body))
                            {
                                di.DeinitFunc = Engine.Function.Construct(body);
                            }
                        }
                        break;

                        case "class":
                            break;

                        default: {
                            ObjectInstance p = pr.Value as ObjectInstance;
                            if (p != null && p.HasProperty("type"))
                            {
                                var pin = new DeclInstance.PinDecl();
                                pin.name = pr.Name;
                                if (p != null)
                                {
                                    foreach (var pi in p.Properties)
                                    {
                                        switch (pi.Name)
                                        {
                                        case "pos":
                                            pin.pos = Convert.ToInt32(pi.Value);
                                            break;

                                        case "type":
                                            pin.flags = (DeclInstance.Flags)Convert.ToInt32(pi.Value);
                                            break;
                                        }
                                    }
                                }
                                di._pins.Add(pin);
                            }
                        }
                        break;
                        }
                    }
                    DeclInstance.funcs[di._name] = di;
                    return(di);
                }

                    #endregion declarer
                    #region function
                case "function": {
                    string jo_decl;
                    if ((jo_decl = jo.GetPropertyValue("declarer") as string) != null)
                    {
                        DeclInstance decl;
                        if (DeclInstance.funcs.TryGetValue(jo_decl, out decl) && decl != null)
                        {
                            return(new FuncInst(Engine, decl));
                        }
                        else
                        {
                            Log.Warning("{0}[{1}] - unknown declarer", dst.path, jo_decl);
                        }
                    }
                }
                break;
                    #endregion function
                }
            }
            return(o);
        }