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


C# Thread.Call方法代码示例

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


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

示例1: CallbackReturn

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

            var globals = new Table();
            var func = Helpers.LoadFunc( "Thread/CallbackReturn.lua", globals );

            int numCallbacks = 0;
            globals[new LString( "callback" )] = (Callable)(l =>
            {
                Assert.AreEqual( 3, l.StackTop );

                for( int i = 1; i <= 3; i++ )
                    l.Push( l[i].ToDouble() + i );

                numCallbacks++;
                return 3;
            });

            thread.Call( func, 0, 3 );

            Assert.AreEqual( 2, numCallbacks );

            Assert.AreEqual( 42, thread[1] );
            Assert.AreEqual( 54, thread[2] );
            Assert.AreEqual( 66, thread[3] );
        }
开发者ID:henchmeninteractive,项目名称:HenchLua,代码行数:27,代码来源:ThreadTests.cs

示例2: RunTestScriptWithGlobals

        private static void RunTestScriptWithGlobals( string script, Table globals, params Value[] expectedResults )
        {
            Libs.BaseLib.SetBaseMethods( globals );
            Libs.MathLib.SetMathMethods( globals );
            Libs.TableLib.SetTableMethods( globals );
            Libs.StringLib.SetStringMethods( globals );

            globals["print"] = (Callable)(l => 0);
            globals["assert"] = (Callable)(l =>
            {
                if( !l[1].ToBool() )
                    Assert.Fail();
                return 0;
            });

            var thread = new Thread();

            var func = Helpers.LoadFunc( "lua-core/" + script, globals );
            Function.Optimize( func );

            thread.Call( func, 0, Thread.CallReturnAll );

            Assert.AreEqual( expectedResults.Length, thread.StackTop );
            for( int i = 0; i < expectedResults.Length; i++ )
                Assert.AreEqual( expectedResults[i], thread[i + 1] );
        }
开发者ID:henchmeninteractive,项目名称:HenchLua,代码行数:26,代码来源:CoreTests.cs

示例3: Callback2

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

            var globals = new Table();
            var func = Helpers.LoadFunc( "Thread/Callback.lua", globals );

            var fn = new CallbackFunc();
            globals[new LString( "callback" )] = (Callable)fn;

            thread.Call( func, 0, 0 );

            Assert.AreEqual( 1, fn.RunCount );
        }
开发者ID:henchmeninteractive,项目名称:HenchLua,代码行数:14,代码来源:ThreadTests.cs

示例4: RunTestScript

        private static void RunTestScript( string script, params Value[] expectedResults )
        {
            var thread = new Thread();

            var globals = new Table();
            Libs.BaseLib.SetBaseMethods( globals );

            var func = Helpers.LoadFunc( "MetaTable/" + script, globals );
            Function.Optimize( func );

            thread.Call( func, 0, Thread.CallReturnAll );

            Assert.AreEqual( expectedResults.Length, thread.StackTop );
            for( int i = 0; i < expectedResults.Length; i++ )
                Assert.AreEqual( expectedResults[i], thread[i + 1] );
        }
开发者ID:henchmeninteractive,项目名称:HenchLua,代码行数:16,代码来源:MetaTableTests.cs

示例5: Callback1

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

            var globals = new Table();
            var func = Helpers.LoadFunc( "Thread/Callback.lua", globals );

            int numCallbacks = 0;
            globals[new LString( "callback" )] = (Callable)(l =>
            {
                Assert.AreEqual( 1, l.StackTop );
                Assert.AreEqual( 42, l[1] );

                numCallbacks++;
                return 0;
            });

            thread.Call( func, 0, 0 );

            Assert.AreEqual( 1, numCallbacks );
        }
开发者ID:henchmeninteractive,项目名称:HenchLua,代码行数:21,代码来源:ThreadTests.cs

示例6: BPairs

        private static int BPairs( Thread l )
        {
            var val = l[1];
            var mt = GetMetatableImp( val );

            Value mmt;
            if( mt != null && mt.TryGetValue( Literals.TagMethod_Pairs, out mmt ) )
            {
                l.StackTop = 1;
                l.Call( (Callable)mmt, 1, 3 );
            }
            else
            {
                l.SetStack( (Callable)new StableNext(),
                    val, Value.Nil );
            }

            return 3;
        }
开发者ID:henchmeninteractive,项目名称:HenchLua,代码行数:19,代码来源:BaseLib.cs

示例7: BIPairs

        private static int BIPairs( Thread l )
        {
            var val = l[1];
            var mt = GetMetatableImp( val );

            Value mmt;
            if( mt != null && mt.TryGetValue( Literals.TagMethod_IPairs, out mmt ) )
            {
                l.StackTop = 1;
                l.Call( (Callable)mmt, 1, 3 );

                return 3;
            }
            else
            {
                return l.SetReturnValues( INext, val, 0 );
            }
        }
开发者ID:henchmeninteractive,项目名称:HenchLua,代码行数:18,代码来源:BaseLib.cs

示例8: RunTestScriptWithGlobals

        private static void RunTestScriptWithGlobals( string script, Table globals, params Value[] expectedResults )
        {
            globals["assertEqual"] = (Callable)(l => { Assert.AreEqual( l[1], l[2] ); return 0; });

            var thread = new Thread();

            var func = Helpers.LoadFunc( "Thread/" + script, globals );
            Function.Optimize( func );

            thread.Call( func, 0, Thread.CallReturnAll );

            Assert.AreEqual( expectedResults.Length, thread.StackTop );
            for( int i = 0; i < expectedResults.Length; i++ )
                Assert.AreEqual( expectedResults[i], thread[i + 1] );
        }
开发者ID:henchmeninteractive,项目名称:HenchLua,代码行数:15,代码来源:ThreadTests.cs

示例9: TwoSimpleCalls

        public void TwoSimpleCalls()
        {
            var thread = new Thread();
            var func = Helpers.LoadFunc( "Thread/Call.lua", new Table() );

            thread.Call( func, 0, 1 );

            Assert.AreEqual( 1, thread.StackTop );
            Assert.AreEqual( 42, thread[1] );

            thread.Pop();
            Assert.AreEqual( 0, thread.StackTop );

            thread.Call( func, 0, 1 );

            Assert.AreEqual( 1, thread.StackTop );
            Assert.AreEqual( 42, thread[1] );
        }
开发者ID:henchmeninteractive,项目名称:HenchLua,代码行数:18,代码来源:ThreadTests.cs

示例10: 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


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