private void CheckLuaScript()
        {
            if (expScript == null && !loc.Equals("") && !funcName.Equals(""))
            {
                try
                {
                    expScript = new NLua.Lua();
                    expScript.LoadCLRPackage();
                    expScript.DoFile(Game1.rootContent + loc);

                    bHasProperLua = expScript.GetFunction(funcName) != null;
                }
                catch (Exception e)
                {
                    bHasProperLua = false;
                    expScript     = null;
                    if (Game1.bIsDebug)
                    {
                        Console.WriteLine(e);
                        //throw e;
                    }
                }
            }
            else if (loc.Equals(""))
            {
                bHasProperLua = false;
                expScript     = null;
            }
            else if (!bHasProperLua)
            {
                expScript     = null;
                bHasProperLua = false;
            }
        }
Exemple #2
0
        protected override void Initialized(object state)
        {
            base.Initialized(state);

            if (_ctx != null)
            {
                _ctx.Dispose();
            }

            _ctx = new NLua.Lua();
            _ctx.LoadCLRPackage();

            _ctx.RegisterFunction("AddCommand", this, this.GetType().GetMethod("AddCommand"));
            _ctx.RegisterFunction("ArraySort", this, this.GetType().GetMethod("ArraySort"));
            //_ctx.RegisterFunction("HookBase", this, this.GetType().GetMethods()
            //    .Where(x => x.Name == "HookBase" && x.GetParameters().Last().ParameterType == typeof(NLua.LuaFunction))
            //    .First());

            _ctx.DoFile(Path);

            CallSelf("Initialized");

            var plg = _ctx["export"] as NLua.LuaTable;

            if (plg != null)
            {
                this.TDSMBuild   = (int)(double)plg["TDSMBuild"];
                this.Author      = plg["Author"] as String;
                this.Description = plg["Description"] as String;
                this.Name        = plg["Name"] as String;
                this.Version     = plg["Version"] as String;

                IsValid = true;

                var hooks = plg["Hooks"] as NLua.LuaTable;
                if (hooks != null)
                {
                    foreach (KeyValuePair <Object, Object> hookTarget in hooks)
                    {
                        var hook      = hookTarget.Key as String;
                        var hookPoint = PluginManager.GetHookPoint(hook);

                        if (hookPoint != null)
                        {
                            var details  = hookTarget.Value as NLua.LuaTable;
                            var priority = (HookOrder)(details["Priority"] ?? HookOrder.NORMAL);
                            //var priority = FindOrder(details["Priority"] as String);

                            var del = _ctx.GetFunction(hookPoint.DelegateType, "export.Hooks." + hook + ".Call");
                            HookBase(hookPoint, priority, del); //TODO maybe fake an actual delegate as this is only used for registering or make a TDSM event info class
                        }
                    }
                }
            }
        }
Exemple #3
0
 /// <summary>
 /// 跑文件
 /// </summary>
 /// <param name="s">文件路径</param>
 /// <returns>返回的结果</returns>
 public object[] DoFile(string s)
 {
     try
     {
         return(lua.DoFile(s));
     }
     catch (Exception e)
     {
         ErrorEvent?.Invoke(lua, e.Message);
         throw new Exception(e.Message);
     }
 }
Exemple #4
0
 public object[] DoFile(string s)
 {
     try
     {
         return(lua.DoFile(s));
     }
     catch (Exception e)
     {
         Error(e);
         throw e;
     }
 }
Exemple #5
0
        ///<summary>
        ///Load LUA Module
        ///</summary>
        public void LoadModule(Module module)
        {
            string ModuleName = module.Name;
            string Creator    = module.Creator;

            string ModuleFile = "modules" + Config.Folders.FolderSplit + Creator + Config.Folders.FolderSplit + ModuleName + ".lua";

            if (File.Exists(ModuleFile))
            {
                Environment.DoFile(ModuleFile); // We should probably avoid loading the LUA files with LoadFile and instead make a command loading this into a sandbox?
            }
            // https://github.com/kikito/sandbox.lua/blob/master/sandbox.lua
        }
Exemple #6
0
 public void Run(string code)
 {
     using (NLua.Lua lua = new NLua.Lua())
     {
         lua["lua_run_result_var"] = "";
         try
         {
             lua.RegisterFunction("httpGet_row", null, typeof(Tools).GetMethod("HttpGet"));
             lua.RegisterFunction("httpPost_row", null, typeof(Tools).GetMethod("HttpPost"));
             lua.RegisterFunction("setData_row", null, typeof(Tools).GetMethod("LuaSetXml"));
             lua.RegisterFunction("getData_row", null, typeof(Tools).GetMethod("LuaGetXml"));
             lua.RegisterFunction("fileDownload", null, typeof(Tools).GetMethod("FileDownload"));
             lua.RegisterFunction("getImg", null, typeof(LuaApi).GetMethod("GetBitmap"));
             lua.RegisterFunction("setImgText", null, typeof(LuaApi).GetMethod("PutText"));
             lua.RegisterFunction("putImgBlock", null, typeof(LuaApi).GetMethod("putBlock"));
             lua.RegisterFunction("setImgImage", null, typeof(LuaApi).GetMethod("setImage"));
             lua.RegisterFunction("getImgDir", null, typeof(LuaApi).GetMethod("GetDir"));
             lua.RegisterFunction("getPath", null, typeof(LuaApi).GetMethod("GetPath"));
             lua.DoFile(AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "lua/head.lua");
             lua.DoString(Encoding.UTF8.GetBytes(headRun));
             lua.DoString(Encoding.UTF8.GetBytes(code));
             if (Tools.CharNum(lua["lua_run_result_var"].ToString(), "\n") > 40 ||
                 Tools.CharNum(lua["lua_run_result_var"].ToString(), "\r") > 40)
             {
                 result = "行数超过了20行,限制一下吧";
             }
             else if (lua["lua_run_result_var"].ToString().Length > 2000)
             {
                 result = "字数超过了2000,限制一下吧";
             }
             else
             {
                 result = lua["lua_run_result_var"].ToString();
             }
         }
         catch (Exception e)
         {
             string err = e.Message;
             int    l   = err.IndexOf("lua/");
             if (l >= 0)
             {
                 err = err.Substring(l);
             }
             result = "代码崩掉啦\r\n" + err;
         }
     }
 }
