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


C# ILuaState.L_Error方法代码示例

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


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

示例1: TBL_Concat

		private static int TBL_Concat( ILuaState lua )
		{
			string sep = lua.L_OptString( 2, "" );
			lua.L_CheckType( 1, LuaType.LUA_TTABLE );
			int i = lua.L_OptInt( 3, 1 );
			int last = lua.L_Opt( lua.L_CheckInteger, 4, lua.L_Len(1) );

			StringBuilder sb = new StringBuilder();
			for( ; i<last; ++i )
			{
				lua.RawGetI( 1, i );
				if( !lua.IsString(-1) )
					lua.L_Error(
						"invalid value ({0}) at index {1} in table for 'concat'",
						lua.L_TypeName(-1), i );
				sb.Append( lua.ToString(-1) );
				sb.Append( sep );
				lua.Pop( 1 );
			}
			if( i == last ) // add last value (if interval was not empty)
			{
				lua.RawGetI( 1, i );
				if( !lua.IsString(-1) )
					lua.L_Error(
						"invalid value ({0}) at index {1} in table for 'concat'",
						lua.L_TypeName(-1), i );
				sb.Append( lua.ToString(-1) );
				lua.Pop( 1 );
			}
			lua.PushString( sb.ToString() );
			return 1;
		}
开发者ID:jaydenh,项目名称:UniLua,代码行数:32,代码来源:LuaTableLib.cs

示例2: Str_Byte

		private static int Str_Byte( ILuaState lua )
		{
			string s = lua.L_CheckString(1);
			int posi = PosRelative( lua.L_OptInt(2, 1), s.Length );
			int pose = PosRelative( lua.L_OptInt(3, posi), s.Length );
			if( posi < 1 ) posi = 1;
			if( pose > s.Length ) pose = s.Length;
			if( posi > pose ) return 0; // empty interval; return no values
			int n = pose - posi + 1;
			if( posi + n <= pose) // overflow?
				return lua.L_Error( "string slice too long" );
			lua.L_CheckStack(n, "string slice too long");
			for( int i=0; i<n; ++i )
				lua.PushInteger( (byte)s[(int)posi+i-1] );
			return n;
		}
开发者ID:Jornason,项目名称:UniLua,代码行数:16,代码来源:LuaStrLib.cs

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

示例4: B_Assert

 public static int B_Assert( ILuaState lua )
 {
     if( !lua.ToBoolean( 1 ) )
         return lua.L_Error( "{0}", lua.L_OptString( 2, "assertion failed!" ) );
     return lua.GetTop();
 }
开发者ID:matthewyang,项目名称:UniLua,代码行数:6,代码来源:LuaBaseLib.cs

示例5: B_Print

 public static int B_Print( ILuaState lua )
 {
     StringBuilder sb = new StringBuilder();
     int n = lua.GetTop();
     lua.GetGlobal( "tostring" );
     for( int i=1; i<=n; ++i )
     {
         lua.PushValue( -1 );
         lua.PushValue( i );
         lua.Call( 1, 1 );
         string s = lua.ToString( -1 );
         if( s == null )
             return lua.L_Error("'tostring' must return a string to 'print'");
         if( i > 1 )
             sb.Append( "\t" );
         sb.Append( s );
         lua.Pop( 1 );
     }
     Debug.Log( sb.ToString() );
     return 0;
 }
开发者ID:matthewyang,项目名称:UniLua,代码行数:21,代码来源:LuaBaseLib.cs

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

示例7: Str_Dump

		private static int Str_Dump( ILuaState lua )
		{
			lua.L_CheckType( 1, LuaType.LUA_TFUNCTION );
			lua.SetTop( 1 );
			var bsb = new ByteStringBuilder();
			LuaWriter writeFunc = 
				delegate(byte[] bytes, int start, int length)
			{
				bsb.Append(bytes, start, length);
				return DumpStatus.OK;
			};
			if( lua.Dump( writeFunc ) != DumpStatus.OK )
				return lua.L_Error( "unable to dump given function" );
			lua.PushString( bsb.ToString() );
			return 1;
		}
开发者ID:Jornason,项目名称:UniLua,代码行数:16,代码来源:LuaStrLib.cs

示例8: Str_Format


