当前位置: 首页>>代码示例>>C#>>正文


C# Thread.Push方法代码示例

本文整理汇总了C#中System.Thread.Push方法的典型用法代码示例。如果您正苦于以下问题:C# Thread.Push方法的具体用法?C# Thread.Push怎么用?C# Thread.Push使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Thread的用法示例。


在下文中一共展示了Thread.Push方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SGsub

        private static int SGsub( Thread l )
        {
            var str = (LString)l[1];
            var pat = (LString)l[2];

            var subst = l[3];
            var subTy = subst.ValueType;

            switch( subTy )
            {
            case LValueType.Number:
                l.ConvertToString( ref subst );
                break;

            case LValueType.String:
            case LValueType.Function:
            case LValueType.Table:
                break;

            default:
                throw new ArgumentException( "string/function/table expected" );
            }

            var max = l.StackTop >= 4 ? (int)l[4] : int.MaxValue;

            MatchState ms;
            InitMatchState( out ms, l );

            ms.Str = str.InternalData;
            ms.StrInit = LString.BufferDataOffset;

            ms.Pat = pat.InternalData;
            int patInit = LString.BufferDataOffset;

            bool anchor = patInit < ms.Pat.Length && ms.Pat[patInit] == (byte)'^';
            if( anchor )
                patInit++;

            var strBuilder = l.GetStrBuilder( str.Length * 2 );

            int sPos = LString.BufferDataOffset;

            int n = 0;
            while( n < max )
            {
                ms.Level = 0;
                Debug.Assert( ms.MatchDepth == MaxCCalls );

                var e = SMatch( ref ms, sPos, patInit );
                if( e != -1 )
                {
                    n++;

                    Value substVal;

                    switch( subTy )
                    {
                    case LValueType.Function:
                        {
                            l.Push( subst );

                            var nCap = PushCaptures( ref ms, sPos, e, false );
                            l.Call( nCap, 1 );

                            substVal = l.PopValue();
                        }
                        break;

                    case LValueType.Table:
                        PushCapture( ref ms, 0, sPos, e );
                        substVal = l.GetTable( (Table)subst, l.PopValue() );
                        break;

                    case LValueType.Number:
                        //it's already been made a string
                        substVal = subst;
                        break;

                    case LValueType.String:
                        //need to handle escape sequences
                        {
                            var sb = (byte[])subst.RefVal;
                            for( int i = LString.BufferDataOffset; i < sb.Length; i++ )
                            {
                                var ch = sb[i];

                                if( ch != (byte)'%' )
                                {
                                    strBuilder.Append( ch );
                                    continue;
                                }

                                if( ++i == sb.Length )
                                    throw new ArgumentException( "Invalid use of % in replacement string" );

                                ch = sb[i];

                                if( ch == (byte)'%' )
                                {
                                    strBuilder.Append( ch );
//.........这里部分代码省略.........
开发者ID:henchmeninteractive,项目名称:HenchLua,代码行数:101,代码来源:StringLib.cs

示例2: PushPop

        public void PushPop()
        {
            var thread = new Thread();

            Assert.AreEqual( 0, thread.StackTop );

            thread.Push( Math.PI );
            Assert.AreEqual( 1, thread.StackTop );

            Assert.AreEqual( Math.PI, thread.PopValue() );
            Assert.AreEqual( 0, thread.StackTop );
        }
开发者ID:henchmeninteractive,项目名称:HenchLua,代码行数:12,代码来源:ThreadTests.cs

示例3: FindCore

        private static int FindCore( Thread l, bool isFind )
        {
            var str = (LString)l[1];
            var pat = (LString)l[2];

            int init = l.StackTop >= 3 ? StrIdxArg( str, (int)l[3] ) : 0;
            if( init == -1 )
                init = 0;

            if( init == str.Length && init != 0 )
                return l.SetNilReturnValue();

            if( isFind && (l[4].ToBool() || !HasPatternSpecials( pat )) )
            {
                //do a plain search
                int idx = str.IndexOf( pat, init );
                if( idx != -1 )
                    return l.SetReturnValues( idx + 1, idx + pat.Length );
                else
                    return l.SetNilReturnValue();
            }
            else
            {
                MatchState ms;
                InitMatchState( out ms, l );

                ms.Str = str.InternalData;
                ms.StrInit = LString.BufferDataOffset;

                ms.Pat = pat.InternalData;
                int patInit = LString.BufferDataOffset;

                bool anchor = patInit < ms.Pat.Length && ms.Pat[patInit] == (byte)'^';
                if( anchor )
                    patInit++;

                int sPos = LString.BufferDataOffset + init;

                do {
                    Debug.Assert( ms.MatchDepth == MaxCCalls );

                    ms.Level = 0;
                    var res = SMatch( ref ms, sPos, patInit );
                    if( res != -1 )
                    {
                        if( isFind )
                        {
                            l.StackTop = 0;
                            l.Push( sPos - LString.BufferDataOffset + 1 );
                            l.Push( res - LString.BufferDataOffset );
                            return PushCaptures( ref ms, -1, -1 ) + 2;
                        }
                        else
                        {
                            return PushCaptures( ref ms, sPos, res );
                        }
                    }
                } while( sPos++ < ms.Str.Length && !anchor );

                RetireMatchState( ref ms );
                return l.SetNilReturnValue();
            }
        }
开发者ID:henchmeninteractive,项目名称:HenchLua,代码行数:63,代码来源:StringLib.cs


注:本文中的System.Thread.Push方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。