Exemple #7
0
 /// <summary>
 /// 在沙盒中运行代码,仅允许安全地运行
 /// </summary>
 /// <param name="code"></param>
 /// <returns></returns>
 public static string RunSandBox(string code)
 {
     using var lua = new NLua.Lua();
     try
     {
         lua.State.Encoding = Encoding.UTF8;
         lua.LoadCLRPackage();
         lua["lua_run_result_var"] = "";//返回值所在的变量
         lua.DoFile(Path + "lua/sandbox/head.lua");
         lua.DoString(code);
         return(lua["lua_run_result_var"].ToString());
     }
     catch (Exception e)
     {
         Log.Warn("lua沙盒错误", e.Message);
         return("运行错误:" + e.ToString());
     }
 }
Exemple #8
0
 /// <summary>
 /// 在沙盒中运行代码,仅允许安全地运行
 /// </summary>
 /// <param name="code"></param>
 /// <returns></returns>
 public static string RunSandBox(string code)
 {
     using var lua = new NLua.Lua();
     try
     {
         lua.State.Encoding = Encoding.UTF8;
         lua.LoadCLRPackage();
         lua["lua_run_result_var"] = "";//返回值所在的变量
         lua.DoFile(Common.AppData.CQApi.AppDirectory + "lua/sandbox/main.lua");
         lua.DoString(code);
         return(lua["lua_run_result_var"].ToString());
     }
     catch (Exception e)
     {
         Common.AppData.CQLog.Warning("lua沙盒错误", e.Message);
         return("运行错误:" + e.ToString());
     }
 }
Exemple #9
0
        /// <summary>
        /// Plays the macro on the current thread.
        /// </summary>
        private void PlayMacro()
        {
            if (CurrentMacro == null || CurrentMacro.MacroFile == null)
            {
                return;
            }

            IsPlaying = true;
            int currentRepetition = repetitions;

            while (currentRepetition > 0)
            {
                lua.DoFile(CurrentMacro.MacroFile);
                currentRepetition--;
            }

            IsPlaying = false;
        }
Exemple #10
0
 /// <summary>
 /// 在沙盒中运行代码,仅允许安全地运行
 /// </summary>
 /// <param name="code"></param>
 /// <returns></returns>
 public static string RunSandBox(string code)
 {
     using (var lua = new NLua.Lua())
     {
         try
         {
             lua.State.Encoding        = Encoding.UTF8;
             lua["lua_run_result_var"] = "";//返回值所在的变量
             lua.DoFile(Common.AppDirectory + "lua/require/sandbox/head.lua");
             lua.DoString(code);
             return(lua["lua_run_result_var"].ToString());
         }
         catch (Exception e)
         {
             Common.CqApi.AddLoger(Sdk.Cqp.Enum.LogerLevel.Error, "沙盒lua脚本错误", e.ToString());
             return("运行错误:" + e.ToString());
         }
     }
 }
Exemple #11
0
        public bool HasProperLua()
        {
            bool temp = false;

            if (!luaLoc.Equals(""))
            {
                try
                {
                    luaState = new NLua.Lua();
                    luaState.LoadCLRPackage();
                    luaState.DoFile(Game1.rootContent + luaLoc);
                    return(true);
                }
                catch (Exception)
                {
                }
            }

            return(temp);
        }