//.........这里部分代码省略.........
					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':
					{
						sb.Append(lua.L_CheckString(arg));
						break;
					}
					default: // also treat cases `pnLlh'
					{
						return lua.L_Error( "invalid option '{0}' to 'format'",
							format[s-1] );
					}
				}
			}
			lua.PushString( sb.ToString() );
			return 1;
		}
开发者ID:Jornason,项目名称:UniLua,代码行数:101,代码来源:LuaStrLib.cs

示例9: ScanFormat

		private static int ScanFormat( ILuaState lua, string format, int s, out string form )
		{
			int p = s;
			// skip flags
			while( p < format.Length && format[p] != '\0' && FLAGS.IndexOf(format[p]) != -1 )
				p++;
			if( p - s > FLAGS.Length )
				lua.L_Error( "invalid format (repeat flags)" );
			if( Char.IsDigit( format[p] ) ) p++; // skip width
			if( Char.IsDigit( format[p] ) ) p++; // (2 digits at most)
			if( format[p] == '.' )
			{
				p++;
				if( Char.IsDigit( format[p] ) ) p++; // skip precision
				if( Char.IsDigit( format[p] ) ) p++; // (2 digits at most)
			}
			if( Char.IsDigit( format[p] ) )
				lua.L_Error( "invalid format (width of precision too long)" );
			form = "%" + format.Substring( s, (p-s+1) );
			return p;
		}
开发者ID:Jornason,项目名称:UniLua,代码行数:21,代码来源:LuaStrLib.cs

示例10: TBL_Insert

		private static int TBL_Insert( ILuaState lua )
		{
			int e = AuxGetN(lua, 1) + 1; // first empty element
			int pos; // where to insert new element
			switch( lua.GetTop() )
			{
				case 2: // called with only 2 arguments
				{
					pos = e; // insert new element at the end
					break;
				}
				case 3:
				{
					pos = lua.L_CheckInteger(2); // 2nd argument is the position
					if( pos > e ) e = pos; // `grow' array if necessary
					for( int i=e; i>pos; --i ) // move up elements
					{
						lua.RawGetI( 1, i-1 );
						lua.RawSetI( 1, i ); // t[i] = t[i-1]
					}
					break;
				}
				default:
				{
					return lua.L_Error( "wrong number of arguments to 'insert'" );
				}
			}
			lua.RawSetI( 1, pos ); // t[pos] = v
			return 0;
		}
开发者ID:jaydenh,项目名称:UniLua,代码行数:30,代码来源:LuaTableLib.cs

示例11: AuxSort

		private static void AuxSort( ILuaState lua, int l, int u )
		{
			while( l < u ) // for tail recursion
			{
				// sort elements a[l], a[(l+u)/2] and a[u]
				lua.RawGetI( 1, l );
				lua.RawGetI( 1, u );
				if( SortComp( lua, -1, -2 ) ) // a[u] < a[l]?
					Set2( lua, l, u );
				else
					lua.Pop( 2 );
				if( u-l == 1 ) break; // only 2 elements
				int i = (l+u) / 2;
				lua.RawGetI( 1, i );
				lua.RawGetI( 1, l );
				if( SortComp( lua, -2, -1 ) ) // a[i] < a[l]?
					Set2( lua, i, l );
				else
				{
					lua.Pop( 1 ); // remove a[l]
					lua.RawGetI( 1, u );
					if( SortComp( lua, -1, -2 ) ) // a[u] < a[i]?
						Set2( lua, i, u );
					else
						lua.Pop( 2 );
				}
				if( u-l == 2 ) break; // only 3 arguments
				lua.RawGetI( 1, i ); // Pivot
				lua.PushValue( -1 );
				lua.RawGetI( 1, u-1 );
				Set2(lua, i, u-1);
				/* a[l] <= P == a[u-1] <= a[u], only need to sort from l+1 to u-2 */
				i = l;
				int j = u-1;
				for (;;) {  /* invariant: a[l..i] <= P <= a[j..u] */
					/* repeat ++i until a[i] >= P */
					lua.RawGetI( 1, ++i );
					while( SortComp(lua, -1, -2) )
					{
						if (i>=u) lua.L_Error( "invalid order function for sorting" );
						lua.Pop(1);  /* remove a[i] */
						lua.RawGetI( 1, ++i );
					}
					/* repeat --j until a[j] <= P */
					lua.RawGetI( 1, --j );
					while ( SortComp(lua, -3, -1) ) {
						if (j<=l) lua.L_Error( "invalid order function for sorting" );
						lua.Pop(1);  /* remove a[j] */
						lua.RawGetI( 1, --j );
					}
					if (j<i) {
						lua.Pop(3);  /* pop pivot, a[i], a[j] */
						break;
					}
					Set2(lua, i, j);
				}
				lua.RawGetI( 1, u-1 );
				lua.RawGetI( 1, i );
				Set2(lua, u-1, i);  /* swap pivot (a[u-1]) with a[i] */
				/* a[l..i-1] <= a[i] == P <= a[i+1..u] */
				/* adjust so that smaller half is in [j..i] and larger one in [l..u] */
				if (i-l < u-i) {
					j=l; i=i-1; l=i+2;
				}
				else {
					j=i+1; i=u; u=j-2;
				}
				AuxSort(lua, j, i);  /* call recursively the smaller one */
			}  /* repeat the routine for the larger one */
		}
