Beispiel #1
0
        public void MainThread(object coreInst)
        {
            core = (Core)coreInst;

            window         = core.RequestPlugin("ArkDesktop.LayeredWindow").CreateInstance("ArkDesktop.LayeredWindow") as LayeredWindow;
            manager        = core.RequestPlugin("ArkDesktop.LayeredWindowManager").CreateInstance("ArkDesktop.LayeredWindowManager") as LayeredWindowManager;
            manager.window = window;
            manager.config = core.config;
            manager.HelpPositionChange();
            manager.helpZoomChange    = true;
            configControl             = new ConfigControl();
            configControl.Dock        = DockStyle.Fill;
            configControl.makerParent = this;
            configControl.manager     = manager;
            core.AddControl("图片播放", configControl);

            if (core.config.GetElement(ns + "StaticPic") == null)
            {
                CreateConfig();
            }
            LoadConfig();
            while (!manager.Ready)
            {
                ;
            }

            if (core.config.GetElement(ns + "StaticPic").Element(ns + "LuaScript") != null)
            {
                LuaInterface.Lua lua    = new LuaInterface.Lua();
                LuaApi           luaApi = new LuaApi(this, lua);
                window.Click += (sender, e) => luaApi.OnClick();
                lua.DoString(core.config.GetElement(ns + "StaticPic").Element(ns + "LuaScript").Value);
            }
            else
            {
                while (!closed)
                {
                    int size = bitmaps.Count;
                    allowModify = size == 0;
                    for (int i = 0; i < size; ++i)
                    {
                        Thread.Sleep(1000 / frameTime);
                        if (needModify)
                        {
                            allowModify = true;
                            while (needModify)
                            {
                                ;
                            }
                            break;
                        }
                        manager.SetBits(bitmaps[i]);
                    }
                }
            }
            while (!manager.IsDisposed)
            {
                ;
            }
        }
Beispiel #2
0
 public ViewModel(System.Windows.Threading.Dispatcher d)
 {
     dispatcher   = d;
     ClickCommand = new CommonCommand(OnClick);
     lua          = new LuaInterface.Lua();
     lua.DoFile("aaa.lua");
     lua["this"] = this;
 }
 void DoLua()
 {
     using (LuaInterface.Lua lua = new LuaInterface.Lua())
     {
         lua.DoString("luanet.load_assembly('MyAssembly')");
         //... do what you want within Lua with MyAssembly
     }
 }
Beispiel #4
0
 private void Initialize()
 {
     if (lua == null)
     {
         lua = new LuaInterface.Lua();
         ExposeLibraries();
     }
 }
        public static string ParseVersion(Engine engine)
        {
            ScriptEngine se = engine.GetScriptEngine(0) as ScriptEngine;

            LuaInterface.Lua lua = se.GetScriptHandle() as LuaInterface.Lua;
            string           str = (string)lua["Version"];

            return(str);
        }
