当前位置: 首页>>代码示例>>C#>>正文


C# Lua.CreateEnvironment方法代码示例

本文整理汇总了C#中Lua.CreateEnvironment方法的典型用法代码示例。如果您正苦于以下问题:C# Lua.CreateEnvironment方法的具体用法?C# Lua.CreateEnvironment怎么用?C# Lua.CreateEnvironment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Lua的用法示例。


在下文中一共展示了Lua.CreateEnvironment方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: IrcScriptEngine

 public IrcScriptEngine()
 {
     Engine = new Lua (
         integerType: LuaIntegerType.Int32,
         floatType: LuaFloatType.Float
     );
     LuaEnvironment = Engine.CreateEnvironment<LuaGlobal> ();
 }
开发者ID:SplittyDev,项目名称:DaBawd,代码行数:8,代码来源:IrcScriptEngine.cs

示例2: TestGlobalProperty01

        public void TestGlobalProperty01()
        {
            using (Lua l = new Lua())
            {
                var g = l.CreateEnvironment<LuaGlobalNew>();

                g.DoChunk("BoolProperty = true", "test1.lua");
                TestResult(g.DoChunk("return BoolProperty", "test2.lua"), true);
            }
        }
开发者ID:htwddwiedem,项目名称:neolua,代码行数:10,代码来源:Runtime.cs

示例3: CodePlexExample0

 public void CodePlexExample0()
 {
   using (Lua l = new Lua()) // create the lua script engine
   {
     dynamic g = l.CreateEnvironment(); // create a environment
     g.dochunk("a = 'Hallo World!';", "test.lua"); // create a variable in lua
     Console.WriteLine(g.a); // access a variable in c#
     g.dochunk("function add(b) return b + 3; end;", "test.lua"); // create a function in lua
     Console.WriteLine("Add(3) = {0}", g.add(3)); // call the function in c#
   }
 }
开发者ID:edisonh,项目名称:neolua,代码行数:11,代码来源:Examples.cs

示例4: CodePlexExample2b

 public void CodePlexExample2b()
 {
   using (Lua l = new Lua())
   {
     dynamic dg = l.CreateEnvironment();
     dg.t = new LuaTable();
     dg.t[0] = 2;
     dg.t[1] = 4;
     dg.dochunk("t[2] = t[0] + t[1]", "test.lua");
     Console.WriteLine(dg.t[2]);
   }
 }
开发者ID:edisonh,项目名称:neolua,代码行数:12,代码来源:Examples.cs

示例5: CodePlexExample2a

 public void CodePlexExample2a()
 {
   using (Lua l = new Lua())
   {
     dynamic dg = l.CreateEnvironment();
     dg.t = new LuaTable();
     dg.t.a = 2;
     dg.t.b = 4;
     dg.dochunk("t.c = t.a + t.b", "test.lua");
     Console.WriteLine(dg.t.c);
   }
 }
开发者ID:edisonh,项目名称:neolua,代码行数:12,代码来源:Examples.cs

示例6: CodePlexExample2

    public void CodePlexExample2()
    {
      using (Lua l = new Lua())
      {
        var g = l.CreateEnvironment();
        dynamic dg = g;

        dg.a = 2; // dynamic way to set a variable
        g["b"] = 4; // second way to access variable
        dg.dochunk("c = a + b", "test.lua");

        Console.WriteLine(dg.c);
        Console.WriteLine(g["c"]);
      }
    }
开发者ID:edisonh,项目名称:neolua,代码行数:15,代码来源:Examples.cs

示例7: Exception01

		public void Exception01()
		{
			using (Lua l = new Lua())
			{
				var g = l.CreateEnvironment();
				try
				{
					g.DoChunk(l.CompileChunk("\nNull(a, a);", "test.lua", LuaDeskop.StackTraceCompileOptions, new KeyValuePair<string, Type>("a", typeof(int))), 1);
				}
				catch (Exception e)
				{
					LuaExceptionData d = LuaExceptionData.GetData(e);
					Assert.IsTrue(d[2].LineNumber == 2);
				}
			}
		} // proc Exception01
开发者ID:edisonh,项目名称:neolua,代码行数:16,代码来源:Exceptions.cs

