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


C# ILuaState.L_ArgCheck方法代码示例

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


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

示例1: CO_Resume

 private static int CO_Resume( ILuaState lua )
 {
     ILuaState co = lua.ToThread( 1 );
     lua.L_ArgCheck( co != null, 1, "coroutine expected" );
     int r = AuxResume( lua, co, lua.GetTop() - 1 );
     if( r < 0 )
     {
         lua.PushBoolean( false );
         lua.Insert( -2 );
         return 2; // return false + error message
     }
     else
     {
         lua.PushBoolean( true );
         lua.Insert( -(r+1) );
         return r+1; // return true + `resume' returns
     }
 }
开发者ID:matthewyang,项目名称:UniLua,代码行数:18,代码来源:LuaCoroLib.cs

示例2: B_XPCall

 public static int B_XPCall( ILuaState lua )
 {
     int n = lua.GetTop();
     lua.L_ArgCheck( n>=2, 2, "value expected" );
     lua.PushValue( 1 ); // exchange function...
     lua.Copy( 2, 1); // ...and error handler
     lua.Replace( 2 );
     ThreadStatus status = lua.PCallK( n-2, LuaDef.LUA_MULTRET,
         1, 0, PCallContinuation );
     return FinishPCall( lua, status == ThreadStatus.LUA_OK );
 }
开发者ID:matthewyang,项目名称:UniLua,代码行数:11,代码来源:LuaBaseLib.cs

示例3: B_ToNumber

 public static int B_ToNumber( ILuaState lua )
 {
     LuaType t = lua.Type( 2 );
     if( t == LuaType.LUA_TNONE || t == LuaType.LUA_TNIL ) // standard conversion
     {
         bool isnum;
         double n = lua.ToNumberX( 1, out isnum );
         if( isnum )
         {
             lua.PushNumber( n );
             return 1;
         } // else not a number; must be something
         lua.L_CheckAny( 1 );
     }
     else
     {
         string s = lua.L_CheckString( 1 );
         int numBase = lua.L_CheckInteger( 2 );
         bool negative = false;
         lua.L_ArgCheck( (2 <= numBase && numBase <= 36), 2,
             "base out of range" );
         s = s.Trim( ' ', '\f', '\n', '\r', '\t', '\v' );
         s = s + '\0'; // guard
         int pos = 0;
         if(s[pos] == '-') { pos++; negative = true; }
         else if(s[pos] == '+') pos++;
         if( Char.IsLetterOrDigit( s, pos ) )
         {
             double n = 0.0;
             do
             {
                 int digit;
                 if( Char.IsDigit( s, pos ) )
                     digit = Int32.Parse( s[pos].ToString() );
                 else
                     digit = Char.ToUpper( s[pos] ) - 'A' + 10;
                 if( digit >= numBase )
                     break; // invalid numeral; force a fail
                 n = n * (double)numBase + (double)digit;
                 pos++;
             } while( Char.IsLetterOrDigit( s, pos ) );
             if( pos == s.Length - 1 ) // except guard, no invalid trailing characters?
             {
                 lua.PushNumber( negative ? -n : n );
                 return 1;
             } // else not a number
         } // else not a number
     }
     lua.PushNil(); // not a number
     return 1;
 }
开发者ID:matthewyang,项目名称:UniLua,代码行数:51,代码来源:LuaBaseLib.cs

示例4: B_SetMetaTable

 public static int B_SetMetaTable( ILuaState lua )
 {
     LuaType t = lua.Type( 2 );
     lua.L_CheckType( 1, LuaType.LUA_TTABLE );
     lua.L_ArgCheck( t == LuaType.LUA_TNIL || t == LuaType.LUA_TTABLE,
         2, "nil or table expected" );
     if( lua.L_GetMetaField( 1, "__metatable" ) )
         return lua.L_Error( "cannot change a protected metatable" );
     lua.SetTop( 2 );
     lua.SetMetaTable( 1 );
     return 1;
 }
开发者ID:matthewyang,项目名称:UniLua,代码行数:12,代码来源:LuaBaseLib.cs

示例5: B_Select

 public static int B_Select( ILuaState lua )
 {
     int n = lua.GetTop();
     if( lua.Type( 1 ) == LuaType.LUA_TSTRING &&
         lua.ToString( 1 )[0] == '#' )
     {
         lua.PushInteger( n-1 );
         return 1;
     }
     else
     {
         int i = lua.L_CheckInteger( 1 );
         if( i < 0 ) i = n + i;
         else if( i > n ) i = n;
         lua.L_ArgCheck( 1 <= i, 1, "index out of range" );
         return n - i;
     }
 }
