Esempio n. 1
0
        public LuaGlobal ExeLua(string strLuaPath)
        {
            LuaExeInfo exeInfo     = null;
            string     strFullPath = Path.GetFullPath(strLuaPath);

            lock (this.dictLuaCache)
            {
                if (!this.dictLuaCache.TryGetValue(strFullPath, out exeInfo))
                {
                    Func <string> code      = () => File.ReadAllText(strFullPath);
                    string        chunkName = Path.GetFileName(strFullPath);
                    LuaChunk      c         = this.lua.CompileChunk(code(), chunkName, false, new KeyValuePair <string, Type> [0]);
                    exeInfo = new LuaExeInfo();
                    exeInfo.dateLastWrite = File.GetLastWriteTime(strFullPath);
                    exeInfo.luaChunk      = c;
                    this.dictLuaCache.Add(strFullPath, exeInfo);
                }
                this.gEnv.DoChunk(exeInfo.luaChunk, new object[0]);
            }
            return(this.gEnv);
        }
Esempio n. 2
0
        /// <summary>
        /// 运行Lua脚本
        /// </summary>
        public LuaGlobal ExeLua(String strLuaPath)
        {
            LuaExeInfo exeInfo     = null;
            String     strFullPath = Path.GetFullPath(strLuaPath);

            lock (dictLuaCache)
            {
                if (!dictLuaCache.TryGetValue(strFullPath, out exeInfo))
                {
                    Func <string> code      = () => File.ReadAllText(strFullPath);
                    string        chunkName = Path.GetFileName(strFullPath);

                    LuaChunk c = lua.CompileChunk(code(), chunkName, false);
                    exeInfo = new LuaExeInfo();
                    exeInfo.dateLastWrite = File.GetLastWriteTime(strFullPath);
                    exeInfo.luaChunk      = c;
                    dictLuaCache.Add(strFullPath, exeInfo);
                }

                gEnv.DoChunk(exeInfo.luaChunk);
            }

            return(gEnv);
        }