Exemple #12
0
        //private Dictionary<object, object>

        private void itmMainFileOpenManual_Click(object sender, EventArgs e)
        {
            if (dlgOpenSavedVars.ShowDialog() == DialogResult.OK)
            {
                NLua.Lua loadedVars = new NLua.Lua();
                try
                {
                    loadedVars.DoFile(dlgOpenSavedVars.FileName);

                    Dictionary <object, object> _elephantDB = loadedVars.GetTableDict(loadedVars.GetTable("ElephantDBPerChar"));
                    Dictionary <object, object> profileKeys = loadedVars.GetTableDict((NLua.LuaTable)_elephantDB["profileKeys"]);
                    //profileKeys[0] is null WHY?!?! how to get this value?
                    //Hey dummy, use profileKeys.ElementAt(0) instead!
                    MessageBox.Show(dlgOpenSavedVars.FileName + " loaded for " + profileKeys.First().Value + "!");
                }
                catch (NLua.Exceptions.LuaException ex)
                {
                    MessageBox.Show(ex.Message, "Error Parsing SavedVariables File", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
        public void CheckScript()
        {
            if (!functionName.Equals("") && levelUpScript == null && !scriptLoc.Equals("") || (bRecheckScript && !scriptLoc.Equals("")))
            {
                try
                {
                    levelUpScript = new NLua.Lua();
                    levelUpScript.LoadCLRPackage();
                    levelUpScript.DoFile(Game1.rootContent + scriptLoc);
                }
                catch (Exception e)
                {
                    levelUpScript = null;
                }
            }

            if (levelUpScript != null)
            {
                bHasProperScript = levelUpScript.GetFunction(functionName) != null;
            }
            bHasProperScript = levelUpScript != null;
        }
        internal bool CheckScript()
        {
            if (scriptFunction.Equals(""))
            {
                return(false);
            }
            else if (!scriptLoc.Equals(""))
            {
                NLua.Lua state = new NLua.Lua();
                state.LoadCLRPackage();
                try
                {
                    state.DoFile(Game1.rootContent + scriptLoc);
                }
                catch (Exception)
                {
                    script = null;
                    return(false);
                }

                bool bIsCorrectScriptAndFunction = state.GetFunction(scriptFunction) != null;
                if (bIsCorrectScriptAndFunction)
                {
                    script = state;
                    if (!modFunctionName.Equals(""))
                    {
                        modFunction = state.GetFunction(modFunctionName);
                    }
                    else
                    {
                        modFunction = null;
                    }

                    return(true);
                }
                return(false);
            }
            return(false);
        }
Exemple #15
0
 internal void Execute(LuaTurnSetInfo ltsi)
 {
     if (state == null)
     {
         state = new NLua.Lua();
         state.LoadCLRPackage();
         if (fileNameLoc.StartsWith(@"\"))
         {
             fileNameLoc = fileNameLoc.Remove(0, 1);
         }
         String comp = System.IO.Path.Combine(TBAGW.Game1.rootContent, fileNameLoc);
         state.DoFile(comp);
     }
     if (state.GetFunction(functionName) != null)
     {
         if (bNoParameter)
         {
             (state[functionName] as NLua.LuaFunction).Call();
         }
         else
         if (!bNoParameter)
         {
             //var temp = ltsi.otherGroups[0].RandomMember();
             if (eventType == EventType.updateEV)
             {
                 (state[functionName] as NLua.LuaFunction).Call(ltsi, msTime);
             }
             else
             {
                 (state[functionName] as NLua.LuaFunction).Call(ltsi);
             }
         }
     }
     else
     {
         Console.WriteLine("Lua error from " + fileNameLoc + " , @function-name " + functionName);
         eventType = EventType.None;
     }
 }
Exemple #16
0
 /// <summary>
 /// 在沙盒中运行代码,仅允许安全地运行
 /// </summary>
 /// <param name="code"></param>
 /// <returns></returns>
 public static string RunSandBox(string code)
 {
     using (var lua = new NLua.Lua())
     {
         try
         {
             lua.State.Encoding = Encoding.UTF8;
             lua.RegisterFunction("apiGetPath", null, typeof(LuaApi).GetMethod("GetPath"));
             //获取程序运行目录
             lua.RegisterFunction("apiGetAsciiHex", null, typeof(LuaApi).GetMethod("GetAsciiHex"));
             //获取字符串ascii编码的hex串
             lua["lua_run_result_var"] = "";//返回值所在的变量
             lua.DoFile(Common.AppDirectory + "lua/require/sandbox/head.lua");
             lua.DoString(code);
             return(lua["lua_run_result_var"].ToString());
         }
         catch (Exception e)
         {
             Common.CqApi.AddLoger(Sdk.Cqp.Enum.LogerLevel.Error, "沙盒lua脚本错误", e.ToString());
             return("运行错误:" + e.ToString());
         }
     }
 }
Exemple #17
0
 /// <summary>
 /// 运行lua文件
 /// </summary>
 /// <param name="code">提前运行的代码</param>
 /// <param name="file">文件路径(app/xxx.xxx.xx/lua/开头)</param>
 public static bool RunLua(string code, string file)
 {
     using (var lua = new NLua.Lua())
     {
         try
         {
             lua.State.Encoding = Encoding.UTF8;
             lua["handled"]     = false;//处理标志
             Initial(lua);
             lua.DoString(code);
             if (file != "")
             {
                 lua.DoFile(Common.AppDirectory + "lua/" + file);
             }
             return((bool)lua["handled"]);
         }
         catch (Exception e)
         {
             Common.CqApi.AddLoger(Sdk.Cqp.Enum.LogerLevel.Error, "lua脚本错误", e.ToString());
             return(false);
         }
     }
 }
Exemple #18
0
        /// <summary>
        /// 运行lua文件
        /// </summary>
        /// <param name="code">提前运行的代码</param>
        /// <param name="file">文件路径(app/xxx.xxx.xx/lua/开头)</param>
        public static bool RunLua(string code, string file, ArrayList args = null)
        {
            //还没下载lua脚本,先不响应消息
            if (!File.Exists(Common.AppDirectory + "lua/require/head.lua"))
            {
                return(false);
            }

            using (var lua = new NLua.Lua())
            {
                try
                {
                    lua.State.Encoding = Encoding.UTF8;
                    lua.LoadCLRPackage();
                    lua["handled"] = false;//处理标志
                    Initial(lua);
                    if (args != null)
                    {
                        for (int i = 0; i < args.Count; i += 2)
                        {
                            lua[(string)args[i]] = args[i + 1];
                        }
                    }
                    lua.DoString(code);
                    if (file != "")
                    {
                        lua.DoFile(Common.AppDirectory + "lua/" + file);
                    }
                    return((bool)lua["handled"]);
                }
                catch (Exception e)
                {
                    Common.CqApi.AddLoger(Sdk.Cqp.Enum.LogerLevel.Error, "lua脚本错误", e.ToString());
                    return(false);
                }
            }
        }
Exemple #19
0
        public void InitLUA(Channel Channel)
        {
            ParentChannel = Channel;
            string chName = Channel.Name;

            Environment = new NLua.Lua();

            RegisterLUAFunctions();

            //We should retrieve modules before looping through to load them.

            foreach (Module module in Modules)
            {
                try
                {
                    LoadModule(module);
                } catch
                {
                    // Do nothing for now
                }
            }
            // Now you can start loading channel code.
            string channelLUA = "channels" + Config.Folders.FolderSplit + chName + Config.Folders.FolderSplit + Config.LUA.DefaultFile;

            try
            {
                if (File.Exists(channelLUA))
                {
                    Environment.DoFile(channelLUA);// We should probably avoid loading the LUA files with LoadFile and instead make a command loading this into a sandbox?
                }
                // https://github.com/kikito/sandbox.lua/blob/master/sandbox.lua
            } catch
            {
                // Do nothing for now
            }
        }
Exemple #20
0
        /// <summary>
        /// 初始化lua对象
        /// </summary>
        /// <param name="lua"></param>
        /// <returns></returns>
        public static void Initial(NLua.Lua lua)
        {
            ///////////////
            //酷q类的接口//
            //////////////
            lua.RegisterFunction("cqCode_At", null, typeof(LuaApi).GetMethod("CqCode_At"));
            //获取酷Q "At某人" 代码
            lua.RegisterFunction("cqCqCode_Emoji", null, typeof(LuaApi).GetMethod("CqCode_Emoji"));
            //获取酷Q "emoji表情" 代码
            lua.RegisterFunction("cqCqCode_Face", null, typeof(LuaApi).GetMethod("CqCode_Face"));
            //获取酷Q "表情" 代码
            lua.RegisterFunction("cqCqCode_Shake", null, typeof(LuaApi).GetMethod("CqCode_Shake"));
            //获取酷Q "窗口抖动" 代码
            lua.RegisterFunction("cqCqCode_Trope", null, typeof(LuaApi).GetMethod("CqCode_Trope"));
            //获取字符串的转义形式
            lua.RegisterFunction("cqCqCode_UnTrope", null, typeof(LuaApi).GetMethod("CqCode_UnTrope"));
            //获取字符串的非转义形式
            lua.RegisterFunction("cqCqCode_ShareLink", null, typeof(LuaApi).GetMethod("CqCode_ShareLink"));
            //获取酷Q "链接分享" 代码
            lua.RegisterFunction("cqCqCode_ShareCard", null, typeof(LuaApi).GetMethod("CqCode_ShareCard"));
            //获取酷Q "名片分享" 代码
            lua.RegisterFunction("cqCqCode_ShareGPS", null, typeof(LuaApi).GetMethod("CqCode_ShareGPS"));
            //获取酷Q "位置分享" 代码
            lua.RegisterFunction("cqCqCode_Anonymous", null, typeof(LuaApi).GetMethod("CqCode_Anonymous"));
            //获取酷Q "匿名" 代码
            lua.RegisterFunction("cqCqCode_Image", null, typeof(LuaApi).GetMethod("CqCode_Image"));
            //获取酷Q "图片" 代码
            lua.RegisterFunction("cqCqCode_Music", null, typeof(LuaApi).GetMethod("CqCode_Music"));
            //获取酷Q "音乐" 代码
            lua.RegisterFunction("cqCqCode_MusciDIY", null, typeof(LuaApi).GetMethod("CqCode_MusciDIY"));
            //获取酷Q "音乐自定义" 代码
            lua.RegisterFunction("cqCqCode_Record", null, typeof(LuaApi).GetMethod("CqCode_Record"));
            //获取酷Q "语音" 代码
            lua.RegisterFunction("cqSendGroupMessage", null, typeof(LuaApi).GetMethod("SendGroupMessage"));
            //发送群消息
            lua.RegisterFunction("cqSendPrivateMessage", null, typeof(LuaApi).GetMethod("SendPrivateMessage"));
            //发送私聊消息
            lua.RegisterFunction("cqSendDiscussMessage", null, typeof(LuaApi).GetMethod("SendDiscussMessage"));
            //发送讨论组消息
            lua.RegisterFunction("cqSendPraise", null, typeof(LuaApi).GetMethod("SendPraise"));
            //发送赞
            lua.RegisterFunction("cqRepealMessage", null, typeof(LuaApi).GetMethod("RepealMessage"));
            //撤回消息
            lua.RegisterFunction("cqGetLoginQQ", null, typeof(LuaApi).GetMethod("GetLoginQQ"));
            //取登录QQ
            lua.RegisterFunction("cqGetLoginNick", null, typeof(LuaApi).GetMethod("GetLoginNick"));
            //获取当前登录QQ的昵称
            lua.RegisterFunction("cqAppDirectory", null, typeof(LuaApi).GetMethod("GetAppDirectory"));
            //取应用目录
            lua.RegisterFunction("cqGetMemberInfo", null, typeof(LuaApi).GetMethod("GetMemberInfo"));
            //获取群成员信息
            lua.RegisterFunction("cqAddLoger", null, typeof(LuaApi).GetMethod("AddLoger"));
            //添加日志
            lua.RegisterFunction("cqAddFatalError", null, typeof(LuaApi).GetMethod("AddFatalError"));
            //添加致命错误提示
            lua.RegisterFunction("cqSetGroupWholeBanSpeak", null, typeof(LuaApi).GetMethod("SetGroupWholeBanSpeak"));
            //置全群禁言
            lua.RegisterFunction("cqSetGroupMemberNewCard", null, typeof(LuaApi).GetMethod("SetGroupMemberNewCard"));
            //置群成员名片
            lua.RegisterFunction("cqSetGroupManager", null, typeof(LuaApi).GetMethod("SetGroupManager"));
            //置群管理员
            lua.RegisterFunction("cqSetAnonymousStatus", null, typeof(LuaApi).GetMethod("SetAnonymousStatus"));
            //置群匿名设置
            lua.RegisterFunction("cqSetGroupMemberRemove", null, typeof(LuaApi).GetMethod("SetGroupMemberRemove"));
            //置群员移除
            lua.RegisterFunction("cqSetDiscussExit", null, typeof(LuaApi).GetMethod("SetDiscussExit"));
            //置讨论组退出
            lua.RegisterFunction("cqSetGroupSpecialTitle", null, typeof(LuaEnv).GetMethod("SetGroupSpecialTitle"));
            //置群成员专属头衔
            lua.RegisterFunction("cqSetGroupAnonymousBanSpeak", null, typeof(LuaEnv).GetMethod("SetGroupAnonymousBanSpeak"));
            //置匿名群员禁言
            lua.RegisterFunction("cqSetGroupBanSpeak", null, typeof(LuaEnv).GetMethod("SetGroupBanSpeak"));
            //置群员禁言
            lua.RegisterFunction("cqSetFriendAddRequest", null, typeof(LuaApi).GetMethod("SetFriendAddRequest"));
            //置好友添加请求
            lua.RegisterFunction("cqSetGroupAddRequest", null, typeof(LuaApi).GetMethod("SetGroupAddRequest"));
            //置群添加请求

            /////////////
            //工具类接口//
            /////////////
            lua.RegisterFunction("apiGetPath", null, typeof(LuaApi).GetMethod("GetPath"));
            //获取程序运行目录
            lua.RegisterFunction("apiGetBitmap", null, typeof(LuaApi).GetMethod("GetBitmap"));
            //获取图片对象
            lua.RegisterFunction("apiPutText", null, typeof(LuaApi).GetMethod("PutText"));
            //摆放文字
            lua.RegisterFunction("apiPutBlock", null, typeof(LuaApi).GetMethod("PutBlock"));
            //填充矩形
            lua.RegisterFunction("apiSetImage", null, typeof(LuaApi).GetMethod("SetImage"));
            //摆放图片
            lua.RegisterFunction("apiGetDir", null, typeof(LuaApi).GetMethod("GetDir"));
            //保存并获取图片路径

            lua.RegisterFunction("apiGetImagePath", null, typeof(LuaApi).GetMethod("GetImagePath"));
            //获取qq消息中图片的网址

            lua.RegisterFunction("apiHttpDownload", null, typeof(LuaApi).GetMethod("HttpDownload"));
            //下载文件
            lua.RegisterFunction("apiHttpGet", null, typeof(LuaApi).GetMethod("HttpGet"));
            //GET 请求与获取结果
            lua.RegisterFunction("apiHttpPost", null, typeof(LuaApi).GetMethod("HttpPost"));
            //POST 请求与获取结果
            lua.RegisterFunction("apiBase64File", null, typeof(LuaApi).GetMethod("Base64File"));
            //获取在线文件的base64结果
            lua.RegisterFunction("apiGetPictureWidth", null, typeof(LuaApi).GetMethod("GetPictureWidth"));
            //获取在线文件的base64结果
            lua.RegisterFunction("apiGetPictureHeight", null, typeof(LuaApi).GetMethod("GetPictureHeight"));
            //获取在线文件的base64结果
            lua.RegisterFunction("apiSetVar", null, typeof(LuaApi).GetMethod("SetVar"));
            //设置某值存入ram
            lua.RegisterFunction("apiGetVar", null, typeof(LuaApi).GetMethod("GetVar"));
            //取出某缓存的值
            lua.RegisterFunction("apiGetAsciiHex", null, typeof(LuaApi).GetMethod("GetAsciiHex"));
            //获取字符串ascii编码的hex串

            lua.RegisterFunction("apiGetHardDiskFreeSpace", null, typeof(Tools).GetMethod("GetHardDiskFreeSpace"));
            //获取指定驱动器的剩余空间总大小(单位为MB)
            lua.RegisterFunction("apiMD5Encrypt", null, typeof(Tools).GetMethod("MD5Encrypt"));
            //计算MD5

            lua.RegisterFunction("apiTcpSend", null, typeof(TcpServer).GetMethod("Send"));
            //发送tcp广播数据

            lua.RegisterFunction("apiSandBox", null, typeof(LuaEnv).GetMethod("RunSandBox"));
            //沙盒环境

            ///////////////
            //XML操作接口//
            //////////////
            lua.RegisterFunction("apiXmlReplayGet", null, typeof(XmlApi).GetMethod("replay_get"));
            //随机获取一条结果
            lua.RegisterFunction("apiXmlListGet", null, typeof(XmlApi).GetMethod("list_get"));
            //获取所有回复的列表
            lua.RegisterFunction("apiXmlDelete", null, typeof(XmlApi).GetMethod("del"));
            //删除所有匹配的条目
            lua.RegisterFunction("apiXmlRemove", null, typeof(XmlApi).GetMethod("remove"));
            //删除完全匹配的第一个条目
            lua.RegisterFunction("apiXmlInsert", null, typeof(XmlApi).GetMethod("insert"));
            //插入一个词条
            lua.RegisterFunction("apiXmlSet", null, typeof(XmlApi).GetMethod("set"));
            //更改某条的值
            lua.RegisterFunction("apiXmlGet", null, typeof(XmlApi).GetMethod("xml_get"));
            //获取某条的结果
            lua.RegisterFunction("apiXmlRow", null, typeof(XmlApi).GetMethod("xml_row"));
            //按结果查源头(反查)

            lua.DoFile(Common.AppDirectory + "lua/require/head.lua");
        }
Exemple #21
0
 public object[] DoFile(string sLuaFile)
 {
     return(mLua.DoFile(sLuaFile));
 }
Exemple #22
0
 public void DoFile(string fileName)
 {
     lua.DoFile(fileName);
 }
Exemple #23
0
 public static void SetupLuaUtils(Random r)
 {
     NLua.Lua L = new NLua.Lua();
     L.DoFile(TBAGW.Game1.rootContent + "LUA\\" + "utils.lua");
 }
Exemple #24
0
        /// <summary>
        /// 初始化lua对象
        /// </summary>
        /// <param name="lua"></param>
        /// <returns></returns>
        public static void Initial(NLua.Lua lua)
        {
            ///////////////
            //酷q类的接口//
            //////////////
            lua.RegisterFunction("cqCode_At", null, typeof(LuaApi).GetMethod("CqCode_At"));
            //获取酷Q "At某人" 代码
            lua.RegisterFunction("cqCqCode_Emoji", null, typeof(LuaApi).GetMethod("CqCode_Emoji"));
            //获取酷Q "emoji表情" 代码
            lua.RegisterFunction("cqCqCode_Face", null, typeof(LuaApi).GetMethod("CqCode_Face"));
            //获取酷Q "表情" 代码
            lua.RegisterFunction("cqCqCode_Shake", null, typeof(LuaApi).GetMethod("CqCode_Shake"));
            //获取酷Q "窗口抖动" 代码
            lua.RegisterFunction("cqCqCode_Trope", null, typeof(LuaApi).GetMethod("CqCode_Trope"));
            //获取字符串的转义形式
            lua.RegisterFunction("cqCqCode_UnTrope", null, typeof(LuaApi).GetMethod("CqCode_UnTrope"));
            //获取字符串的非转义形式
            lua.RegisterFunction("cqCqCode_ShareLink", null, typeof(LuaApi).GetMethod("CqCode_ShareLink"));
            //获取酷Q "链接分享" 代码
            lua.RegisterFunction("cqCqCode_ShareCard", null, typeof(LuaApi).GetMethod("CqCode_ShareCard"));
            //获取酷Q "名片分享" 代码
            lua.RegisterFunction("cqCqCode_ShareGPS", null, typeof(LuaApi).GetMethod("CqCode_ShareGPS"));
            //获取酷Q "位置分享" 代码
            lua.RegisterFunction("cqCqCode_Anonymous", null, typeof(LuaApi).GetMethod("CqCode_Anonymous"));
            //获取酷Q "匿名" 代码
            lua.RegisterFunction("cqCqCode_Image", null, typeof(LuaApi).GetMethod("CqCode_Image"));
            //获取酷Q "图片" 代码
            lua.RegisterFunction("cqCqCode_Music", null, typeof(LuaApi).GetMethod("CqCode_Music"));
            //获取酷Q "音乐" 代码
            lua.RegisterFunction("cqCqCode_MusciDIY", null, typeof(LuaApi).GetMethod("CqCode_MusciDIY"));
            //获取酷Q "音乐自定义" 代码
            lua.RegisterFunction("cqCqCode_Record", null, typeof(LuaApi).GetMethod("CqCode_Record"));
            //获取酷Q "语音" 代码
            lua.RegisterFunction("cqSendGroupMessage", null, typeof(LuaApi).GetMethod("SendGroupMessage"));
            //发送群消息
            lua.RegisterFunction("cqSendPrivateMessage", null, typeof(LuaApi).GetMethod("SendPrivateMessage"));
            //发送私聊消息
            lua.RegisterFunction("cqSendDelyMessage", null, typeof(LuaApi).GetMethod("SendDelyMessage"));
            //发送延迟消息
            lua.RegisterFunction("cqSendDiscussMessage", null, typeof(LuaApi).GetMethod("SendDiscussMessage"));
            //发送讨论组消息
            lua.RegisterFunction("cqSendPraise", null, typeof(LuaApi).GetMethod("SendPraise"));
            //发送赞
            lua.RegisterFunction("cqRepealMessage", null, typeof(LuaApi).GetMethod("RepealMessage"));
            //撤回消息
            lua.RegisterFunction("cqGetLoginQQ", null, typeof(LuaApi).GetMethod("GetLoginQQ"));
            //取登录QQ
            lua.RegisterFunction("cqGetLoginNick", null, typeof(LuaApi).GetMethod("GetLoginNick"));
            //获取当前登录QQ的昵称
            lua.RegisterFunction("cqAppDirectory", null, typeof(LuaApi).GetMethod("GetAppDirectory"));
            //取应用目录
            lua.RegisterFunction("cqGetMemberInfo", null, typeof(LuaApi).GetMethod("GetMemberInfo"));
            //获取群成员信息
            lua.RegisterFunction("cqGetMemberList", null, typeof(LuaApi).GetMethod("GetMemberList"));
            //获取全部群成员信息
            lua.RegisterFunction("cqGetGroupList", null, typeof(LuaApi).GetMethod("GetGroupList"));
            //获取群列表
            lua.RegisterFunction("cqAddLoger", null, typeof(LuaApi).GetMethod("AddLoger"));
            //添加日志
            lua.RegisterFunction("cqAddFatalError", null, typeof(LuaApi).GetMethod("AddFatalError"));
            //添加致命错误提示
            lua.RegisterFunction("cqSetGroupWholeBanSpeak", null, typeof(LuaApi).GetMethod("SetGroupWholeBanSpeak"));
            //置全群禁言
            lua.RegisterFunction("cqSetGroupMemberNewCard", null, typeof(LuaApi).GetMethod("SetGroupMemberNewCard"));
            //置群成员名片
            lua.RegisterFunction("cqSetGroupManager", null, typeof(LuaApi).GetMethod("SetGroupManager"));
            //置群管理员
            lua.RegisterFunction("cqSetAnonymousStatus", null, typeof(LuaApi).GetMethod("SetAnonymousStatus"));
            //置群匿名设置
            lua.RegisterFunction("cqSetGroupMemberRemove", null, typeof(LuaApi).GetMethod("SetGroupMemberRemove"));
            //置群员移除
            lua.RegisterFunction("cqSetDiscussExit", null, typeof(LuaApi).GetMethod("SetDiscussExit"));
            //置讨论组退出
            lua.RegisterFunction("cqSetGroupSpecialTitle", null, typeof(LuaApi).GetMethod("SetGroupSpecialTitle"));
            //置群成员专属头衔
            lua.RegisterFunction("cqSetGroupAnonymousBanSpeak", null, typeof(LuaApi).GetMethod("SetGroupAnonymousBanSpeak"));
            //置匿名群员禁言
            lua.RegisterFunction("cqSetGroupBanSpeak", null, typeof(LuaApi).GetMethod("SetGroupBanSpeak"));
            //置群员禁言
            lua.RegisterFunction("cqSetFriendAddRequest", null, typeof(LuaApi).GetMethod("SetFriendAddRequest"));
            //置好友添加请求
            lua.RegisterFunction("cqSetGroupAddRequest", null, typeof(LuaApi).GetMethod("SetGroupAddRequest"));
            //置群添加请求
            lua.RegisterFunction("cqSetGroupExit", null, typeof(LuaApi).GetMethod("SetGroupExit"));
            //置群退出


            /////////////
            //工具类接口//
            /////////////
            lua.RegisterFunction("apiGetPath", null, typeof(LuaApi).GetMethod("GetPath"));
            //获取程序运行目录
            lua.RegisterFunction("apiGetAppName", null, typeof(LuaApi).GetMethod("GetAppName"));
            //获取插件包名
            lua.RegisterFunction("apiGetBitmap", null, typeof(LuaApi).GetMethod("GetBitmap"));
            //获取图片对象
            lua.RegisterFunction("apiPutText", null, typeof(LuaApi).GetMethod("PutText"));
            //摆放文字
            lua.RegisterFunction("apiPutBlock", null, typeof(LuaApi).GetMethod("PutBlock"));
            //填充矩形
            lua.RegisterFunction("apiSetImage", null, typeof(LuaApi).GetMethod("SetImage"));
            //摆放图片
            lua.RegisterFunction("apiGetDir", null, typeof(LuaApi).GetMethod("GetDir"));
            //保存并获取图片路径
            lua.RegisterFunction("apiGetImagePath", null, typeof(LuaApi).GetMethod("GetImagePath"));
            //获取qq消息中图片的网址
            lua.RegisterFunction("apiHttpFileDownload", null, typeof(LuaApi).GetMethod("HttpFileDownload"));
            //下载文件
            lua.RegisterFunction("apiHttpImageDownload", null, typeof(LuaApi).GetMethod("HttpImageDownload"));
            //爬取图片
            lua.RegisterFunction("apiHttpGet", null, typeof(LuaApi).GetMethod("HttpGet"));
            //GET 请求与获取结果
            lua.RegisterFunction("apiHttpPost", null, typeof(LuaApi).GetMethod("HttpPost"));
            //POST 请求与获取结果
            lua.RegisterFunction("apiBase64File", null, typeof(LuaApi).GetMethod("Base64File"));
            //获取在线文件的base64结果
            lua.RegisterFunction("apiGetPictureWidth", null, typeof(LuaApi).GetMethod("GetPictureWidth"));
            //获取在线文件的base64结果
            lua.RegisterFunction("apiGetPictureHeight", null, typeof(LuaApi).GetMethod("GetPictureHeight"));
            //获取在线文件的base64结果
            lua.RegisterFunction("apiSetVar", null, typeof(LuaApi).GetMethod("SetVar"));
            //设置某值存入ram
            lua.RegisterFunction("apiGetVar", null, typeof(LuaApi).GetMethod("GetVar"));
            //取出某缓存的值
            lua.RegisterFunction("apiDirectoryList", null, typeof(LuaApi).GetMethod("DirectoryList"));
            //获取xml目录下的文件夹列表
            lua.RegisterFunction("apiFileList", null, typeof(LuaApi).GetMethod("FileList"));
            //获取xml目录下的文件列表
            lua.RegisterFunction("apiGetAsciiHex", null, typeof(LuaApi).GetMethod("GetAsciiHex"));
            //获取字符串ascii编码的hex串
            lua.RegisterFunction("apiSetTimerScriptWait", null, typeof(LuaApi).GetMethod("SetTimerScriptWait"));
            //设置定时脚本运行间隔时间
            lua.RegisterFunction("apiGetHardDiskFreeSpace", null, typeof(Tools).GetMethod("GetHardDiskFreeSpace"));
            //获取指定驱动器的剩余空间总大小(单位为MB)
            lua.RegisterFunction("apiMD5Encrypt", null, typeof(Tools).GetMethod("MD5Encrypt"));
            //计算MD5
            lua.RegisterFunction("apiSandBox", null, typeof(LuaEnv).GetMethod("RunSandBox"));
            //沙盒环境
            lua.RegisterFunction("apiOrderSearch", null, typeof(LuaApi).GetMethod("OrderSearch"));
            //单号识别
            lua.RegisterFunction("apiNowSearch", null, typeof(LuaApi).GetMethod("NowSearch"));
            //快递查询
            lua.RegisterFunction("apiOrderSub", null, typeof(LuaApi).GetMethod("OrderSub"));
            //快递订阅
            lua.RegisterFunction("apiservice", null, typeof(TcpSer).GetMethod("service"));
            //开启tcp服务器
            lua.RegisterFunction("apiclient", null, typeof(TcpSer).GetMethod("client"));
            //连接tcp服务器
            lua.RegisterFunction("apiListenStart", null, typeof(HttpListenerPostParaHelper).GetMethod("ListenStart"));
            //开启httprequest监听
            lua.RegisterFunction("apiGetResponseHeaders", null, typeof(LuaApi).GetMethod("GetResponseHeaders"));
            //获取response header头
            lua.RegisterFunction("apiTimerStart", null, typeof(TimerRun).GetMethod("TimerStart"));
            //开启循环任务
            lua.RegisterFunction("apiGeneralBasic", null, typeof(BaiDuApi).GetMethod("GeneralBasic"));
            //本地图片文字识别
            lua.RegisterFunction("apiGeneralBasicUrl", null, typeof(BaiDuApi).GetMethod("GeneralBasicUrl"));
            //链接图片文字识别
            lua.RegisterFunction("apiAdvancedGeneral", null, typeof(BaiDuApi).GetMethod("AdvancedGeneral"));
            //图像识别
            lua.RegisterFunction("apiQREncode", null, typeof(QRCode).GetMethod("QREncode"));
            //二维码生成
            lua.RegisterFunction("apiQRDecode", null, typeof(QRCode).GetMethod("QRDecode"));
            //二维码解码
            lua.RegisterFunction("apiCombinImage", null, typeof(QRCode).GetMethod("CombinImage"));
            //二维码logo生成


            ///////////////
            //XML操作接口//
            //////////////
            lua.RegisterFunction("apiXmlReplayGet", null, typeof(XmlApi).GetMethod("replay_get"));
            //随机获取一条结果
            lua.RegisterFunction("apiXmlListGet", null, typeof(XmlApi).GetMethod("alist_get"));
            //获取所有回复的列表
            lua.RegisterFunction("apiXmlDelete", null, typeof(XmlApi).GetMethod("del"));
            //删除所有匹配的条目
            lua.RegisterFunction("apiXmlRemove", null, typeof(XmlApi).GetMethod("remove"));
            //删除完全匹配的第一个条目
            lua.RegisterFunction("apiXmlInsert", null, typeof(XmlApi).GetMethod("insert"));
            //插入一个词条
            lua.RegisterFunction("apiXmlSet", null, typeof(XmlApi).GetMethod("set"));
            //更改某条的值
            lua.RegisterFunction("apiXmlGet", null, typeof(XmlApi).GetMethod("xml_get"));
            //获取某条的结果
            lua.RegisterFunction("apiXmlRow", null, typeof(XmlApi).GetMethod("xml_row"));
            //按结果查源头(反查)
            lua.RegisterFunction("apiXmlIdListGet", null, typeof(XmlApi).GetMethod("nlist_get"));
            //获取所有号码id列表

            lua.DoFile(Common.AppDirectory + "lua/require/head.lua");
        }
 public void ReloadDataFromLuaStringFile(String luaLoc)
 {
     NLua.Lua lua = new NLua.Lua();
     lua.DoFile(luaLoc);
 }
        public static void Test()
        {
            NLua.Lua state = new NLua.Lua();

            NLua.Lua state2 = new NLua.Lua();

            someData sd = new someData();

            sd.ID = 25;
            sd.sList.AddRange(new String[] { "this", " is", " a", " test", " list" });
            luaData ld = new luaData(sd);


            //var test = state.DoString("return 10 + 3*(5 + 2)")[0];
            //var type = test.GetType();

            //int value = 6;
            //state["test"] = value;
            //var result = state.DoString("return test*3+(test-3)")[0];

            //state.DoString(@"
            // function ScriptFunc (val1, val2)
            //     val1=val1+2
            //     val2=val2+3
            //     return val1, val2
            //  end");

            //var scriptFunc = state["ScriptFunc"] as NLua.LuaFunction;
            //var res = scriptFunc.Call(3, 5);

            testClass tc = new testClass("Some test string here");

            tc.list.Add(25);
            state["provision"] = "Random piece of information";



            testClass tc2 = new testClass("Indirect summon");

            tc2.data = ld;
            tc2.ProvideInfoToLua(state);
            //state["testObj"] = tc;

            state.LoadCLRPackage();
            // state.DoString(@" import ('The betrayer', 'TBAGW.Utilities')
            //   import ('System.Web')
            //    import ('System')");

            // var testStringFromObject = state.DoString("return TestObject.testList[0]")[0];
            // var elementType = testStringFromObject.GetType();
            // testClass testObjFromLUA = state.DoString("return TestObject")[0] as testClass;
            //bool bWhat = testObjFromLUA.GetType() == tc.GetType();

            state.DoString("print(\"Hello World\")");

            System.Windows.Forms.OpenFileDialog ofd = new System.Windows.Forms.OpenFileDialog();
            ofd.Filter           = "LUA files (*.lua)|*.lua";
            ofd.InitialDirectory = Game1.rootContent;
            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                state = new NLua.Lua();
                state.LoadCLRPackage();
                state.DoFile(ofd.FileName);
                var time = System.IO.File.GetLastWriteTime(ofd.FileName);
            }
            //var statsTest = ((state["generateSomeStats"] as NLua.LuaFunction).Call()[0] as LuaStatEdit).ExtractStatChart();

            //BaseSprite bs = new BaseSprite();
            //bs.position = new Vector2(136, 2556);
            //if (Scenes.Editor.MapBuilder.loadedMap != null)
            //{
            //    bs.UpdatePosition();
            //}
            // List<List<Object>> luaStuff = new List<List<object>>();
            //var ttt = (state["save"] as NLua.LuaFunction).Call()[0].GetType();
            (state["save"] as NLua.LuaFunction).Call();
            var st = LuaSaveData.getGlobalData("My Collection", "luaStuff");

            (state["loadProcess"] as NLua.LuaFunction).Call();
            //var dabdab = ((state["getShapeData"] as NLua.LuaFunction).Call(bs));
            //  NLua.LuaFunction savedFunction = state["e1.Test"] as NLua.LuaFunction;
            uic = ((state["createUI"] as NLua.LuaFunction).Call()[0] as LuaUICollection).ConvertFromLua(state);
            goto skip;
            var luaRect = ShapeAnimation.animFromLuaInfo(((state["generateAnimation"] as NLua.LuaFunction).Call()[0] as LuaShapeAnimationInfo));
            var resldo  = (state["returnLuaSpecificData"] as NLua.LuaFunction).Call()[0];

            NLua.LuaTable lt = (state["returnLuaSpecificData"] as NLua.LuaFunction).Call()[0] as NLua.LuaTable;
            (state["GenerateSomeStuff"] as NLua.LuaFunction).Call();
            ListDataProvider.setLuaData(state);
            (state["publicStaticCall"] as NLua.LuaFunction).Call();
            (state["internalStaticCall"] as NLua.LuaFunction).Call();
            state["testObj"] = tc;
            var ele2                     = (state["attempt"] as NLua.LuaFunction).Call()[0];
            var returnedData             = (state["returnData"] as NLua.LuaFunction).Call()[0];
            var oldProvision             = state["provision"];
            var value2                   = state["testObj.i"];
            var function                 = state["MyFunc"] as NLua.LuaFunction;
            var funcRes                  = function.Call(state["testObj.i"])[0];
            var tableResult              = (state["returnTable"] as NLua.LuaFunction).Call()[0];
            var bCompare1                = tableResult.GetType() == typeof(NLua.LuaTable);
            var tableToList              = LUAUtilities.LUATableToListUtility(typeof(testClass), tableResult as NLua.LuaTable).Cast <testClass>().ToList();
            var tableToListGenericObject = LUAUtilities.LUATableToListUtility(typeof(testClass), tableResult as NLua.LuaTable);
            var listType                 = tableToList.GetType();
            var listTypeGO               = tableToListGenericObject.GetType();



            state = new NLua.Lua();
            state.LoadCLRPackage();
            state.DoFile(ofd.FileName);
            List <testClass> tcl = new List <testClass>();

            tcl.Add(new testClass(""));
            tcl.Last().i = 25;
            tcl.Add(new testClass(""));
            tcl.Last().i = 0;
            tcl.Add(new testClass(""));
            tcl.Last().i = 10;
            foreach (var item in tcl)
            {
                (state["setStuff"] as NLua.LuaFunction).Call(item);
            }

            tcl = LUAUtilities.LUATableToListUtility(typeof(testClass), (state["doStuff"] as NLua.LuaFunction).Call()[0] as NLua.LuaTable).Cast <testClass>().ToList();
            skip : { }
            bDoTest = false;
        }