Ejemplo n.º 1
0
 public void Setup()
 {
     lua                 = new Lua();
     luaEnv              = lua.CreateEnvironment();
     options             = new LuaCompileOptions();
     options.DebugEngine = new LuaStackTraceDebugger();
 }
Ejemplo n.º 2
0
        private void menuitem_testlua_Click(object sender, EventArgs e)
        {
            FileInfo fi = new FileInfo(this.nowFile);
            string   fn = fi.Name;

            if (!fn.ToUpper().EndsWith(".LUA"))
            {
                return;
            }
            string cCode = fn.Substring(0, fn.Length - 4);
            bool   error = false;

            try
            {
                Directory.SetCurrentDirectory(fi.DirectoryName);
                Lua    lua = new Lua();
                var    env = lua.CreateEnvironment();
                string pre = "Duel={} Effect={} Card={} aux={} Auxiliary={} " + cCode + "={} Duel.LoadScript=function(str) end ";
                env.DoChunk(pre + this.fctb.Text, "test.lua");
            }
            catch (LuaException ex)
            {
                MessageBox.Show($"LINE{ex.Line} - {ex.Message}");
                error = true;
            }
            if (!error)
            {
                MyMsg.Show(LMSG.syntaxCheckPassed);
            }
        }
Ejemplo n.º 3
0
 public LazynetLua()
 {
     using (Lua l = new Lua())
     {
         this.G = l.CreateEnvironment();
     }
 }
Ejemplo n.º 4
0
        public void EnvDynamicCall01()
        {
            using (Lua l = new Lua())
            {
                l.PrintExpressionTree = true;
                dynamic g = l.CreateEnvironment();
                g.dochunk(GetLines("Lua.EnvDynamicCall01.lua"), "test.lua");

                TestResult(new LuaResult(g.test(2)), 4);
                TestResult(((LuaTable)g).CallMember("test", 2), 4);

                // test of c# binders
                Debug.Print("C# Binders:");
                TestResult(g.b.a(5), 20);
                TestResult(g.b.b(5), 115);
                TestResult(g.b.c(g.b, 5), 110);
                TestResult(g.test(5), 10);

                // test of lua binders
                Debug.Print("Lua Binders:");
                TestResult(g.dochunk("return b.a(5)", "test.lua"), 20);
                TestResult(g.dochunk("return b:b(5)", "test.lua"), 115);
                TestResult(g.dochunk("return b.b(b, 5)", "test.lua"), 115);
                TestResult(g.dochunk("return b:c(5)", "test.lua"), 110);
                TestResult(g.dochunk("return b.c(b, 5)", "test.lua"), 110);
                TestResult(g.dochunk("return test(5)", "test.lua"), 10);
            }
        } // prop EnvDynamicCall01