Beispiel #6
0
        } // func ExecuteScriptLoop

        private static long ExecuteLuaIntf(int i, string sScript)
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();
            using (LuaInterface.Lua lua = new LuaInterface.Lua())
            {
                lua.RegisterFunction("test", null, typeof(Program).GetMethod("LuaTest"));
                lua.RegisterFunction("echo", null, typeof(Program).GetMethod("LuaEcho"));
                DebugOut("LuaIntf", i, lua.DoString(sScript, "test"));
            }
            return(sw.ElapsedMilliseconds);
        } // proc ExecuteLuaIntf
        /// <summary>
        /// Инициализировать информацию об IO-Link устройствах.
        /// </summary>
        private void InitIOLinkSizesForDevices()
        {
            IOLinkSizes = new Dictionary <string, IODevice.IOLinkSize>();
            var          lua         = new LuaInterface.Lua();
            const string devicesFile = "sys_iolink_devices.lua";
            var          fullPath    = Path.Combine(
                ProjectManager.GetInstance().SystemFilesPath, devicesFile);

            if (File.Exists(fullPath))
            {
                object[] result = lua.DoFile(fullPath);
                if (result == null)
                {
                    return;
                }

                var dataTables = result[0] as LuaInterface.LuaTable;
                foreach (var table in dataTables.Values)
                {
                    var    tableData   = table as LuaInterface.LuaTable;
                    string articleName = (string)tableData["articleName"];
                    // Читаем float т.к могут быть 0.5 размер (в словах)
                    float sizeIn  = (float)((double)tableData["sizeIn"]);
                    float sizeOut = (float)((double)tableData["sizeOut"]);

                    if (IOLinkSizes.ContainsKey(articleName) == false)
                    {
                        // Для расчета IO-Link округляем до целого, кроме 0
                        // Для настройки - оставляем как есть
                        int intSizeIn = Convert.ToInt32(
                            Math.Round(sizeIn, MidpointRounding.AwayFromZero));
                        int intSizeOut = Convert.ToInt32(
                            Math.Round(sizeOut, MidpointRounding.AwayFromZero));
                        var properties = new IODevice.IOLinkSize
                        {
                            SizeIn          = intSizeIn,
                            SizeOut         = intSizeOut,
                            SizeInFromFile  = sizeIn,
                            SizeOutFromFile = sizeOut
                        };
                        IOLinkSizes.Add(articleName, properties);
                    }
                }
            }
            else
            {
                string template = EasyEPlanner.Properties.Resources
                                  .ResourceManager.GetString("IOLinkDevicesFilePattern");
                File.WriteAllText(fullPath, template);
            }
        }
Beispiel #8
0
 public Test()
 {
     //dynamic = new DynamicProgramming();
     //mikelChar = new CharacterNPC("Settings/Mikel.xml");
     //Init();
     //Go();
     lua = new LuaInterface.Lua();
     AI.Scripting.ScriptFunctions methods = new WiccanRede.AI.Scripting.ScriptFunctions(new NPC(mikelChar, new Microsoft.DirectX.Vector3(), null, null));
     RegisterNewMethod(methods);
     lua.DoFile(skript1);
     lua.GetFunction("Update").Call();
     //RunLua();
     //ai = new AICore(grid);
     string str = Console.ReadLine();
 }
        public static tmTreeNode ParseProfile(Engine engine)
        {
            ScriptEngine se = engine.GetScriptEngine(0) as ScriptEngine;

            LuaInterface.Lua      lua   = se.GetScriptHandle() as LuaInterface.Lua;
            LuaInterface.LuaTable table = lua["items"] as LuaInterface.LuaTable;
            if (table == null)
            {
                throw new System.Exception("Invalid profile,could't found the global variabl \"items\"");
            }

            tmTreeNode tree = new tmTreeNode("Root");   //root

            ParseLuaTable(tree, table);

            return(tree);
        }
Beispiel #10
0
        private static double ExecuteLuaIntfCompiled(string sScript, int iLoops)
        {
            using (LuaInterface.Lua lua = new LuaInterface.Lua())
            {
                lua.RegisterFunction("test", null, typeof(Program).GetMethod("LuaTest"));
                lua.RegisterFunction("echo", null, typeof(Program).GetMethod("LuaEcho"));
                LuaInterface.LuaFunction f = lua.LoadString(sScript, "test");

                Stopwatch sw = new Stopwatch();
                sw.Start();

                for (int i = 0; i < iLoops; i++)
                {
                    DebugOut("LuaIntf-C", i, f.Call());
                }

                return(sw.ElapsedMilliseconds / (double)iLoops);
            }
        }
