本文整理汇总了C#中ILuaState.L_OptInt方法的典型用法代码示例。如果您正苦于以下问题:C# ILuaState.L_OptInt方法的具体用法?C# ILuaState.L_OptInt怎么用?C# ILuaState.L_OptInt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ILuaState
的用法示例。
在下文中一共展示了ILuaState.L_OptInt方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: B_Error
public static int B_Error( ILuaState lua )
{
int level = lua.L_OptInt( 2, 1 );
lua.SetTop( 1 );
if( lua.IsString( 1 ) && level > 0 )
{
lua.L_Where( level );
lua.PushValue( 1 );
lua.Concat( 2 );
}
return lua.Error();
}
示例4: Str_Sub
private static int Str_Sub( ILuaState lua )
{
string s = lua.L_CheckString(1);
int start = PosRelative( lua.L_CheckInteger(2), s.Length );
int end = PosRelative( lua.L_OptInt(3, -1), s.Length );
if( start < 1 ) start = 1;
if( end > s.Length ) end = s.Length;
if( start <= end )
lua.PushString( s.Substring(start-1, end-start+1) );
else
lua.PushString( "" );
return 1;
}
示例5: 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;
}
示例6: StrFindAux
private static int StrFindAux( ILuaState lua, bool find )
{
string s = lua.L_CheckString( 1 );
string p = lua.L_CheckString( 2 );
int init = PosRelative( lua.L_OptInt(3, 1), s.Length );
if( init < 1 ) init = 1;
else if( init > s.Length + 1 ) // start after string's end?
{
lua.PushNil(); // cannot find anything
return 1;
}
// explicit request or no special characters?
if( find && (lua.ToBoolean(4) || NoSpecials(p)) )
{
// do a plain search
int pos = s.IndexOf( p, init-1 );
if( pos >= 0 )
{
lua.PushInteger( pos+1 );
lua.PushInteger( pos+p.Length );
return 2;
}
}
else
{
int s1 = init-1;
int ppos = 0;
bool anchor = p[ppos] == '^';
if( anchor )
ppos++; // skip anchor character
MatchState ms = new MatchState();
ms.Lua = lua;
ms.Src = s;
ms.SrcInit = s1;
ms.SrcEnd = s.Length;
ms.Pattern = p;
ms.PatternEnd = p.Length;
do
{
ms.Level = 0;
int res = Match( ms, s1, ppos );
if( res != -1 )
{
if(find)
{
lua.PushInteger( s1+1 ); // start
lua.PushInteger( res ); // end
return PushCaptures(lua, ms, -1, 0) + 2;
}
else return PushCaptures(lua, ms, s1, res);
}
} while( s1++ < ms.SrcEnd && !anchor );
}
lua.PushNil(); // not found
return 1;
}
示例7: 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;
}
示例8: TBL_Remove
private static int TBL_Remove( ILuaState lua )
{
int e = AuxGetN(lua, 1);
int pos = lua.L_OptInt( 2, e );
if( !(1 <= pos && pos <= e) ) // position is outside bounds?
return 0; // nothing to remove
lua.RawGetI(1, pos); /* result = t[pos] */
for( ; pos<e; ++pos )
{
lua.RawGetI( 1, pos+1 );
lua.RawSetI( 1, pos ); // t[pos] = t[pos+1]
}
lua.PushNil();
lua.RawSetI( 1, e ); // t[2] = nil
return 1;
}
示例9: 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;
}