Ejemplo n.º 5
0
 public void MainThread(ResourceManager resources, InstanceHelper instanceHelper)
 {
     resourceManager = resources;
     config          = resources.GetConfig(Name);
     if (EnsureConfigCorrect() == false)
     {
         resourceManager.SaveConfig(Name);
         resourceManager.SaveConfig("ArkDesktop.LayeredWindowManager");
         return;
     }
     ;
     manager = new LayeredWindowManager(resources);
     instanceHelper.AddControl("", manager);
     if (loadPosition == LoadPosition.InConfig)
     {
         if (config.Element("Script") == null)
         {
             MessageBox.Show("似乎没有加载到脚本,请联系配置包制作者");
             return;
         }
         luaScript = config.Element("Script").Value;
     }
     else
     {
         using (var sr = new System.IO.StreamReader(resourceManager.OpenRead("script.lua"))) luaScript = sr.ReadToEnd();
         if (luaScript == "")
         {
             MessageBox.Show("似乎没有加载到脚本,请联系配置包制作者", "QAQ");
             return;
         }
     }
     using (Lua lua = new Lua())
     {
         dynamic env   = lua.CreateEnvironment();
         LuaApi  api   = new LuaApi(this, lua, env);
         var     chunk = lua.CompileChunk(luaScript, "script.lua", new LuaCompileOptions {
             DebugEngine = LuaStackTraceDebugger.Default
         });
         manager.window.Click += (sender, e) => api.OnClick();
         var luaThread = new Thread(new ThreadStart(() =>
         {
             if (launchType == LaunchType.Positive)
             {
                 while (true)
                 {
                     try
                     {
                         env.dochunk(chunk);
                     }
                     catch (ThreadAbortException)
                     {
                         break;
                     }
                 }
                 catch (Exception e)
                 {
                     MessageBox.Show("发生异常:" + e.Message + "\n" + e.StackTrace);
                 }
             }
Ejemplo n.º 6
0
 public IrcScriptEngine()
 {
     Engine = new Lua (
         integerType: LuaIntegerType.Int32,
         floatType: LuaFloatType.Float
     );
     LuaEnvironment = Engine.CreateEnvironment<LuaGlobal> ();
 }
Ejemplo n.º 7
0
 public void TestParserIssue55()
 {
     using (var l = new Lua())
     {
         var g = l.CreateEnvironment();
         var r = g.DoChunk("repeat break if true then end until true return 23", "TestParserIssue55");
         Assert.AreEqual(23, r[0]);
     }
 }
Ejemplo n.º 8
0
 private T CreateWpfType <T>(string snippet)
     where T : class
 {
     using (var lua = new Lua())
     {
         var g = lua.CreateEnvironment();
         return((T)g.DoChunk(snippet, "wpf.lua", new KeyValuePair <string, object>("UI", new LuaUI()))[0]);
     }
 }         // func CreateWpfType
Ejemplo n.º 9
0
 public void TestFunctions58()
 {
     using (Lua l = new Lua())
     {
         l.PrintExpressionTree = Console.Out;
         dynamic g = l.CreateEnvironment();
         TestResult(g.dochunk("return p:ParamOut(1, 2);", "dummy", "p", new TestParam()), 1, 1, 2);
     }
 }
Ejemplo n.º 10
0
 public void TestFunctions59()
 {
     using (Lua l = new Lua())
     {
         l.PrintExpressionTree = Console.Out;
         dynamic g = l.CreateEnvironment();
         TestResult(g.dochunk("local b = p:GetValue(); return b;", "dummy", "p", new TestParam()), 4);
     }
 }
Ejemplo n.º 11
0
        static void Main(string[] args)
        {
            //Minitouch.connect("localhost", 1111);
            //Minitouch.setPos(1, 100, 100);
            //Minitouch.press(1);

            using var lua = new Lua();
            var env = lua.CreateEnvironment();

            env.RegisterPackage("autopcr", typeof(Autopcr));
            env.RegisterPackage("minitouch", typeof(Minitouch));

            var chunk = lua.CompileChunk(File.ReadAllText("timeline.lua"), "timeline.lua", new LuaCompileOptions());

            Console.Write("pid>");
            var pid = int.Parse(Console.ReadLine());

            //var pid = 11892;
            hwnd = NativeFunctions.OpenProcess(NativeFunctions.PROCESS_ALL_ACCESS, false, pid);

            var tuple = AobscanHelper.Aobscan(hwnd, idcode, addr =>
            {
                var frame = TryGetInfo(hwnd, addr);
                if (frame.Item1 >= 0 && frame.Item1 < 1000 && frame.Item2 > 80 && frame.Item2 < 100)
                {
                    Console.WriteLine($"data found, frameCount = {frame.Item1}, limitTime = {frame.Item2}");
                    return(true);
                }
                return(false);
            });

            addr = tuple.Item1;

            Console.WriteLine($"addr = {addr:x}");

            Console.WriteLine();

            if (addr == -1)
            {
                Console.WriteLine("aobscan failed.");
                return;
            }

            seed_addr = AobscanHelper.Aobscan(hwnd, seed_code, addr =>
            {
                Console.WriteLine($"seed found.");
                return(true);
            }).Item1 - 0x90;

            chunk.Run(env);

            Console.WriteLine("script finished.");
            Minitouch.exit();

            Console.ReadLine();
        }
Ejemplo n.º 12
0
        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);
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// 初始化Lua运行环境
        /// </summary>
        public void InitLuaEnv()
        {
            gEnv = lua.CreateEnvironment();

            // 每100秒对其中一个字典进行检测
            timerCheckDict          = new Timer(100 * 1000);
            timerCheckDict.Elapsed += new ElapsedEventHandler(CheckDictLuaInfo);
            timerCheckDict.Interval = 100 * 1000;
            timerCheckDict.Enabled  = true;
        }
Ejemplo n.º 14
0
        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);
            }
        }
Ejemplo n.º 15
0
        public void AbstractCall01()
        {
            var c = new TestImpl();

            using (var l = new Lua())
            {
                var g = l.CreateEnvironment();
                TestResult(g.DoChunk("return cast(LuaDLR.Test.LuaTypeTests.ITestIntf, a):Foo()", "test.lua", new KeyValuePair <string, object>("a", c)), 42);
            }
        }
Ejemplo n.º 16
0
 public void TestRuntimeLua14()
 {
     using (var l = new Lua())
     {
         var g = l.CreateEnvironment();
         l.PrintExpressionTree = Console.Out;
         g.RegisterPackage("debug", typeof(System.Diagnostics.Debug));
         g.DoChunk("debug:Print('Hallo World!');", "test.lua");
     }
 }         // proc TestRuntimeLua13
Ejemplo n.º 17
0
        public LuaEngine()
        {
            this._script = "";

            _lua            = new Lua();
            _luaEnvironment = _lua.CreateEnvironment();

            this.AddVariable("TCAdminFolder", Path.GetFullPath(Path.Combine(Path.Combine(Utility.GetSharedPath(), ".."), "..")));
            this.AddVariable("Script", this);
        }
Ejemplo n.º 18
0
 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#
     }
 }
