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


C# Lua.LoadFile方法代碼示例

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


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

示例1: TestLoadFileLeak

		public void TestLoadFileLeak ()
		{
			//Test to prevent stack overflow
			//See: http://code.google.com/p/nlua/issues/detail?id=5
			//number of iterations to test
			int count = 1000;
			using (Lua lua = new Lua ()) {
				for (int i = 0; i < count; i++) {
					lua.LoadFile (Environment.CurrentDirectory + System.IO.Path.DirectorySeparatorChar + "test.lua");
				}
			}
			//any thrown exceptions cause the test run to fail
		}
開發者ID:The-Megax,項目名稱:NLua,代碼行數:13,代碼來源:LuaTests.cs

示例2: Main

        public static void Main(string[] args)
        {
            if (args.Contains("-h")) {
            var arglist = new List<string>(args);
            int index = arglist.IndexOf("-h");
            HOME = arglist [index + 1];
            arglist.RemoveAt(index);
            arglist.RemoveAt(index);
            args = arglist.ToArray();
              }

              if (args.Contains("-d")) {
            var arglist = new List<string>(args);
            int index = arglist.IndexOf("-d");
            CURRENT = arglist [index + 1];
            arglist.RemoveAt(index);
            arglist.RemoveAt(index);
            args = arglist.ToArray();
              }

              if (HOME == null) HOME = Directory.GetCurrentDirectory();
              if (CURRENT == null)  CURRENT = HOME;
              Directory.SetCurrentDirectory(CURRENT);

              if (args.Length == 0) args = new[] { "self.build" };

              if (args [0] == "help") {
            Logger.Default
              .Log("> ", false, COLOR).Log ("Available commands:")
              .Log("./kaizow ", false, COLOR).Log ("help                       - display this help message")
              .Log("./kaizow ", false, COLOR).Log ("update (<directory>)       - update kaizo from git repository or from <directory>")
              .Log("./kaizow ", false, COLOR).Log ("<tasks> (-arg <arguments>) - run <tasks> with optional <arguments>");
            return;
              } else if (args [0] == "version") {
            Logger.Default.Log ("Kaizo ", false).Log(VERSION, true, ConsoleColor.Magenta);
            return;
              }

              time.Start ();
              Logger.Default.Log("> ", false, COLOR).Log("Build started");
              Console.Write("Loading build script");

              lua = new Lua ();
              lua.LoadCLRPackage ();
              lua.DoString (@"
            package.path = package.path..';./?/project.lua'

            properties = {}
            dependencies = {
              project = {},
              system = {},
              nuget = {}
            }

            function project(name)
              return module(name, package.seeall)
            end
              ");

              var tasks = Assembly.GetExecutingAssembly().GetTypes().Where(
            t => String.Equals(t.Namespace, "Kaizo.Tasks", StringComparison.Ordinal) &&
            !String.Equals(t.Name, "Task", StringComparison.Ordinal)).ToArray();

              foreach (var task in tasks) {
            Activator.CreateInstance(task, lua);
              }

              lua.RegisterFunction ("task", typeof(Task).GetMethod("Call"));
              LuaFunction project = null;

              try {
            project = lua.LoadFile (Path.Combine(CURRENT, "project.lua"));
              } catch (LuaScriptException e) {
            Fail (e);
              }

              var cmdtasks = new List<string> (args);
              var cmdargs = new List<string> (args);

              if (args.Contains ("-arg")) {
            int index = cmdargs.IndexOf ("-arg");
            cmdargs.RemoveRange (0, index + 1);
            cmdtasks.RemoveRange (index, args.Length - 1);
              } else {
            cmdargs.Clear ();
              }

              var luaargs = lua.CreateTable ();

              foreach (var cmdarg in cmdargs) {
            var key = cmdarg.Replace ("\"", "").Replace ("'", "").Split ('=');
            luaargs [key [0]] = key [1];
              }

              lua ["arg"] = luaargs;

              Console.ForegroundColor = ConsoleColor.Magenta;
              Console.WriteLine(" [DONE]");
              Console.ResetColor();

//.........這裏部分代碼省略.........
開發者ID:nondev,項目名稱:kaizo,代碼行數:101,代碼來源:Program.cs


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