开发者ID:matthewyang,项目名称:UniLua,代码行数:18,代码来源:LuaBaseLib.cs

示例6: B_RawLen

 public static int B_RawLen( ILuaState lua )
 {
     LuaType t = lua.Type( 1 );
     lua.L_ArgCheck( t == LuaType.LUA_TTABLE || t == LuaType.LUA_TSTRING,
         1, "table or string expected" );
     lua.PushInteger( lua.RawLen( 1 ) );
     return 1;
 }
开发者ID:matthewyang,项目名称:UniLua,代码行数:8,代码来源:LuaBaseLib.cs

示例7: Math_Random

		private static int Math_Random( ILuaState lua )
		{
			double r = RandObj.NextDouble();
			switch( lua.GetTop() )
			{
				case 0: // no argument
					lua.PushNumber( r );
					break;
				case 1:
				{
					double u = lua.L_CheckNumber(1);
					lua.L_ArgCheck( 1.0 <= u, 1, "interval is empty" );
					lua.PushNumber( Math.Floor(r*u) + 1.0 ); // int in [1, u]
					break;
				}
				case 2:
				{
					double l = lua.L_CheckNumber(1);
					double u = lua.L_CheckNumber(2);
					lua.L_ArgCheck( l <= u, 2, "interval is empty" );
					lua.PushNumber( Math.Floor(r*(u-l+1)) + l ); // int in [l, u]
					break;
				}
				default: return lua.L_Error( "wrong number of arguments" );
			}
			return 1;
		}
开发者ID:Jornason,项目名称:UniLua,代码行数:27,代码来源:LuaMathLib.cs

示例8: Str_Char

		private static int Str_Char( ILuaState lua )
		{
			int n = lua.GetTop();
			StringBuilder sb = new StringBuilder();
			for( int i=1; i<=n; ++i )
			{
				int c = lua.L_CheckInteger(i);
				lua.L_ArgCheck( (char)c == c, i, "value out of range" );
				sb.Append( (char)c );
			}
			lua.PushString( sb.ToString() );
			return 1;
		}
开发者ID:Jornason,项目名称:UniLua,代码行数:13,代码来源:LuaStrLib.cs

示例9: Str_Gsub

		private static int Str_Gsub( ILuaState lua )
		{
			
			string src = lua.L_CheckString(1);
			int srcl = src.Length;
			string p = lua.L_CheckString(2);
			LuaType tr = lua.Type(3);
			int max_s = lua.L_OptInt(4, srcl + 1);
			int anchor = 0;
			if (p[0] == '^')
			{
                p = p.Substring(1);
                anchor = 1;
			}
			int n = 0;
			MatchState ms = new MatchState();
			StringBuilder b = new StringBuilder(srcl);
			lua.L_ArgCheck(tr == LuaType.LUA_TNUMBER || tr == LuaType.LUA_TSTRING ||
						   tr == LuaType.LUA_TFUNCTION || tr == LuaType.LUA_TTABLE, 3,
							  "string/function/table expected");
			ms.Lua = lua;
			ms.Src = src;
			ms.SrcInit = 0;
			ms.SrcEnd = srcl;
			ms.Pattern = p;
			ms.PatternEnd = p.Length;
			int s = 0;
			while (n < max_s) {
			   ms.Level = 0;
			   int e = Match(ms, s, 0);
			   if (e != -1) {
			       n++;
				   Add_Value(ms, b, s, e);
			   }
			   if ((e != -1) && e > s) /* non empty match? */
			      s = e;  /* skip it */
			   else if (s < ms.SrcEnd)
			   {
			       char c = src[s];
				   ++s;
			       b.Append(c);
			   }
			   else break;
			   if (anchor != 0) break;
		    }
			b.Append(src.Substring(s, ms.SrcEnd - s));
			lua.PushString(b.ToString());
		    lua.PushInteger(n);  /* number of substitutions */
		    return 2;
		}
开发者ID:Jornason,项目名称:UniLua,代码行数:50,代码来源:LuaStrLib.cs