Ejemplo n.º 19
0
        public void CodePlexExample8c()
        {
            using (Lua l = new Lua())
            {
                dynamic g = l.CreateEnvironment();

                g.c = new ClrClass();

                Console.WriteLine((int)g.dochunk("return c + 2;"));
            }
        }
Ejemplo n.º 20
0
 public void Setup()
 {
     IOC.Reset();
     lua       = new Lua();
     luaEnv    = lua.CreateEnvironment();
     apiBridge = Mock.Interface <IApiBridge>();
     IOC.Register <IApiBridge>(() => apiBridge);
     IOC.Register <ApiAdapter>(() => new ApiAdapter());
     api        = IOC.Resolve <ApiAdapter>();
     api.LuaEnv = luaEnv;
 }
Ejemplo n.º 21
0
 public void TestFunctions10()
 {
     using (Lua l = new Lua())
     {
         l.PrintExpressionTree = Console.Out;
         var g = l.CreateEnvironment();
         var p = new TestParam();
         g.DoChunk("p.Test = 3;", "dummy", new KeyValuePair <string, object>("p", p));
         Assert.AreEqual(3, p.Test);
     }
 }
Ejemplo n.º 22
0
 public void TestFunctions61()
 {
     using (Lua l = new Lua())
     {
         l.PrintExpressionTree = Console.Out;
         dynamic g = l.CreateEnvironment();
         TestResult(g.dochunk("function test(a) if a ~= nil then return a; end; end;", "test.lua"));
         TestResult(g.test());
         TestResult(g.test(1), 1);
     }
 }
Ejemplo n.º 23
0
 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#
   }
 }
Ejemplo n.º 24
0
        private static void MasterTest()
        {
            using (Lua l = new Lua())
            {
                dynamic g = l.CreateEnvironment();

                g.dofile(@"d:\temp\a\m.lua");

                LuaTable t = (LuaTable)g.array;
                Console.WriteLine("{0}", t[1]);
            }
        }
Ejemplo n.º 25
0
        public static void Example()
        {
            using (var l = new Lua())
            {
                dynamic g = l.CreateEnvironment();
                g.t = new LuaTable();
                ((LuaTable)g.t).DefineFunction("getStruct", new Func <MyStruct>(getStruct));

                g.dochunk("local o = t.getStruct(); " + Environment.NewLine + "" +
                          "print(o.Bla); print(o.Awesome); ", "test.lua");
            }
        }