开发者ID:jaydenh,项目名称:UniLua,代码行数:70,代码来源:LuaTableLib.cs

示例12: TBL_Unpack

		private static int TBL_Unpack( ILuaState lua )
		{
			lua.L_CheckType( 1, LuaType.LUA_TTABLE );
			int i = lua.L_OptInt( 2, 1 );
			int e = lua.L_OptInt( 3, lua.L_Len(1) );
			if( i > e ) return 0; // empty range
			int n = e - i + 1; // number of elements
			if( n <= 0 || !lua.CheckStack(n) ) // n <= 0 means arith. overflow
				return lua.L_Error( "too many results to unpack" );
			lua.RawGetI( 1, i ); // push arg[i] (avoiding overflow problems
			while( i++ < e ) // push arg[i + 1...e]
				lua.RawGetI( 1, i );
			return n;
		}
开发者ID:jaydenh,项目名称:UniLua,代码行数:14,代码来源:LuaTableLib.cs

示例13: FindLoader

		private static void FindLoader( ILuaState lua, string name )
		{
			// will be at index 3
			lua.GetField( lua.UpvalueIndex(1), "searchers" );
			if( ! lua.IsTable(3) )
				lua.L_Error("'package.searchers' must be a table");

			var sb = new StringBuilder();
			// iterator over available searchers to find a loader
			for( int i=1; ; ++i )
			{
				lua.RawGetI( 3, i ); // get a searcher
				if( lua.IsNil( -1 ) ) // no more searchers?
				{
					lua.Pop( 1 ); // remove nil
					lua.PushString( sb.ToString() );
					lua.L_Error( "module '{0}' not found:{1}",
						name, lua.ToString(-1));
					return;
				}

				lua.PushString( name );
				lua.Call( 1, 2 ); // call it
				if( lua.IsFunction(-2) ) // did it find a loader
					return; // module loader found
				else if( lua.IsString(-2) ) // searcher returned error message?
				{
					lua.Pop( 1 ); // return extra return
					sb.Append( lua.ToString(-1) );
				}
				else
					lua.Pop( 2 ); // remove both returns
			}
		}
开发者ID:bharath1097,项目名称:UniLua,代码行数:34,代码来源:LuaPkgLib.cs

示例14: CheckLoad

		private static int CheckLoad( ILuaState lua,
			bool stat, string filename )
		{
			if( stat ) // module loaded successfully?
			{
				lua.PushString( filename ); // will be 2nd arg to module
				return 2; // return open function and file name
			}
			else return lua.L_Error(
				"error loading module '{0}' from file '{1}':\n\t{2}",
				lua.ToString(1), filename, lua.ToString(-1) );
		}
开发者ID:bharath1097,项目名称:UniLua,代码行数:12,代码来源:LuaPkgLib.cs

示例15: FindFile

		private static string FindFile( ILuaState lua,
			string name, string pname, string dirsep )
		{
			lua.GetField( lua.UpvalueIndex(1), pname );
			string path = lua.ToString( -1 );
			if( path == null )
				lua.L_Error( "'package.{0}' must be a string", pname );
			return SearchPath( lua, name, path, ".", dirsep );
		}
开发者ID:bharath1097,项目名称:UniLua,代码行数:9,代码来源:LuaPkgLib.cs


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