當前位置: 首頁>>代碼示例>>C#>>正文


C# LuaTable.GetKey方法代碼示例

本文整理匯總了C#中SharpLua.LuaTypes.LuaTable.GetKey方法的典型用法代碼示例。如果您正苦於以下問題:C# LuaTable.GetKey方法的具體用法?C# LuaTable.GetKey怎麽用?C# LuaTable.GetKey使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在SharpLua.LuaTypes.LuaTable的用法示例。


在下文中一共展示了LuaTable.GetKey方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: REPL


//.........這裏部分代碼省略.........
     #else
     GlobalEnvironment.SetNameValue("DEBUG", LuaBoolean.False);
     #endif
     
     Prompt = "> ";
     // load startup scripts
     LoadFiles();
     
     // check command line args
     if (args.Length > 0)
     {
         string file = args[0];
         if (File.Exists(file))
         {
             try
             {
                 GlobalEnvironment.SetNameValue("_WORKDIR", new LuaString(Path.GetDirectoryName(file)));
                 if (file.EndsWith(".out") || file.EndsWith(".luac") || file.EndsWith(".sluac"))
                 {
                     Chunk c = Serializer.Deserialize(file) as Chunk;
                     c.Enviroment = GlobalEnvironment;
                     bool isBreak;
                     c.Execute(GlobalEnvironment, out isBreak).ToString();
                 }
                 else
                 {
                     LuaRuntime.RunFile(file, GlobalEnvironment);
                 }
                 // it loaded successfully
                 if (args.Length > 1) // possibly interactive mode after
                     Console.WriteLine("Loaded file '" + Path.GetFileName(file) + "'");
             }
             catch (Exception error)
             {
                 Console.WriteLine(error.Message);
             }
             //Console.ReadKey(true);
             //return;
             // instead, go to interactive
         }
         else
         {
             Console.WriteLine(file + " not found.");
         }
     }
     
     // check for interactive mode
     foreach (string arg in args)
         if (arg.ToUpper() == "-I")
             GoInteractive = true;
     
     if (args.Length == 0)
         GoInteractive = true;
     
     if (GoInteractive)
     {
         while (true)
         {
             Console.Write(Prompt);
             string line = Console.ReadLine();
             
             if (line == "quit" || line == "exit" || line == "bye")
             {
                 break;
             }
             else
             {
                 try
                 {
                     LuaValue v = Run(line, GlobalEnvironment);
                     if (v == null)
                         Console.WriteLine("=> [no returned value]");
                     else
                         Console.WriteLine("=> " + v.ToString());
                 }
                 catch (Parser.ParserException error)
                 {
                     // create spacing
                     StringBuilder sb = new StringBuilder();
                     for (int i = 0; i < Prompt.Length; i++)
                         sb.Append(" ");
                     for (int i = 0; i < error.FirstErrorIndex; i++)
                         sb.Append(" ");
                     
                     Console.WriteLine(sb.ToString() + "^");
                     Console.WriteLine("Error: " + error.Message);
                     GlobalEnvironment.SetNameValue("LASTERROR", ObjectToLua.ToLuaValue(error));
                 }
                 catch (Exception error)
                 {
                     if (((LuaBoolean)GlobalEnvironment.GetValue(GlobalEnvironment.GetKey("DEBUG"))) == LuaBoolean.True)
                         Console.WriteLine(error.ToString());
                     else
                         Console.WriteLine("Error: " + error.Message);
                     GlobalEnvironment.SetNameValue("LASTERROR", ObjectToLua.ToLuaValue(error));
                 }
             }
         }
     }
 }
開發者ID:chenzuo,項目名稱:SharpLua,代碼行數:101,代碼來源:LuaRuntime.cs


注:本文中的SharpLua.LuaTypes.LuaTable.GetKey方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。