示例10: Str_Format

		private static int Str_Format( ILuaState lua )
		{
			int top = lua.GetTop();
			StringBuilder sb = new StringBuilder();
			int arg = 1;
			string format = lua.L_CheckString( arg );
			int s = 0;
			int e = format.Length;
			while(s < e)
			{
				if( format[s] != L_ESC )
				{
					sb.Append( format[s++] );
					continue;
				}

				if( format[++s] == L_ESC )
				{
					sb.Append( format[s++] );
					continue;
				}

				// else format item
				if( ++arg > top )
					lua.L_ArgError( arg, "no value" );

				string form;
				s = ScanFormat( lua, format, s, out form );
				switch( format[s++] ) // TODO: properly handle form
				{
					case 'c':
					{
						sb.Append( (char)lua.L_CheckInteger(arg) );
						break;
					}
					case 'd': case 'i':
					{
						int n = lua.L_CheckInteger(arg);
						sb.Append( n.ToString() );
						break;
					}
					case 'u':
					{
						int n = lua.L_CheckInteger(arg);
						lua.L_ArgCheck( n >= 0, arg,
							"not a non-negative number is proper range" );
						sb.Append( n.ToString() );
						break;
					}
					case 'o':
					{
						int n = lua.L_CheckInteger(arg);
						lua.L_ArgCheck( n >= 0, arg,
							"not a non-negative number is proper range" );
						sb.Append( Convert.ToString(n, 8) );
						break;
					}
					case 'x':
					{
						int n = lua.L_CheckInteger(arg);
						lua.L_ArgCheck( n >= 0, arg,
							"not a non-negative number is proper range" );
						// sb.Append( string.Format("{0:x}", n) );
						sb.AppendFormat("{0:x}", n);
						break;
					}
					case 'X':
					{
						int n = lua.L_CheckInteger(arg);
						lua.L_ArgCheck( n >= 0, arg,
							"not a non-negative number is proper range" );
						// sb.Append( string.Format("{0:X}", n) );
						sb.AppendFormat("{0:X}", n);
						break;
					}
					case 'e':  case 'E':
					{
						sb.AppendFormat("{0:E}", lua.L_CheckNumber(arg));
						break;
					}
					case 'f':
					{
						sb.AppendFormat("{0:F}", lua.L_CheckNumber(arg));
						break;
					}
#if LUA_USE_AFORMAT
					case 'a': case 'A':
#endif
					case 'g': case 'G':
					{
						sb.AppendFormat("{0:G}", lua.L_CheckNumber(arg));
						break;
					}
					case 'q':
					{
						AddQuoted(lua, sb, arg);
						break;
					}
					case 's':
					{
//.........这里部分代码省略.........
开发者ID:Jornason,项目名称:UniLua,代码行数:101,代码来源:LuaStrLib.cs

示例11: CO_Status

 private static int CO_Status( ILuaState lua )
 {
     ILuaState co = lua.ToThread( 1 );
     lua.L_ArgCheck( co != null, 1, "coroutine expected" );
     if( (LuaState)lua == (LuaState)co )
         lua.PushString( "running" );
     else switch( co.Status )
     {
         case ThreadStatus.LUA_YIELD:
             lua.PushString( "suspended" );
             break;
         case ThreadStatus.LUA_OK:
         {
             LuaDebug ar = new LuaDebug();
             if( co.GetStack( 0, ar ) ) // does it have frames?
                 lua.PushString( "normal" );
             else if( co.GetTop() == 0 )
                 lua.PushString( "dead" );
             else
                 lua.PushString( "suspended" );
             break;
         }
         default: // some error occurred
             lua.PushString( "dead" );
             break;
     }
     return 1;
 }
开发者ID:matthewyang,项目名称:UniLua,代码行数:28,代码来源:LuaCoroLib.cs

示例12: FieldArgs

		private static int FieldArgs( ILuaState lua, int farg, out int width )
		{
			int f = lua.L_CheckInteger( farg );
			int w = lua.L_OptInt( farg+1, 1 );
			lua.L_ArgCheck( 0 <= f, farg, "field cannot be nagetive" );
			lua.L_ArgCheck( 0 < w, farg+1, "width must be positive" );
			if( f + w > LUA_NBITS )
				lua.L_Error( "trying to access non-existent bits" );
			width = w;
			return f;
		}
开发者ID:Jornason,项目名称:UniLua,代码行数:11,代码来源:LuaBitLib.cs


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