Ejemplo n.º 26
0
 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);
     }
 }
Ejemplo n.º 27
0
 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);
   }
 }
Ejemplo n.º 28
0
 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]);
     }
 }
Ejemplo n.º 29
0
 public void TestConvert01()
 {
     using (Lua l = new Lua())
     {
         l.PrintExpressionTree = Console.Out;
         var g = l.CreateEnvironment();
         var r = g.DoChunk("return cast(System.Diagnostics.ProcessStartInfo, { FileName = 'Test.exe', Arguments = 'aaa' });", "dummy");
         ProcessStartInfo psi = (ProcessStartInfo)r[0];
         Assert.IsTrue(psi.FileName == "Test.exe");
         Assert.IsTrue(psi.Arguments == "aaa");
     }
 }         // func TestConvert01
Ejemplo n.º 30
0
        public void TestConst01()
        {
            using (Lua l = new Lua())
            {
                l.PrintExpressionTree = Console.Out;
                var g = l.CreateEnvironment();

                TestResult(g.DoChunk("const a = 20; return a;", "dummy"), 20);
                TestResult(g.DoChunk("const a = cast(ushort, 20); return a;", "dummy"), (ushort)20);
                TestResult(g.DoChunk("const a = cast(int, '20'); return a;", "dummy"), 20);
            }
        }
Ejemplo n.º 31
0
        public void TestArithmetic05()
        {
            using (Lua l = new Lua())
            {
                l.PrintExpressionTree = Console.Out;
                var g = l.CreateEnvironment();
                var c = l.CompileChunk("return 1 + a;", "test.lua", null, new KeyValuePair <string, Type>("a", typeof(string)));

                TestResult(g.DoChunk(c, "2"), 3);
                TestResult(g.DoChunk(c, "2.0"), 3.0);
            }
        }
Ejemplo n.º 32
0
 public void TestIndex04()
 {
     using (Lua l = new Lua())
     {
         l.PrintExpressionTree = Console.Out;
         var g = l.CreateEnvironment();
         TestResult(
             g.DoChunk("test[1] = 42; return test[0], test[1], test[2];", "dummy",
                       new KeyValuePair <string, object>("test", new int[] { 1, 2, 3 })
                       ), 1, 42, 3);
     }
 }
Ejemplo n.º 33
0
 public void TestIndex03()
 {
     using (Lua l = new Lua())
     {
         l.PrintExpressionTree = Console.Out;
         var g = l.CreateEnvironment();
         TestResult(
             g.DoChunk("return test[0], test[1];", "dummy",
                       new KeyValuePair <string, object>("test", new IndexAccess())
                       ), 0, 1);
     }
 }
Ejemplo n.º 34
0
 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]);
   }
 }
Ejemplo n.º 35
0
        public void TestFunctions62()
        {
            using (var l = new Lua())
            {
                l.PrintExpressionTree = Console.Out;
                dynamic g = l.CreateEnvironment();
                var     c = l.CompileChunk("print(a)", "dummy", null, new KeyValuePair <string, Type>("a", typeof(object)));

                g.dochunk(c, 1);
                g.dochunk(c, "a");
            }
        }
Ejemplo n.º 36
0
    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"]);
      }
    }
Ejemplo n.º 37
0
		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
Ejemplo n.º 38
0
    } // 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
Ejemplo n.º 39
0
    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);
      }
    }
        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);
                        }
                    }
                }
            }
        }
Ejemplo n.º 41
0
		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
Ejemplo n.º 42
0
		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");
			}
		}
Ejemplo n.º 43
0
        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))");
              }
        }
Ejemplo n.º 44
0
        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;
            }
        }
Ejemplo n.º 45
0
        public void MethodTest05()
        {
            using (Lua l = new Lua())
              {
                dynamic g = l.CreateEnvironment();
                dynamic r = g.dochunk(Lines(
                    new string[] {
                        "local c = clr.LuaDLR.Test.LuaTypeTests.SubClass()",
                        "c.Test('Test');",
                        "return c.Test;"
                    }));

                foreach (var c in r[0])
                    Console.WriteLine(c.GetType().Name);
              }
        }
