本文整理汇总了C#中ILuaState.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# ILuaState.ToString方法的具体用法?C# ILuaState.ToString怎么用?C# ILuaState.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ILuaState
的用法示例。
在下文中一共展示了ILuaState.ToString方法的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;
}
示例2: ENC_Encode
private static int ENC_Encode( ILuaState lua )
{
var s = lua.ToString(1);
var e = lua.ToString(2);
if( e != ENC_UTF8 )
throw new Exception("unsupported encoding:" + e);
var bytes = Encoding.UTF8.GetBytes(s);
var sb = new StringBuilder();
for( var i=0; i<bytes.Length; ++i )
{
sb.Append( (char)bytes[i] );
}
lua.PushString( sb.ToString() );
return 1;
}
示例3: ENC_Decode
private static int ENC_Decode( ILuaState lua )
{
var s = lua.ToString(1);
var e = lua.ToString(2);
if( e != ENC_UTF8 )
throw new Exception("unsupported encoding:" + e);
var bytes = new Byte[s.Length];
for( int i=0; i<s.Length; ++i )
{
bytes[i] = (byte)s[i];
}
lua.PushString( Encoding.UTF8.GetString( bytes ) );
return 1;
}
示例4: Awake
void Awake() {
Debug.Log("LuaScriptController Awake");
if( Lua == null )
{
Lua = LuaAPI.NewState();
Lua.L_OpenLibs();
var status = Lua.L_DoFile( LuaScriptFile );
if( status != ThreadStatus.LUA_OK )
{
throw new Exception( Lua.ToString(-1) );
}
if( ! Lua.IsTable(-1) )
{
throw new Exception(
"framework main's return value is not a table" );
}
AwakeRef = StoreMethod( "awake" );
StartRef = StoreMethod( "start" );
UpdateRef = StoreMethod( "update" );
LateUpdateRef = StoreMethod( "late_update" );
FixedUpdateRef = StoreMethod( "fixed_update" );
Lua.Pop(1);
Debug.Log("Lua Init Done");
}
CallMethod( AwakeRef );
}
示例5: ENC_Encode
private static int ENC_Encode( ILuaState lua )
{
var s = lua.ToString(1);
var e = lua.ToString(2);
if( e != ENC_UTF8 )
throw new Exception("unsupported encoding:" + e);
var bytes = Encoding.UTF8.GetBytes(s);
var sb = new StringBuilder();
foreach( var b in bytes )
{
sb.Append( b );
}
lua.PushString( sb.ToString() );
return 1;
}
示例6: FFI_AddAssembly
private static int FFI_AddAssembly( ILuaState lua )
{
var name = lua.ToString(1);
var assembly = Assembly.Load( name );
if( assembly != null )
AssemblyList.Add( assembly );
else
UnityEngine.Debug.LogError("assembly not found:" + name);
return 0;
}
示例7: Traceback
private static int Traceback(ILuaState lua)
{
var msg = lua.ToString(1);
if(msg != null) {
lua.L_Traceback(lua, msg, 1);
}
// is there an error object?
else if(!lua.IsNoneOrNil(1)) {
// try its `tostring' metamethod
if(!lua.L_CallMeta(1, "__tostring")) {
lua.PushString("(no error message)");
}
}
return 1;
}
示例8: FFI_ParseSignature
// return `ReturnType', `FuncName', `ParameterTypes'
private static int FFI_ParseSignature( ILuaState lua )
{
var signature = lua.ToString(1);
var result = FuncSignatureParser.Parse( lua, signature );
if( result.ReturnType != null )
lua.PushString( result.ReturnType );
else
lua.PushNil();
lua.PushString( result.FuncName );
if( result.ParameterTypes != null ) {
lua.NewTable();
for( int i=0; i<result.ParameterTypes.Length; ++i ) {
lua.PushString( result.ParameterTypes[i] );
lua.RawSetI( -2, i+1 );
}
}
else {
lua.PushNil();
}
return 3;
}
示例9: Awake
void Awake() {
Debug.Log("LuaScriptController Awake");
if( Lua == null )
{
Lua = LuaAPI.NewState();
Lua.L_OpenLibs();
var status = Lua.L_DoFile( LuaScriptFile );
if( status != ThreadStatus.LUA_OK )
{
throw new Exception( Lua.ToString(-1) );
}
if( ! Lua.IsTable(-1) )
{
throw new Exception(
"framework main's return value is not a table" );
}
AwakeRef = StoreMethod( "awake" );
StartRef = StoreMethod( "start" );
UpdateRef = StoreMethod( "update" );
LateUpdateRef = StoreMethod( "late_update" );
FixedUpdateRef = StoreMethod( "fixed_update" );
Lua.Pop(1);
Debug.Log("Lua Init Done");
}
Lua.GetGlobal("xxsmain");
if (Lua.PCall(0, 0, 0) != ThreadStatus.LUA_OK)
{
Debug.LogWarning("Call global function xxsmain failed:" + Lua.ToString(-1));
Lua.Pop(1);
}
Debug.Log("dofile main...........");
CallMethod( AwakeRef );
}
示例10: GetValue
public static dynamic GetValue(this LuaType self, ILuaState luaState, int index)
{
switch (self)
{
case LuaType.Boolean:
return luaState.ToBoolean(index);
case LuaType.Number:
return luaState.ToNumber(index);
case LuaType.String:
return luaState.ToString(index);
case LuaType.Table:
return new LuaTable(luaState, index);
case LuaType.Nil:
return null;
default:
throw new NotImplementedException(string.Format("Try get {0} of type {1}", index, self));
}
}
示例11: FFI_GetStaticProp
private static int FFI_GetStaticProp( ILuaState lua )
{
var t = (Type)lua.ToUserData(1);
var name = lua.ToString(2);
var pinfo = t.GetProperty( name,
BindingFlags.Static |
BindingFlags.Public );
// UnityEngine.Debug.Log("FFI_GetStaticProp t:"+t+" name:"+name+" pinfo:"+pinfo);
if( pinfo == null )
throw new Exception("GetProperty failed:"+name);
lua.PushLightUserData(pinfo);
return 1;
}
示例12: FFI_GetField
private static int FFI_GetField( ILuaState lua )
{
var t = (Type)lua.ToUserData(1);
var name = lua.ToString(2);
var finfo = t.GetField( name,
BindingFlags.Instance |
BindingFlags.Public );
if( finfo == null )
throw new Exception("GetField failed:"+name);
// UnityEngine.Debug.Log("FFI_GetField t:"+t+" name:"+name+" finfo:"+finfo);
lua.PushLightUserData(finfo);
return 1;
}
示例13: GmatchAux
private static int GmatchAux( ILuaState lua )
{
MatchState ms = new MatchState();
string src = lua.ToString( lua.UpvalueIndex(1) );
string pattern = lua.ToString( lua.UpvalueIndex(2) );
ms.Lua = lua;
ms.Src = src;
ms.SrcInit = 0;
ms.SrcEnd = src.Length;
ms.Pattern = pattern;
ms.PatternEnd = pattern.Length;
for( int s = lua.ToInteger( lua.UpvalueIndex(3) )
; s <= ms.SrcEnd
; s++ )
{
ms.Level = 0;
int e = Match( ms, s, 0 );
if( e != -1 )
{
int newStart = (e == 0) ? e+1: e;
lua.PushInteger( newStart );
lua.Replace( lua.UpvalueIndex(3) );
return PushCaptures(lua, ms, s, e);
}
}
return 0; // not found
}
示例14: showChessboardDialog
/// <summary>
/// 显示棋盘对话框
/// <para>string message</para>
/// </summary>
public static int showChessboardDialog(ILuaState luaState)
{
string message = luaState.ToString(1);
ChessboardDialogControl.SetDialogString(message);
luaState.PushBoolean(ChessboardDialogControl.GetClickedButton());
return 1;
}
示例15: SearchPath
private static string SearchPath( ILuaState lua,
string name, string path, string sep, string dirsep )
{
var sb = new StringBuilder(); // to build error message
if( !String.IsNullOrEmpty(sep) ) // non-empty separator?
name = name.Replace( sep, dirsep ); // replace it by `dirsep'
int pos = 0;
while(PushNextTemplate(lua, path, ref pos))
{
var template = lua.ToString(-1);
string filename = template.Replace( LUA_PATH_MARK, name );
lua.Remove( -1 ); // remove path template
if( Readable( filename ) ) // does file exist and is readable?
return filename; // return that file name
lua.PushString( string.Format( "\n\tno file '{0}'", filename) );
lua.Remove( -2 ); // remove file name
sb.Append( lua.ToString(-1) ); // concatenate error msg. entry
}
lua.PushString( sb.ToString() ); // create error message
return null; // not found
}