Beispiel #11
0
        public Main()
        {
            Lua = new LuaInterface.Lua();

            Lua.DoFile(AppDomain.CurrentDomain.BaseDirectory + "Lua\\TrigEditPlus\\constparser.lua");
            Lua.DoFile(AppDomain.CurrentDomain.BaseDirectory + "Lua\\TrigEditPlus\\condition.lua");
            Lua.DoFile(AppDomain.CurrentDomain.BaseDirectory + "Lua\\TrigEditPlus\\action.lua");
            Lua.DoFile(AppDomain.CurrentDomain.BaseDirectory + "Lua\\TrigEditPlus\\briefing.lua");
            Lua.DoFile(AppDomain.CurrentDomain.BaseDirectory + "Lua\\TrigEditPlus\\tool.lua");


            Lua.RegisterFunction("msgbox", this, this.GetType().GetMethod("MsgBox"));



            Lua.RegisterFunction("Trigger", this, this.GetType().GetMethod("Triggerinterpreter"));
            Lua.RegisterFunction("ParseString", this, this.GetType().GetMethod("ParseString"));
            Lua.RegisterFunction("ParseLocation", this, this.GetType().GetMethod("ParseLocation"));
            Lua.RegisterFunction("ParseUPRP", this, this.GetType().GetMethod("ParseUPRP"));
            Lua.RegisterFunction("ParseUnit", this, this.GetType().GetMethod("ParseUnit"));
            Lua.RegisterFunction("ParseSwitchName", this, this.GetType().GetMethod("ParseSwitchName"));
        }
 public ScriptingLua()
 {
     lua = new LuaInterface.Lua();
     //AI.Scripting.LuaFsmFunctions methods = new WiccanRede.AI.Scripting.LuaFsmFunctions();
     //RegisterFunctions(methods);
 }
Beispiel #13
0
 void Framework.ILaunched.Launch()
 {
     _Lua = new LuaInterface.Lua();
 }
Beispiel #14
0
 public LuaEngine()
 {
     scriptEngine = new LuaInterface.Lua();
 }
Beispiel #15
0
    private static double ExecuteLuaIntfCompiled(string sScript, int iLoops)
    {
      using (LuaInterface.Lua lua = new LuaInterface.Lua())
      {
        lua.RegisterFunction("test", null, typeof(Program).GetMethod("LuaTest"));
        lua.RegisterFunction("echo", null, typeof(Program).GetMethod("LuaEcho"));
        LuaInterface.LuaFunction f = lua.LoadString(sScript, "test");
        
        Stopwatch sw = new Stopwatch();
        sw.Start();

        for (int i = 0; i < iLoops; i++)
          DebugOut("LuaIntf-C", i, f.Call());

        return sw.ElapsedMilliseconds / (double)iLoops;
      }
    }
Beispiel #16
0
        private void OKButton_Click(object sender, EventArgs e)
        {
            if (BotDesc.Running)
            {
                if (MessageBox.Show("To apply the modification, bots must be restarted.", "warning", MessageBoxButtons.OKCancel) != DialogResult.OK)
                {
                    return;
                }
            }

            DialogResult = DialogResult.OK;

            BotDesc.Name = (string)FPropTable["Name"];

            BotDesc.BotCommands.Clear();

            if (BotDesc.Name.Length == 0)
            {
                BotDesc.Name = "No Name";
            }

            BotDesc.Silenced = (bool)FPropTable["Silence Mode"];
            BotDesc.Count = (int)FPropTable["Count"];

            try
            {
                IPAddress ip_addr = (IPAddress)FPropTable["HostAddress"];
                BotDesc.Host = new IPEndPoint(ip_addr, (int)FPropTable["HostPort"]);

                LuaInterface.Lua lua = new LuaInterface.Lua();

                lua.DoFile(BotDesc.Script);

                LuaInterface.LuaTable bot_cmds = lua.GetTable("BotCommandList");

                if (bot_cmds != null)
                {
                    foreach (object cmd_name in bot_cmds.Keys)
                    {
                        BotEngine.BotCommand cmd = new BotStudio.BotEngine.BotCommand(BotDesc, (string)cmd_name);

                        BotDesc.BotCommands.Add(cmd);

                        LuaInterface.LuaTable param_table = (LuaInterface.LuaTable)bot_cmds[(string)cmd_name];
                        if (param_table == null)
                        {
                            continue;
                        }

                        foreach (object param in param_table.Values)
                        {
                            cmd.Parameters.Add(new BotEngine.BotCommand.Parameter((string)param, ""));
                        }
                    }
                }
            }
            catch(Exception ip_e)
            {
                MessageBox.Show(ip_e.Message);
                AppContext.WriteLog(ip_e.Message);
                DialogResult = DialogResult.None;
                return;
            }
        }
