本文整理汇总了C#中ILuaState.IsNil方法的典型用法代码示例。如果您正苦于以下问题:C# ILuaState.IsNil方法的具体用法?C# ILuaState.IsNil怎么用?C# ILuaState.IsNil使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ILuaState
的用法示例。
在下文中一共展示了ILuaState.IsNil方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IpairsAux
private static int IpairsAux( ILuaState lua )
{
int i = lua.ToInteger( 2 );
i++; // next value
lua.PushInteger( i );
lua.RawGetI( 1, i );
return lua.IsNil( -1 ) ? 1 : 2;
}
示例2: SortComp
private static bool SortComp( ILuaState lua, int a, int b )
{
if( !lua.IsNil(2) ) // function?
{
lua.PushValue( 2 );
lua.PushValue( a-1 ); // -1 to compensate function
lua.PushValue( b-2 ); // -2 to compensate function add `a'
lua.Call( 2, 1 );
bool res = lua.ToBoolean( -1 );
lua.Pop( 1 );
return res;
}
else /// a < b?
return lua.Compare( a, b, LuaEq.LUA_OPLT );
}
示例3: 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
}
}
示例4: LL_Require
private static int LL_Require( ILuaState lua )
{
string name = lua.L_CheckString( 1 );
lua.SetTop( 1 );
// _LOADED table will be at index 2
lua.GetField( LuaDef.LUA_REGISTRYINDEX, "_LOADED" );
// _LOADED[name]
lua.GetField( 2, name );
// is it there?
if( lua.ToBoolean( -1 ) )
return 1; // package is already loaded
// else must load package
// remove `GetField' result
lua.Pop( 1 );
FindLoader( lua, name );
lua.PushString( name ); // pass name as arg to module loader
lua.Insert( -2 ); // name is 1st arg (before search data)
lua.Call( 2, 1 ); // run loader to load module
if( !lua.IsNil( -1 ) ) // non-nil return?
lua.SetField( 2, name ); // _LOADED[name] = returned value
lua.GetField( 2, name );
if( lua.IsNil( -1 ) ) // module did not set a value?
{
lua.PushBoolean( true ); // use true as result
lua.PushValue( -1 ); // extra copy to be returned
lua.SetField( 2, name ); // _LOADED[name] = true
}
return 1;
}
示例5: SearcherPreload
private static int SearcherPreload( ILuaState lua )
{
string name = lua.L_CheckString( 1 );
lua.GetField( LuaDef.LUA_REGISTRYINDEX, "_PRELOAD" );
lua.GetField( -1, name );
if( lua.IsNil(-1) ) // not found?
lua.PushString( string.Format(
"\n\tno field package.preload['{0}']", name ) );
return 1;
}