Ejemplo n.º 46
0
 public void MethodTest02()
 {
     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;
         Delegate dlg1 = wl[LuaType.GetType(typeof(string))];
         Delegate dlg2 = g.dochunk("return console.WriteLine[clr.System.String]");
         Delegate dlg3 = g.dochunk("return console.WriteLine[]");
         Assert.IsTrue(dlg1 == dlg2);
         Assert.IsTrue(dlg3 != null);
       }
 }
Ejemplo n.º 47
0
        public void TestFunctions62()
        {
            using (Lua l = new Lua())
              {
            l.PrintExpressionTree = Console.Out;
            dynamic g = l.CreateEnvironment();
            var c = l.CompileChunk("print(a)", "dummy", null, new KeyValuePair<string, Type>("a", typeof(object)));

            g.dochunk(c, 1);
            g.dochunk(c, "a");
              }
        }
Ejemplo n.º 48
0
 public void TestFunctions61()
 {
     using (Lua l = new Lua())
       {
         l.PrintExpressionTree = Console.Out;
     dynamic g = l.CreateEnvironment();
     TestResult(g.dochunk("function test(a) if a ~= nil then return a; end; end;", "test.lua"));
     TestResult(g.test());
     TestResult(g.test(1), 1);
       }
 }
Ejemplo n.º 49
0
 public void TestFunctions60()
 {
     using (Lua l = new Lua())
       {
         l.PrintExpressionTree = Console.Out;
     dynamic g = l.CreateEnvironment();
     g.dochunk(Lines(
       "function add(a : int, b : int) : int",
       "  return a + b;",
       "end;"), "add.lua");
     Func<int, int, int> a = g.add;
     Assert.IsTrue(a(1, 3) == 4);
     Assert.IsTrue(g.add(1, 2) == 3);
       }
 }
Ejemplo n.º 50
0
 public void TestFunctions58()
 {
     using (Lua l = new Lua())
       {
         l.PrintExpressionTree = Console.Out;
     dynamic  g = l.CreateEnvironment();
     TestResult(g.dochunk("return p:ParamOut(1, 2);", "dummy", "p", new TestParam()), 1, 1, 2);
       }
 }
Ejemplo n.º 51
0
    public void TestConvert01()
    {
			using (Lua l = new Lua())
			{
				l.PrintExpressionTree = Console.Out;
				var g = l.CreateEnvironment();
				var r = g.DoChunk("return cast(System.Diagnostics.ProcessStartInfo, { FileName = 'Test.exe', Arguments = 'aaa' });", "dummy");
				ProcessStartInfo psi = (ProcessStartInfo)r[0];
				Assert.IsTrue(psi.FileName == "Test.exe");
				Assert.IsTrue(psi.Arguments == "aaa");
			}
    } // func TestConvert01
Ejemplo n.º 52
0
        public void TypeTest03()
        {
            using (Lua l = new Lua())
              {
                dynamic g = l.CreateEnvironment();

                g.dochunk("return cast(System.IO.Stream, null);");
                g.dochunk("return cast(LuaDLR.Test.LuaTypeTests.SubClass, null);");
                g.dochunk("return cast(System.Collections.Generic.List[string[]], null);");
                g.dochunk("return cast(System.String[], null);");
                g.dochunk("return cast(string[], null);");
              }
        }
Ejemplo n.º 53
0
 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);
         }
       }
 }
Ejemplo n.º 54
0
 public void EventTest05()
 {
     using (Lua l = new Lua())
       {
     l.PrintExpressionTree = Console.Out;
         var g = l.CreateEnvironment();
         var c = l.CompileChunk(Lines(
             "local a : System.EventHandler = function(a, b) : void",
             "  print('Hallo');",
             "end;",
             "a();"), "dummy", null);
         g.DoChunk(c);
       }
 }
