Exemple #1
0
 public object Include(string filename, string module = "Application.Lua")
 {
     try
     {
         StreamReader sr;
         string       endfile, luadata;
         if (File.Exists(filename))
         {
             endfile = filename;
         }
         else if (File.Exists(filename + ".lua"))
         {
             endfile = (filename + ".lua");
         }
         else if (File.Exists(filename + ".anf"))
         {
             endfile = (filename + ".anf");
         }
         else if (File.Exists(FindFilePath(mLuaq.mFilename) + "\\" + filename))
         {
             endfile = (FindFilePath(mLuaq.mFilename) + "\\" + filename);
         }
         else if (File.Exists(FindFilePath(mLuaq.mFilename) + "\\" + filename + ".lua"))
         {
             endfile = (FindFilePath(mLuaq.mFilename) + "\\" + filename + ".lua");
         }
         else if (File.Exists(FindFilePath(mLuaq.mFilename) + "\\" + filename + ".anf"))
         {
             endfile = (FindFilePath(mLuaq.mFilename) + "\\" + filename + ".anf");
         }
         else if (File.Exists(filename + "\\init.lua"))
         {
             endfile = (filename + "\\init.lua");
         }
         else if (File.Exists(filename + "\\lua.lua"))
         {
             endfile = (filename + "\\lua.lua");
         }
         else if (File.Exists(filename + "\\init.anf"))
         {
             endfile = (filename + "\\init.anf");
         }
         else if (File.Exists(filename + "\\lua.anf"))
         {
             endfile = (filename + "\\lua.anf");
         }
         else if (File.Exists(filename + "\\Main.anf"))
         {
             endfile = (filename + "\\Main.anf");
         }
         else if (File.Exists(filename.Replace('.', '\\')))
         {
             endfile = (filename.Replace('.', '\\'));
         }
         else if (File.Exists(filename.Replace('.', '\\') + ".lua"))
         {
             endfile = (filename.Replace('.', '\\') + ".lua");
         }
         else if (File.Exists(filename.Replace('.', '\\') + ".anf"))
         {
             endfile = (filename.Replace('.', '\\') + ".anf");
         }
         else if (File.Exists(filename.Replace('.', '\\') + "\\lua.lua"))
         {
             endfile = (filename.Replace('.', '\\') + "\\lua.lua");
         }
         else if (File.Exists(filename.Replace('.', '\\') + "\\lua.anf"))
         {
             endfile = (filename.Replace('.', '\\') + "\\lua.anf");
         }
         else if (File.Exists(filename.Replace('.', '\\') + "\\init.lua"))
         {
             endfile = filename.Replace('.', '\\') + "\\init.lua";
         }
         else if (File.Exists(filename.Replace('.', '\\') + "\\init.anf"))
         {
             endfile = filename.Replace('.', '\\') + "\\init.anf";
         }
         else if (File.Exists(filename.Replace('.', '\\') + "\\main.anf"))
         {
             endfile = filename.Replace('.', '\\') + "\\main.anf";
         }
         else
         {
             MessageBox.Show("无法加载模块 '" + filename + "',文件在以下位置均无效:\n"
                             + "file not found:'" + filename + "'\n"
                             + "file not found:'" + filename + ".lua'\n"
                             + "file not found:'" + filename + ".anf'\n"
                             + "file not found:'" + filename + "\\init.lua'\n"
                             + "file not found:'" + filename + "\\init.anf'\n"
                             + "file not found:'" + filename + "\\lua.lua'\n"
                             + "file not found:'" + filename + "\\lua.anf'\n"
                             + "file not found:'" + filename + "\\main.anf'\n"
                             + "file not found:'" + filename.Replace('.', '\\') + "'\n"
                             + "file not found:'" + filename.Replace('.', '\\') + ".lua'\n"
                             + "file not found:'" + filename.Replace('.', '\\') + ".anf'\n"
                             + "file not found:'" + filename.Replace('.', '\\') + "\\lua.lua'\n"
                             + "file not found:'" + filename.Replace('.', '\\') + "\\lua.anf'\n"
                             + "file not found:'" + filename.Replace('.', '\\') + "\\init.lua'\n"
                             + "file not found:'" + filename.Replace('.', '\\') + "\\init.anf'\n"
                             + "file not found:'" + filename.Replace('.', '\\') + "\\main.anf'\n"
                             , "Application", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             return(null);
         }
         int fid = Luna.dizOpen(endfile, "LUA_COMPILE_DIZFILE", 0);
         if (fid > 0)
         {
             IntPtr ptr = Luna.dizGetField(fid, module);
             if ((int)ptr == 0)
             {
                 Luna.dizClose(fid);
                 return(null);
             }
             int len = Marshal.ReadInt32(ptr - 4);
             luadata = Marshal.PtrToStringAnsi(ptr, len);
             Luna.dizClose(fid);
         }
         else
         {
             sr      = new StreamReader(endfile, Encoding.Default);
             luadata = sr.ReadToEnd();
             sr.Close();
         }
         if (luadata.Trim() == "")
         {
             return(null);
         }
         object[] w = mLuaq.mLua.DoString(luadata);
         if (w != null)
         {
             if (w.Length > 1)
             {
                 return(w);
             }
             else
             {
                 return(w[0]);
             }
         }
         else
         {
             return(null);
         }
     }
     catch (Exception er)
     {
         MessageBox.Show(er.Message, "Application", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         return(null);
     }
 }
Exemple #2
0
 public int dizOpen(string filename, string password)
 {
     return(Luna.dizOpen(filename, password, 0));
 }
        public void _Initialize()
        {
            try
            {
                mLua = new Lua();
                _Function _F = new _Function();
                _Method();
                foreach (_Info i in _Pi)
                {
                    //注册回调函数
                    mLua.RegisterFunction(i.Register, _F, _F.GetType().GetMethod(i.Method));
                    //MessageBox.Show(_F.GetType().GetMethod(i.Method).ToString());
                }
                if (mFilename != "" && File.Exists(mFilename))
                {
                    int fid = Luna.dizOpen(mFilename, "LUA_COMPILE_LDBFILE", 0);
                    switch (fid)
                    {
                    case -1:
                        MessageBox.Show("加载脚本失败:操作失败!", "运行时错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        Environment.Exit(0);
                        break;

                    case -101:
                        MessageBox.Show("加载脚本失败:文件不存在或拒绝访问!", "运行时错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        Environment.Exit(0);
                        break;

                    case -104:
                        MessageBox.Show("加载脚本失败:无法确定的编译器编码!", "运行时错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        Environment.Exit(0);
                        break;

                    default:
                        if (fid > 0)
                        {
                            IntPtr ptr = Luna.dizGetField(fid, "Application.Lua");
                            if ((int)ptr == 0)
                            {
                                Environment.Exit(0);
                            }
                            int    len     = Marshal.ReadInt32(ptr - 4);
                            string luadata = Marshal.PtrToStringAnsi(ptr, len);
                            Luna.dizClose(fid);
                            mLua.DoString(luadata);
                        }
                        else
                        {
                            mLua.DoFile(mFilename);
                        }
                        mTimer          = new Timer();
                        mTimer.Interval = 500;
                        mLua.GetFunction("OnFrameCreate").Call();
                        mTimer.Tick   += new System.EventHandler(mTimer_Tick);
                        mTimer.Enabled = true;
                        break;
                    }
                }
                else
                {
                    MessageBox.Show("加载脚本失败:文件不存在!", "运行时错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    Environment.Exit(0);
                }
            }
            catch (Exception er)
            {
                MessageBox.Show(er.Message, "运行时错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                Environment.Exit(0);
            }
        }