示例8: TestCode

    } // func GetLines

    public void TestCode(string sCode, params object[] expectedResult)
    {
			using (Lua l = new Lua())
			{
				l.PrintExpressionTree = PrintExpressionTree ? Console.Out : null;
				var g = l.CreateEnvironment<LuaGlobal>();
				Console.WriteLine("Test: {0}", sCode);
				Console.WriteLine(new string('=', 66));
				Stopwatch sw = new Stopwatch();
				sw.Start();
				TestResult(g.DoChunk(sCode, "test.lua"), expectedResult);
				Console.WriteLine("  Dauer: {0}ms", sw.ElapsedMilliseconds);
				Console.WriteLine();
				Console.WriteLine();
			}
    } // proc TestCode
开发者ID:edisonh,项目名称:neolua,代码行数:18,代码来源:TestHelper.cs

示例9: CodePlexExample1

    public void CodePlexExample1()
    {
      using (Lua l = new Lua())
      {
        var g = l.CreateEnvironment();
        dynamic dg = g;

        LuaResult r = g.DoChunk("return a + b", "test.lua",
          new KeyValuePair<string, object>("a", 2),
          new KeyValuePair<string, object>("b", 4));

        Console.WriteLine(r[0]);

        dynamic dr = dg.dochunk("return a + b", "test.lua", "a", 2, "b", 4);
        Console.WriteLine((int)dr);
      }
    }
开发者ID:edisonh,项目名称:neolua,代码行数:17,代码来源:Examples.cs

示例10: ArchiveCache

        public ArchiveCache(string unitsyncWritableFolder) {
            Archives = new List<ResourceInfo>();

            var fi = GetCacheFile(unitsyncWritableFolder);
            if (fi != null)
            {
                var lua = new Lua();
                var luaEnv = lua.CreateEnvironment();
                using (var file = fi.OpenText())
                {
                    dynamic result = luaEnv.DoChunk(file, "dummy.lua");
                    foreach (var archive in result.archives)
                    {
                        var v = archive.Value;

                        if (v.archivedata != null)
                        {

                            var newEntry = new ResourceInfo()
                            {
                                ArchiveName = v.name,
                                ArchivePath = v.path,
                                Name = v.archivedata.name,
                                Author = v.archivedata.author,
                                Description = v.archivedata.description,
                                Mutator = v.mutator,
                                ShortGame = v.shortgame,
                                Game = v.game,
                                ShortName = v.shortname,
                                PrimaryModVersion = v.version,
                            };
                            if (v.archivedata.modtype != null) newEntry.ModType = v.archivedata.modtype;
                            if (v.checksum != null)
                            {
                                uint temp;
                                if (uint.TryParse(v.checksum, out temp)) newEntry.CheckSum = temp;
                            }
                            if (v.archivedata.depend != null) foreach (var dep in v.archivedata.depend) newEntry.Dependencies.Add(dep.Value);

                            Archives.Add(newEntry);
                        }
                    }
                }
            }
        }
开发者ID:DeinFreund,项目名称:Zero-K-Infrastructure,代码行数:45,代码来源:ArchiveCache.cs

示例11: RunTest

		public void RunTest()
		{
			using (Lua l = new Lua())
			{
				var g = l.CreateEnvironment<LuaGlobal>();
				dynamic dg = g;

				dg.math.randomseed(0);
				dg.assert = new Func<object, string, object>(TestAssert);

				DoScript(l, g, "calls.lua");
				DoScript(l, g, "strings.lua");
				//DoScript(l, g, "literals.lua");

				DoScript(l, g, "math.lua");
				DoScript(l, g, "bitwise.lua");
			}
		}
开发者ID:edisonh,项目名称:neolua,代码行数:18,代码来源:RunLuaTests.cs

示例12: Exception02

		public void Exception02()
		{
			using (Lua l = new Lua())
			{
				var g = l.CreateEnvironment();
				try
				{
					g.DoChunk(l.CompileChunk("math.abs(-1 / a).A();", "test.lua", LuaDeskop.StackTraceCompileOptions, new KeyValuePair<string, Type>("a", typeof(int))), 1);
				}
				catch (Exception e)
				{
					LuaExceptionData d = LuaExceptionData.GetData(e);
					Debug.Print("Error: {0}", e.Message);
					Debug.Print("Error at:\n{0}", d.StackTrace);
					Assert.IsTrue(d[2].LineNumber == 1); //  && d[2].ColumnNumber == 18 in release this is one
				}
			}
		} // proc Exception01
