public Dsl.FunctionData InitFromDsl(Dsl.ISyntaxComponent param, int startIndex, bool enableComments)
 {
     Dsl.FunctionData ret      = null;
     Dsl.FunctionData callData = param as Dsl.FunctionData;
     if (null == callData && enableComments)
     {
         var statementData = param as Dsl.StatementData;
         if (null != statementData && statementData.GetFunctionNum() == 2)
         {
             var first = statementData.First;
             var last  = statementData.Last;
             if (!first.HaveStatement() && (last.GetId() == "comment" || last.GetId() == "comments"))
             {
                 ret = last;
                 statementData.Functions.RemoveAt(1);
                 callData = first;
             }
         }
     }
     if (null != callData)
     {
         for (int i = startIndex; i < callData.GetParamNum(); ++i)
         {
             StoryValue <P> val = new StoryValue <P>();
             val.InitFromDsl(callData.GetParam(i));
             m_Args.Add(val);
             m_Values.Add(default(P));
         }
     }
     return(ret);
 }
 static public int InitFromDsl(IntPtr l)
 {
     try {
         StorySystem.StoryValue self = (StorySystem.StoryValue)checkSelf(l);
         Dsl.ISyntaxComponent   a1;
         checkType(l, 2, out a1);
         self.InitFromDsl(a1);
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
        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);
        }