Beispiel #17
0
    } // func ExecuteScriptLoop

    private static long ExecuteLuaIntf(int i, string sScript)
    {
      Stopwatch sw = new Stopwatch();
      sw.Start();
      using (LuaInterface.Lua lua = new LuaInterface.Lua())
      {
        lua.RegisterFunction("test", null, typeof(Program).GetMethod("LuaTest"));
        lua.RegisterFunction("echo", null, typeof(Program).GetMethod("LuaEcho"));
        DebugOut("LuaIntf", i, lua.DoString(sScript, "test"));
      }
      return sw.ElapsedMilliseconds;
    } // proc ExecuteLuaIntf
Beispiel #18
0
        /// <summary>
        /// Инициализировать модули информацию о модулях ввода-вывода.
        /// </summary>
        private void InitIOModulesInfo()
        {
            var          lua          = new LuaInterface.Lua();
            const string fileName     = "sys_io.lua";
            const string templateName = "sysIOLuaFilePattern";
            string       pathToFile   = Path.Combine(
                ProjectManager.GetInstance().SystemFilesPath, fileName);

            if (File.Exists(pathToFile))
            {
                object[] result = lua.DoFile(pathToFile);
                if (result == null)
                {
                    return;
                }

                var dataTables = result[0] as LuaInterface.LuaTable;
                foreach (var table in dataTables.Values)
                {
                    var tableData = table as LuaInterface.LuaTable;

                    int    number                 = Convert.ToInt32((double)tableData["n"]);
                    string name                   = (string)tableData["name"];
                    string description            = (string)tableData["description"];
                    int    addressSpaceTypeNumber = Convert.ToInt32(
                        (double)tableData["addressSpaceType"]);
                    string typeName  = (string)tableData["typeName"];
                    string groupName = (string)tableData["groupName"];

                    var channelClamps      = new List <int>();
                    var channelAddressesIn = new List <int>();
                    var channelAddrOut     = new List <int>();

                    var channelClampsTable = tableData[
                        "channelClamps"] as LuaInterface.LuaTable;
                    var channelAddressesInTable = tableData[
                        "channelAddressesIn"] as LuaInterface.LuaTable;
                    var channelAddressesOutTable = tableData[
                        "channelAddressesOut"] as LuaInterface.LuaTable;
                    foreach (var num in channelClampsTable.Values)
                    {
                        channelClamps.Add(Convert.ToInt32((double)num));
                    }
                    foreach (var num in channelAddressesInTable.Values)
                    {
                        channelAddressesIn.Add(Convert.ToInt32((double)num));
                    }
                    foreach (var num in channelAddressesOutTable.Values)
                    {
                        channelAddrOut.Add(Convert.ToInt32((double)num));
                    }

                    int    DOcnt = Convert.ToInt32((double)tableData["DO_count"]);
                    int    DIcnt = Convert.ToInt32((double)tableData["DI_count"]);
                    int    AOcnt = Convert.ToInt32((double)tableData["AO_count"]);
                    int    AIcnt = Convert.ToInt32((double)tableData["AI_count"]);
                    string color = (string)tableData["Color"];

                    IOModuleInfo.AddModuleInfo(number, name, description,
                                               addressSpaceTypeNumber, typeName, groupName,
                                               channelClamps.ToArray(), channelAddressesIn.ToArray(),
                                               channelAddrOut.ToArray(), DOcnt, DIcnt, AOcnt, AIcnt,
                                               color);
                }
            }
            else
            {
                string template = EasyEPlanner.Properties.Resources
                                  .ResourceManager.GetString(templateName);
                File.WriteAllText(pathToFile, template);
                MessageBox.Show("Файл с описанием модулей ввода-вывода" +
                                " не найден. Будет создан пустой файл (без описания).",
                                "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #19
0
 /// <summary>
 /// Creates a new instance of <c>LuaFunctions</c>
 /// </summary>
 /// <param name="vm">Lua VM</param>
 public LuaFunctions(ref LuaInterface.Lua vm)
 {
     _lua = vm;
 }
Beispiel #20
0
 public LuaEngine()
 {
     scriptEngine = new LuaInterface.Lua();
 }
Beispiel #21
0
 public void Stop()
 {
     Enabled = false;
     Thread = null;
 }