示例#1
0
 private void button1_Click(object sender, EventArgs e)
 {
     try
     {
         dynamic lua = new DynamicLua.DynamicLua();
         lua(txt1.Text);
     }
     catch (Exception err)
     {
         Console.WriteLine(err.Message);
     }
 }
示例#2
0
文件: Form1.cs 项目: itha92/luacsharp
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                dynamic lua = new DynamicLua.DynamicLua();
                lua(txt1.Text);

            }
            catch(Exception err)
            {
                Console.WriteLine(err.Message);
            }
        }
示例#3
0
        public static String executeScript(int input, String code)
        {
            String output = String.Empty;

            if (input == 0)
            {
                dynamic lua = new DynamicLua.DynamicLua();

                lua.print = new Func <Object, Object>((x) =>
                {
                    output += x.ToString();
                    return(x);
                });
                lua.showMessageBox = new Func <Object, bool, Object>(showMessageBox);
                lua.execute        = new Func <String, Object>(execute);
                lua.encrypt        = new Func <int[], int[]>(encrypt);
                lua.decrypt        = new Func <int[], int[]>(decrypt);
                lua.speak          = new Func <String, bool, String>(speak);
                lua.shutdown       = new Func <String>(shutdown);
                lua.restart        = new Func <String>(restart);
                lua.logout         = new Func <String>(logout);
                lua.wait           = new Func <double, double>(wait);
                try
                {
                    lua(code);
                }
                catch (Exception e)
                {
                    return("[ERROR] " + e.Message);
                }
            }
            else if (input == 1)
            {
                int    rand     = new Random().Next(0, 9999);
                String fileName = "tempBatch" + rand + ".bat";
                File.WriteAllText(fileName, code);
                output = CMD.executeCommand(Environment.CurrentDirectory + "\\" + fileName);
                File.Delete(fileName);
            }
            else if (input == 2)
            {
                int    rand     = new Random().Next(0, 9999);
                String fileName = "tempHTML" + rand + ".html";
                File.WriteAllText(fileName, code);
                output = CMD.executeCommand("start " + Environment.CurrentDirectory + "\\" + fileName);
            }
            return(output);
        }
示例#4
0
        public void TestDispose()
        {
            System.GC.Collect();
            long startingMem = System.Diagnostics.Process.GetCurrentProcess().WorkingSet64;

            for (int i = 0; i < 100; i++)
            {
                using (dynamic lua = new DynamicLua.DynamicLua())
                {
                    _Calc(lua, i);
                }
            }

            System.GC.Collect();
            Assert.AreEqual(startingMem / 1024 / 1024, System.Diagnostics.Process.GetCurrentProcess().WorkingSet64 / 1024 / 1024, 10); //10MB delta
        }
        private void DumpButton_Click(object sender, RoutedEventArgs e)
        {
            dynamic Lua = new DynamicLua.DynamicLua();

            Lua(@"
            function RunIronbrewDump(input)
                local OldTableConcat = table.concat
                local DumpedStuff = ''
                local VariableCount = 0

                function FormatConcat(argument)
                    return ('[' .. VariableCount .. '] = ' .. argument)
                end

                table.concat = function(argument)
                    VariableCount = (VariableCount + 1)

                    if VariableCount == 1 then
                        DumpedStuff = (DumpedStuff .. FormatConcat('relaxin\' on the beach.') .. '\n')
                    else
                        DumpedStuff = (DumpedStuff .. FormatConcat(OldTableConcat(argument)) .. '\n')
                    end

                    return OldTableConcat(argument)
                end

                local AMOrPM = (tonumber(os.date('%H')) >= 12 and 'PM') or 'AM'

                DumpedStuff = (DumpedStuff .. '--// coasts\' Constant Dumper - ' .. os.date('%m/%d/%Y @ %H:%M:%S ') .. AMOrPM .. '\n')
                local SuccessDump, ErrorDump = pcall(load(input))

                if SuccessDump then
                    return DumpedStuff
                else
                    return ErrorDump
                end
            end");

            var DumpOutput = Lua.RunIronbrewDump(CodeInputTextbox.Text);

            CodeInputTextbox.Text = DumpOutput.ToString();
        }
示例#6
0
        public void TestDispose()
        {
            System.GC.Collect();
            long startingMem = System.Diagnostics.Process.GetCurrentProcess().WorkingSet64;

            for (int i = 0; i < 100; i++)
            {
                using (dynamic lua = new DynamicLua.DynamicLua())
                {
                    _Calc(lua, i);
                }
            }

            System.GC.Collect();
            Assert.AreEqual(startingMem / 1024 / 1024, System.Diagnostics.Process.GetCurrentProcess().WorkingSet64 / 1024 / 1024, 10); //10MB delta
        }