Load() public method

public Load ( Dsl messageHandlerData ) : void
messageHandlerData Dsl
return void
Ejemplo n.º 1
0
 static public int Load(IntPtr l)
 {
     try {
         int argc = LuaDLL.lua_gettop(l);
         if (matchType(l, argc, 2, typeof(Dsl.StatementData)))
         {
             StorySystem.StoryMessageHandler self = (StorySystem.StoryMessageHandler)checkSelf(l);
             Dsl.StatementData a1;
             checkType(l, 2, out a1);
             self.Load(a1);
             pushValue(l, true);
             return(1);
         }
         else if (matchType(l, argc, 2, typeof(Dsl.FunctionData)))
         {
             StorySystem.StoryMessageHandler self = (StorySystem.StoryMessageHandler)checkSelf(l);
             Dsl.FunctionData a1;
             checkType(l, 2, out a1);
             self.Load(a1);
             pushValue(l, true);
             return(1);
         }
         pushValue(l, false);
         LuaDLL.lua_pushstring(l, "No matched override function to call");
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 public bool Init(Dsl.DslInfo config)
 {
     bool ret = false;
     Dsl.FunctionData story = config.First;
     if (null != story && (story.GetId() == "story" || story.GetId() == "script")) {
         ret = true;
         Dsl.CallData callData = story.Call;
         if (null != callData && callData.HaveParam()) {
             m_StoryId = callData.GetParamId(0);
         }
         for (int i = 0; i < story.Statements.Count; i++) {
             if (story.Statements[i].GetId() == "local") {
                 Dsl.FunctionData sectionData = story.Statements[i] as Dsl.FunctionData;
                 if (null != sectionData) {
                     for (int j = 0; j < sectionData.Statements.Count; j++) {
                         Dsl.CallData defData = sectionData.Statements[j] as Dsl.CallData;
                         if (null != defData && defData.HaveId() && defData.HaveParam()) {
                             string id = defData.GetId();
                             if (id.StartsWith("@") && !id.StartsWith("@@")) {
                                 StoryValue val = new StoryValue();
                                 val.InitFromDsl(defData.GetParam(0));
                                 if (!m_PreInitedLocalVariables.ContainsKey(id)) {
                                     m_PreInitedLocalVariables.Add(id, val.Value);
                                 } else {
                                     m_PreInitedLocalVariables[id] = val.Value;
                                 }
                             }
                         }
                     }
                 } else {
     #if DEBUG
                     string err = string.Format("Story {0} DSL, local must be a function ! line:{1} local:{2}", m_StoryId, story.Statements[i].GetLine(), story.Statements[i].ToScriptString());
                     throw new Exception(err);
     #else
                     LogSystem.Error("Story {0} DSL, local must be a function !", m_StoryId);
     #endif
                 }
             } else if (story.Statements[i].GetId() == "onmessage" || story.Statements[i].GetId() == "onnamespacedmessage") {
                 StoryMessageHandler handler = null;
                 Dsl.StatementData msgData = story.Statements[i] as Dsl.StatementData;
                 if (null != msgData) {
                     handler = new StoryMessageHandler();
                     handler.Load(msgData);
                 } else {
                     Dsl.FunctionData sectionData = story.Statements[i] as Dsl.FunctionData;
                     if (null != sectionData) {
                         handler = new StoryMessageHandler();
                         handler.Load(sectionData);
                     }
                 }
                 if (null != handler) {
                     string msgId;
                     if (!string.IsNullOrEmpty(m_Namespace) && story.Statements[i].GetId() == "onnamespacedmessage") {
                         msgId = string.Format("{0}:{1}", m_Namespace, handler.MessageId);
                         handler.MessageId = msgId;
                     } else {
                         msgId = handler.MessageId;
                     }
                     if (!m_MessageQueues.ContainsKey(msgId)) {
                         m_MessageHandlers.Add(handler);
                         m_MessageQueues.Add(msgId, new Queue<MessageInfo>());
                     } else {
     #if DEBUG
                         string err = string.Format("Story {0} DSL, onmessage or onnamespacedmessage {1} duplicate, discard it ! line:{2}", m_StoryId, msgId, story.Statements[i].GetLine());
                         throw new Exception(err);
     #else
                         LogSystem.Error("Story {0} DSL, onmessage {1} duplicate, discard it !", m_StoryId, msgId);
     #endif
                     }
                 } else {
     #if DEBUG
                     string err = string.Format("Story {0} DSL, onmessage must be a function or statement ! line:{1} onmessage:{2}", m_StoryId, story.Statements[i].GetLine(), story.Statements[i].ToScriptString());
                     throw new Exception(err);
     #else
                     LogSystem.Error("Story {0} DSL, onmessage must be a function !", m_StoryId);
     #endif
                 }
             } else {
     #if DEBUG
                 string err = string.Format("StoryInstance::Init, Story {0} unknown part {1}, line:{2} section:{3}", m_StoryId, story.Statements[i].GetId(), story.Statements[i].GetLine(), story.Statements[i].ToScriptString());
                 throw new Exception(err);
     #else
                 LogSystem.Error("StoryInstance::Init, Story {0} unknown part {1}", m_StoryId, story.Statements[i].GetId());
     #endif
             }
         }
     } else {
     #if DEBUG
         string err = string.Format("StoryInstance::Init, isn't story DSL, line:{0} story:{1}", story.GetLine(), story.ToScriptString());
         throw new Exception(err);
     #else
         LogSystem.Error("StoryInstance::Init, isn't story DSL");
     #endif
     }
     LogSystem.Debug("StoryInstance.Init message handler num:{0} {1}", m_MessageHandlers.Count, ret);
     return ret;
 }
        public bool Init(Dsl.DslInfo config)
        {
            if (null == config || null == config.First)
            {
                return(false);
            }
            bool ret = false;

            Dsl.FunctionData story = config.First;
            if (story.GetId() == "story" || story.GetId() == "script")
            {
                ret = true;
                Dsl.CallData callData = story.Call;
                if (null != callData && callData.HaveParam())
                {
                    m_StoryId = callData.GetParamId(0);
                }
                for (int i = 0; i < story.Statements.Count; i++)
                {
                    if (story.Statements[i].GetId() == "local")
                    {
                        Dsl.FunctionData sectionData = story.Statements[i] as Dsl.FunctionData;
                        if (null != sectionData)
                        {
                            for (int j = 0; j < sectionData.Statements.Count; j++)
                            {
                                Dsl.CallData defData = sectionData.Statements[j] as Dsl.CallData;
                                if (null != defData && defData.HaveId() && defData.HaveParam())
                                {
                                    string id = defData.GetId();
                                    if (id.StartsWith("@") && !id.StartsWith("@@"))
                                    {
                                        StoryValue val = new StoryValue();
                                        val.InitFromDsl(defData.GetParam(0));
                                        if (!m_PreInitedLocalVariables.ContainsKey(id))
                                        {
                                            m_PreInitedLocalVariables.Add(id, val.Value);
                                        }
                                        else
                                        {
                                            m_PreInitedLocalVariables[id] = val.Value;
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
#if DEBUG
                            string err = string.Format("Story {0} DSL, local must be a function ! line:{1} local:{2}", m_StoryId, story.Statements[i].GetLine(), story.Statements[i].ToScriptString(false));
                            throw new Exception(err);
#else
                            LogSystem.Error("Story {0} DSL, local must be a function !", m_StoryId);
#endif
                        }
                    }
                    else if (story.Statements[i].GetId() == "onmessage" || story.Statements[i].GetId() == "onnamespacedmessage")
                    {
                        StoryMessageHandler handler = null;
                        Dsl.StatementData   msgData = story.Statements[i] as Dsl.StatementData;
                        if (null != msgData)
                        {
                            handler = new StoryMessageHandler();
                            handler.Load(msgData);
                        }
                        else
                        {
                            Dsl.FunctionData sectionData = story.Statements[i] as Dsl.FunctionData;
                            if (null != sectionData)
                            {
                                handler = new StoryMessageHandler();
                                handler.Load(sectionData);
                            }
                        }
                        if (null != handler)
                        {
                            string msgId;
                            if (!string.IsNullOrEmpty(m_Namespace) && story.Statements[i].GetId() == "onnamespacedmessage")
                            {
                                msgId             = string.Format("{0}:{1}", m_Namespace, handler.MessageId);
                                handler.MessageId = msgId;
                            }
                            else
                            {
                                msgId = handler.MessageId;
                            }
                            if (!m_LoadedMessageHandlers.ContainsKey(msgId))
                            {
                                m_LoadedMessageHandlers.Add(msgId, handler);
                                m_MessageHandlers.Add(handler.Clone());
                                m_MessageQueues.Add(msgId, new Queue <MessageInfo>());
                                m_ConcurrentMessageQueues.Add(msgId, new Queue <MessageInfo>());
                                m_ConcurrentMessageHandlerPool.Add(msgId, new Queue <StoryMessageHandler>());
                            }
                            else
                            {
#if DEBUG
                                string err = string.Format("Story {0} DSL, onmessage or onnamespacedmessage {1} duplicate, discard it ! line:{2}", m_StoryId, msgId, story.Statements[i].GetLine());
                                throw new Exception(err);
#else
                                LogSystem.Error("Story {0} DSL, onmessage {1} duplicate, discard it !", m_StoryId, msgId);
#endif
                            }
                        }
                        else
                        {
#if DEBUG
                            string err = string.Format("Story {0} DSL, onmessage must be a function or statement ! line:{1} onmessage:{2}", m_StoryId, story.Statements[i].GetLine(), story.Statements[i].ToScriptString(false));
                            throw new Exception(err);
#else
                            LogSystem.Error("Story {0} DSL, onmessage must be a function !", m_StoryId);
#endif
                        }
                    }
                    else
                    {
#if DEBUG
                        string err = string.Format("StoryInstance::Init, Story {0} unknown part {1}, line:{2} section:{3}", m_StoryId, story.Statements[i].GetId(), story.Statements[i].GetLine(), story.Statements[i].ToScriptString(false));
                        throw new Exception(err);
#else
                        LogSystem.Error("StoryInstance::Init, Story {0} unknown part {1}", m_StoryId, story.Statements[i].GetId());
#endif
                    }
                }
            }
            else
            {
#if DEBUG
                string err = string.Format("StoryInstance::Init, isn't story DSL, line:{0} story:{1}", story.GetLine(), story.ToScriptString(false));
                throw new Exception(err);
#else
                LogSystem.Error("StoryInstance::Init, isn't story DSL");
#endif
            }
            LogSystem.Debug("StoryInstance.Init message handler num:{0} {1}", m_MessageHandlers.Count, ret);
            return(ret);
        }