本文整理汇总了C#中ILuaState.Call方法的典型用法代码示例。如果您正苦于以下问题:C# ILuaState.Call方法的具体用法?C# ILuaState.Call怎么用?C# ILuaState.Call使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ILuaState
的用法示例。
在下文中一共展示了ILuaState.Call方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PairsMeta
private static int PairsMeta( ILuaState lua, string method, bool isZero
, CSharpFunctionDelegate iter )
{
if( !lua.L_GetMetaField( 1, method ) ) // no metamethod?
{
lua.L_CheckType( 1, LuaType.LUA_TTABLE );
lua.PushCSharpFunction( iter );
lua.PushValue( 1 );
if( isZero )
lua.PushInteger( 0 );
else
lua.PushNil();
}
else
{
lua.PushValue( 1 );
lua.Call( 1, 3 );
}
return 3;
}
示例2: 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;
}
示例3: 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;
}
示例4: 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 );
}
示例5: 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
}
}