开发者ID:edisonh,项目名称:neolua,代码行数:18,代码来源:Exceptions.cs

示例13: TestDateTime01

        public void TestDateTime01()
        {
            using (Lua l = new Lua())
              {
            dynamic g = l.CreateEnvironment<LuaGlobal>();

            g.dochunk("print(os.date('Today is %A, in %B'))");

            TestResult(g.dochunk("return os.date('%x', 906000490)"), new DateTime(1998, 09, 17).ToString("d"));
            TestResult(g.dochunk("return os.date('%d.%m.%Y')"), DateTime.Today.ToString("d"));
            g.dochunk("t = os.date('*t');");
            DateTime dt = DateTime.Now;
            TestResult(g.dochunk("return t.year"), dt.Year);
            TestResult(g.dochunk("return t.month"), dt.Month);
            TestResult(g.dochunk("return t.day"), dt.Day);
            TestResult(g.dochunk("return t.hour"), dt.Hour);
            TestResult(g.dochunk("return t.min"), dt.Minute);
            TestResult(g.dochunk("return t.sec"), dt.Second);
            TestResult(g.dochunk("return t.wday"), (int)dt.DayOfWeek);
            TestResult(g.dochunk("return t.yday"), dt.DayOfYear);
            TestResult(g.dochunk("return t.isdst"), true);
            g.dochunk("t = os.date('!*t');");
            dt = DateTime.UtcNow;
            TestResult(g.dochunk("return t.year"), dt.Year);
            TestResult(g.dochunk("return t.month"), dt.Month);
            TestResult(g.dochunk("return t.day"), dt.Day);
            TestResult(g.dochunk("return t.hour"), dt.Hour);
            TestResult(g.dochunk("return t.min"), dt.Minute);
            TestResult(g.dochunk("return t.sec"), dt.Second);
            TestResult(g.dochunk("return t.wday"), (int)dt.DayOfWeek);
            TestResult(g.dochunk("return t.yday"), dt.DayOfYear);
            TestResult(g.dochunk("return t.isdst"), false);

            TestResult(g.dochunk("return os.date()"), DateTime.Now.ToString("G"));

            g.dochunk("t={};t.year = 2001; print(os.time(t))");
              }
        }
开发者ID:htwddwiedem,项目名称:neolua,代码行数:38,代码来源:Runtime.cs

示例14: LuaInstance

        public LuaInstance()
        {
            lua = new Lua();
            packages = new HashSet<string>();

            try
            {
                global = lua.CreateEnvironment();
                global["package.path"] = LuaConfig.PackagePath;

                LuaAerospike.LoadLibrary(this);
                LuaStream.LoadLibrary(this);

                Assembly assembly = Assembly.GetExecutingAssembly();
                LoadSystemPackage(assembly, "aslib");
                LoadSystemPackage(assembly, "stream_ops");
                LoadSystemPackage(assembly, "aerospike");
            }
            catch (Exception)
            {
                lua.Dispose();
                throw;
            }
        }
开发者ID:Caldas,项目名称:aerospike-client-csharp,代码行数:24,代码来源:LuaInstance.cs

示例15: MethodTest01

 public void MethodTest01()
 {
     using (Lua l = new Lua())
       {
         dynamic g = l.CreateEnvironment();
         g.console = LuaType.GetType(typeof(Console));
         g.dochunk("console.WriteLine('Hallo!');", "test");
         dynamic wl = g.console.WriteLine;
         Assert.IsTrue(wl.GetType() == typeof(LuaOverloadedMethod));
         int iCount = wl.Count;
         Assert.IsTrue(iCount == 19);
         for (int i = 0; i < wl.Count; i++)
         {
             if (i == 17)
                 Console.WriteLine("VarArgs NotImplemented.");
             else
                 Console.WriteLine("{0}: {1}", i, wl[i].GetType().Name);
         }
       }
 }
开发者ID:htwddwiedem,项目名称:neolua,代码行数:20,代码来源:LuaType.cs


注:本文中的Lua.CreateEnvironment方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。