Ejemplo n.º 55
0
 public void MethodTest04()
 {
     using (Lua l = new Lua())
       {
     l.PrintExpressionTree = Console.Out;
         var g = l.CreateEnvironment();
         dynamic m = g.DoChunk("return clr.LuaDLR.Test.LuaTypeTests.Test", "dummy");
         MethodInfo mi = m;
         Action action = m;
         Delegate dlg = m;
         m();
         Assert.IsTrue(mi != null);
         Assert.IsTrue(action != null);
         Assert.IsTrue(dlg != null);
       }
 }
Ejemplo n.º 56
0
 public void TestFunctions59()
 {
     using (Lua l = new Lua())
       {
         l.PrintExpressionTree = Console.Out;
     dynamic g = l.CreateEnvironment();
     TestResult(g.dochunk("local b = p:GetValue(); return b;", "dummy", "p", new TestParam()), 4);
       }
 }
Ejemplo n.º 57
0
 public void TestFunctions10()
 {
     using (Lua l = new Lua())
       {
         l.PrintExpressionTree = Console.Out;
     var g = l.CreateEnvironment();
     var p = new TestParam();
     g.DoChunk("p.Test = 3;", "dummy", new KeyValuePair<string, object>("p", p));
     Assert.AreEqual(3, p.Test);
       }
 }
Ejemplo n.º 58
0
    public void EnvDynamicCall01()
    {
			using (Lua l = new Lua())
			{
				l.PrintExpressionTree = Console.Out;
				dynamic g = l.CreateEnvironment();
				g.dochunk(GetLines("Lua.EnvDynamicCall01.lua"), "test.lua");

				TestResult(new LuaResult(g.test(2)), 4);
				TestResult(((LuaTable)g).CallMember("test", 2), 4);

				// test of c# binders
				Debug.Print("C# Binders:");
				TestResult(g.b.a(5), 20);
				TestResult(g.b.b(5), 115);
				TestResult(g.b.c(g.b, 5), 110);
				TestResult(g.test(5), 10);

				// test of lua binders
				Debug.Print("Lua Binders:");
				TestResult(g.dochunk("return b.a(5)", "test.lua"), 20);
				TestResult(g.dochunk("return b:b(5)", "test.lua"), 115);
				TestResult(g.dochunk("return b.b(b, 5)", "test.lua"), 115);
				TestResult(g.dochunk("return b:c(5)", "test.lua"), 110);
				TestResult(g.dochunk("return b.c(b, 5)", "test.lua"), 110);
				TestResult(g.dochunk("return test(5)", "test.lua"), 10);
			}
    } // prop EnvDynamicCall01
Ejemplo n.º 59
0
        public void TypeTest02()
        {
            using (Lua l = new Lua())
              {
                dynamic g = l.CreateEnvironment();

                Type t = typeof(SubClass);
                LuaType tl = LuaType.GetType(t);
                TestResult(g.dochunk("return clr.LuaDLR.Test.LuaTypeTests.SubClass"), tl);
                TestResult(g.dochunk("return clr.LuaDLR.Test.LuaTypeTests.SubClass:GetType()"), t);

                TestResult(g.dochunk("return clr.System.IO.Stream"), LuaType.GetType(typeof(Stream)));

                LuaType tNull = g.dochunk("return clr.System.Test.Test");
                Assert.IsTrue(tNull.Type == null);

                tl = g.dochunk("return clr.System.Collections.Generic.List[clr.System.String]", "test");
                TestResult(new LuaResult(tl.Type), typeof(List<string>));
                tl = g.dochunk("return clr.System.String[]", "test");
                TestResult(new LuaResult(tl.Type), typeof(string[]));
              }
        }
Ejemplo n.º 60
0
 public void MethodTest03()
 {
     using (Lua l = new Lua())
       {
     l.PrintExpressionTree = Console.Out;
         dynamic g = l.CreateEnvironment();
         g.console = LuaType.GetType(typeof(Console));
         g.dochunk("console.WriteLine('Hallo!');", "test");
         g.dochunk("c = console.WriteLine[clr.System.String];");
         //g.c = g.console.WriteLine[typeof(string)];
         g.c("Hallo");
         g.dochunk("c('Hallo!')");
       }
 }