Пример #1
0
        public void CreateZonesFile(string inputFilename, string outputFilename, string guid, string userName, long userId, string completitionCode, DeviceType device, EngineVersion version)
        {
            FileStream inputStream = null;
            Cartridge  cartridge;

            try
            {
                // Open Lua file
                inputStream = new FileStream(inputFilename, FileMode.Open);

                // Create input object for plain folders
                IInput input = new Folder(inputStream, inputFilename);

                // Check Lua file
                input.Check();

                // Load Lua code and extract all required data
                cartridge = input.Load();

                // Close input
                input = null;
            }
            finally
            {
                if (inputStream != null)
                {
                    inputStream.Close();
                    inputStream = null;
                }
            }

            // Create selected engine
            IEngine engine = Compiler.CreateEngine(device);

            // Convert Lua code and insert special code for this player
            cartridge = engine.ConvertCartridge(cartridge);
            userName  = engine.ConvertString(userName);

            // ---------- Compile Lua code into binary chunk ----------

            // Compile Lua code
            cartridge.Chunk = LUA.Compile(cartridge.LuaCode, cartridge.LuaFileName);

            // ---------- Save cartridge as GWC file ----------

            // Create object for output format (could be also WFC or any other IOutput)
            var outputFormat = new GWC();

            // Write output file
            // Create output in correct format
            var ms = outputFormat.Create(cartridge, userName, userId, completitionCode);

            // Save output to file
            using (FileStream ofs = new FileStream(outputFilename, FileMode.Create)) {
                ms.CopyTo(ofs);
                // Close output
                ofs.Flush();
                ofs.Close();
            }
        }
Пример #2
0
        /// <summary>
        /// 执行脚本
        /// </summary>
        /// <param name="appName">应用名</param>
        /// <param name="fun">函数名</param>
        /// <param name="param1">参数1</param>
        /// <param name="param2">参数2</param>
        /// <param name="param3">参数3</param>
        /// <returns>返回执行结果</returns>
        public object Run(string appName, object fun, object param1 = null, object param2 = null, object param3 = null)
        {
            IEngine eng = null;

            if (appName.EndsWith(".js"))
            {
                eng = new LUA();
            }
            else if (appName.EndsWith(".js"))
            {
                eng = new JS();
            }
            else if (appName.EndsWith(".cs"))
            {
                eng = new CS();
            }
            else if (appName.EndsWith(".lua"))
            {
                eng = new LUA();
            }
            else if (appName.EndsWith(".vbs"))
            {
                eng = new VBS();
            }
            else
            {
                Ex = "不支持的脚本类型!";
                return(null);
            }
            var ret = eng.Run(appName, fun, param1, param2, param3);

            Ex = eng.GetEx();
            return(ret);
        }
Пример #3
0
        /// <summary>
        /// 引擎获取
        /// </summary>
        /// <param name="appName">应用名</param>
        /// <returns>返回引擎</returns>
        public dynamic Get(string appName)
        {
            IEngine eng = null;

            if (appName.EndsWith(".js"))
            {
                eng = new LUA();
            }
            else if (appName.EndsWith(".js"))
            {
                eng = new JS();
            }
            else if (appName.EndsWith(".cs"))
            {
                eng = new CS();
            }
            else if (appName.EndsWith(".lua"))
            {
                eng = new LUA();
            }
            else if (appName.EndsWith(".vbs"))
            {
                eng = new VBS();
            }
            else
            {
                Ex = "错误的脚本类型!";
                return(null);
            }
            var dyn = eng.Get(appName);

            Ex = eng.GetEx();
            return(dyn);
        }
Пример #4
0
        /// <summary>
        /// 卸载脚本
        /// </summary>
        /// <param name="appName">应用名</param>
        /// <param name="waitTime">等待时长,单位:毫秒</param>
        /// <returns>卸载脚本</returns>
        public void Unload(string appName, int waitTime = 2000)
        {
            IEngine eng = null;

            if (appName.EndsWith(".js"))
            {
                eng = new LUA();
            }
            else if (appName.EndsWith(".js"))
            {
                eng = new JS();
            }
            else if (appName.EndsWith(".cs"))
            {
                eng = new CS();
            }
            else if (appName.EndsWith(".lua"))
            {
                eng = new LUA();
            }
            else if (appName.EndsWith(".vbs"))
            {
                eng = new VBS();
            }
            else
            {
                Ex = "错误的脚本类型!";
                return;
            }
            eng.Unload(appName, waitTime);
            Ex = eng.GetEx();
        }
Пример #5
0
        /// <summary>
        /// Initialize the script engine by iterating to lua structure file
        /// </summary>
        public void Initialize()
        {
            lua = new LUA(FileIO.ReadAllText(luaPath));

            if (headerType == HeaderType.Defined)
            {
                dHeader_Template = lua.GetFieldList(FieldsType.Header);
            }

            row_Template = lua.GetFieldList("fields");
        }
Пример #6
0
        public RdbStructure(string script)
        {
            if (script == null)
            {
                throw new ArgumentNullException("script object is null!");
            }
            else if (script.Length == 0)
            {
                throw new Exception("script object is empty!");
            }

            this.script = script;

            lua = new LUA(script);

            if (lua.UseHeader)
            {
                headerCells = lua.GetFieldList("header");
            }

            rowCells = lua.GetFieldList("fields");
        }