本文整理汇总了C#中ILuaState.SetTop方法的典型用法代码示例。如果您正苦于以下问题:C# ILuaState.SetTop方法的具体用法?C# ILuaState.SetTop怎么用?C# ILuaState.SetTop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ILuaState
的用法示例。
在下文中一共展示了ILuaState.SetTop方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: B_DoFile
public static int B_DoFile( ILuaState lua )
{
string filename = lua.L_OptString( 1, null );
lua.SetTop( 1 );
if( lua.L_LoadFile( filename ) != ThreadStatus.LUA_OK )
lua.Error();
lua.CallK( 0, LuaDef.LUA_MULTRET, 0, DoFileContinuation );
return DoFileContinuation( lua );
}
示例2: 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();
}
示例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;
}
示例4: B_Next
public static int B_Next( ILuaState lua )
{
lua.SetTop( 2 );
if( lua.Next(1) )
{
return 2;
}
else
{
lua.PushNil();
return 1;
}
}
示例5: B_RawSet
public static int B_RawSet( ILuaState lua )
{
lua.L_CheckType( 1, LuaType.LUA_TTABLE );
lua.L_CheckAny( 2 );
lua.L_CheckAny( 3 );
lua.SetTop( 3 );
lua.RawSet( 1 );
return 1;
}
示例6: Str_Gmatch
private static int Str_Gmatch( ILuaState lua )
{
lua.L_CheckString(1);
lua.L_CheckString(2);
lua.SetTop(2);
lua.PushInteger(0);
lua.PushCSharpClosure( GmatchAux, 3 );
return 1;
}
示例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;
}
示例8: FinishPCall
private static int FinishPCall( ILuaState lua, bool status )
{
// no space for extra boolean?
if(!lua.CheckStack(1)) {
lua.SetTop(0); // create space for return values
lua.PushBoolean(false);
lua.PushString("stack overflow");
return 2;
}
lua.PushBoolean( status );
lua.Replace( 1 );
return lua.GetTop();
}
示例9: TBL_Sort
private static int TBL_Sort( ILuaState lua )
{
int n = AuxGetN(lua, 1);
lua.L_CheckStack(40, ""); /* assume array is smaller than 2^40 */
if (!lua.IsNoneOrNil(2)) /* is there a 2nd argument? */
lua.L_CheckType( 2, LuaType.LUA_TFUNCTION );
lua.SetTop(2); /* make sure there is two arguments */
AuxSort(lua, 1, n);
return 0;
}
示例10: 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;
}
示例11: loadline
/*
** Read a line and try to load (compile) it first as an expression (by
** adding "return " in front of it) and second as a statement. Return
** the final status of load/call with the resulting function (if any)
** in the top of the stack.
*/
static LuaStatus loadline(ILuaState L)
{
LuaStatus status;
L.SetTop(0);
if (0 == pushline(L, true))
return (LuaStatus)(-1); /* no input */
if ((status = addreturn(L)) != LuaStatus.OK) /* 'return ...' did not work? */
status = multiline(L); /* try as command, maybe with continuation lines */
L.Remove(1); /* remove line from the stack */
L.Assert(L.GetTop() == 1);
return status;
}
示例12: doREPL
/*
** Do the REPL: repeatedly read (load) a line, evaluate (call) it, and
** print any results.
*/
static void doREPL(ILuaState L)
{
LuaStatus status;
String oldprogname = progname;
progname = null; /* no 'progname' on errors in interactive mode */
while ((status = loadline(L)) != (LuaStatus) (-1))
{
if (status == LuaStatus.OK)
status = docall(L, 0, L.MultiReturns);
if (status == LuaStatus.OK) l_print(L);
else report(L, (LuaStatus)status);
}
L.SetTop(0); /* clear stack */
L.WriteLine();
progname = oldprogname;
}