示例#1
0
        static int setOnPhysKeyListener(int L)
        {
            if (!LuaCommon.CheckAndShowArgsError(L, LConst.NFuction))
            {
                return(0);
            }
            if (L != LuaManager.RootLuaManager.L)//物理键注册lua方法的行为只对根任务(RootLuaManager)有效,子任务中不注册物理键返回函数
            {
                return(0);
            }
            int oldListener = LuaManager.RootLuaManager.OnBackspaceListener;

            if (Lua.Lua_isnil(L, 2))
            {
                if (oldListener == 0)
                {
                    return(0);
                }
                Lua.LuaL_unref(L, Lua._LUA_REGISTRYINDEX, oldListener);
                LuaManager.RootLuaManager.OnBackspaceListener = 0;
                return(0);
            }
            if (oldListener != 0)
            {
                Lua.LuaL_unref(L, Lua._LUA_REGISTRYINDEX, oldListener);
                LuaManager.RootLuaManager.OnBackspaceListener = 0;
            }
            int callBackF = Lua.LuaL_ref(L, Lua._LUA_REGISTRYINDEX);

            if (callBackF != 0)
            {
                LuaManager.RootLuaManager.OnBackspaceListener = callBackF;
            }
            return(0);
        }
示例#2
0
        static int showContent(int L)
        {
            if (!LuaCommon.CheckAndShowArgsError(L, LConst.String, LConst.Integer, LConst.NInteger))
            {
                return(0);
            }

            string content        = Lua.Lua_tostring(L, 2).ToString();
            var    tagId          = Lua.Lua_tointeger(L, 3);
            int    transitionType = -1;

            if (Lua.Lua_gettop(L) == 4)
            {
                transitionType = Lua.Lua_tointeger(L, 4);
            }
            object page = LuaManager.GetLuaManager(L).DetailV_;
            var    mi   = page.GetType().GetMethod("showContent", new Type[] { typeof(string), typeof(int), typeof(int) });

            if (mi != null)
            {
                Object[] pars = new Object[] { content, tagId, transitionType };
                mi.Invoke(page, pars);
            }
            return(0);
        }
示例#3
0
        static int setPhysicalkeyListener(int L)
        {
            if (!LuaCommon.CheckAndShowArgsError(L, LConst.String, LConst.Function))
            {
                return(0);
            }
            if (L != LuaManager.RootLuaManager.L)//物理键注册lua方法的行为只对根任务(RootLuaManager)有效,子任务中不注册物理键返回函数
            {
                return(0);
            }
            string key = Lua.Lua_tostring(L, 2).ToString();

            if (!string.IsNullOrEmpty(key) && key.Equals("backspace", StringComparison.CurrentCultureIgnoreCase))
            {
                object       page        = LuaManager.GetLuaManager(L).DetailV_;
                PropertyInfo pi          = page.GetType().GetProperty("BackspaceListener");
                int          oldListener = (int)pi.GetValue(page);
                if (oldListener != 0)
                {
                    Lua.LuaL_unref(L, Lua._LUA_REGISTRYINDEX, oldListener);
                    pi.SetValue(page, 0, null);
                }
                int callBackF = Lua.LuaL_ref(L, Lua._LUA_REGISTRYINDEX);
                if (callBackF != 0)
                {
                    pi.SetValue(page, callBackF, null);
                }
            }
            return(0);
        }
示例#4
0
        static int showControl(int L)
        {
            try
            {
                if (!LuaCommon.CheckAndShowArgsError(L, LConst.UserData, LConst.Integer, LConst.NInteger, LConst.NString))
                {
                    return(0);
                }

                Object control        = Lua.Lua_touserdata(L, 2);
                int    tagId          = Lua.Lua_tointeger(L, 3);
                int    transitionType = -1;
                bool   isMode         = true;
                int    top            = Lua.Lua_gettop(L);
                if (top >= 4)
                {
                    transitionType = Lua.Lua_tointeger(L, 4);
                }
                if (top >= 5)
                {
                    string mode = Lua.Lua_tostring(L, 5);
                    if (!string.IsNullOrEmpty(mode) && mode.Equals("false"))
                    {
                        isMode = false;
                    }
                }
                object     page    = LuaManager.GetLuaManager(L).DetailV_;
                MethodInfo methods = page.GetType().GetMethod("showControl");
                if (methods != null)
                {
                    Object[] pars = new Object[] { control, tagId, transitionType, isMode };
                    methods.Invoke(page, pars);
                }
            }
            catch
            {
            }

            return(0);
        }
示例#5
0
        static int abort(int L)
        {
            if (!LuaCommon.CheckAndShowArgsError(L, LConst.Table))
            {
                return(0);
            }

            bool isTable = Lua.Lua_istable(L, 2);

            if (isTable)
            {
                Lua.Lua_pushnil(L);
                while (Lua.Lua_next(L, -2) != 0)
                {
                    var request = Lua.Lua_touserdata(L, -1);
                    if (request != null)
                    {
                        var mi = request.GetType().GetMethod("Abort");
                        if (mi != null)
                        {
                            mi.Invoke(request, null);
                        }
                    }
                    Lua.Lua_pop(L, 1);
                }
            }

            //var obj = Lua.Lua_touserdata(L, 2);
            //if (obj != null)
            //{
            //    var mi = obj.GetType().GetMethod("Abort");
            //    if (mi != null)
            //    {
            //        mi.Invoke(obj, null);
            //    }
            //}

            return(0);
        }
示例#6
0
        static int open(int L)
        {
            if (!LuaCommon.CheckAndShowArgsError(L, LConst.String))
            {
                return(0);
            }
            String str  = Lua.Lua_tostring(L, 2).ToString().Trim();
            object page = LuaManager.GetLuaManager(L).DetailV_;

            if (str.StartsWith("file://"))
            {
                //string filePath = str.Substring(7, str.Length - 7);
                //if (filePath.IndexOf('.') == -1)
                //{
                //    string error = string.Format("window:open调用错误,{0}文件类型丢失!", filePath);
                //    LuaCommon.ShowError(null, error, RYTLog.Const.LuaPortError);
                //    return 0;
                //}

                //if (FunctionLib.RYTFile.IsFileExist(filePath))
                //{
                //    FunctionLib.RYTTasks.LaunchFileAsync(filePath);
                //}
                //else
                //{
                //    string error = string.Format("window:open调用错误,{0}附件不存在!", filePath);
                //    LuaCommon.ShowError(null, error, RYTLog.Const.LuaPortError);
                //}
            }
            else if (str != null && page != null)
            {
                MethodInfo methods = page.GetType().GetMethod("open");
                Object[]   pars    = new Object[] { str };
                methods.Invoke(page, pars);
            }
            return(0);
        }
示例#7
0
        static int hide(int L)
        {
            if (!LuaCommon.CheckAndShowArgsError(L, LConst.Integer, LConst.NInteger))
            {
                return(0);
            }

            int tagId          = Lua.Lua_tointeger(L, 2);
            int transitionType = -1;

            if (Lua.Lua_gettop(L) == 3)
            {
                transitionType = Lua.Lua_tointeger(L, 3);
            }
            object page = LuaManager.GetLuaManager(L).DetailV_;

            if (page != null)
            {
                MethodInfo methods = page.GetType().GetMethod("hide");
                Object[]   pars    = new Object[] { tagId, transitionType };
                methods.Invoke(page, pars);
            }
            return(0);
        }
示例#8
0
        public static bool CheckAndShowArgsError(int L, params string[] typeArray)
        {
            bool bCheckPassed = true;

            if (!LuaManager.MustVerify)
            {
                return(bCheckPassed);
            }

            #region 打印方法调用方法名

            ////从调用堆栈中获取调用当前方法的方法名.
            //StackTrace st = new StackTrace(false);
            //var packName = st.GetFrame(1).GetMethod().DeclaringType.Name;
            //if (packName.StartsWith("Lua"))
            //    packName = packName.Substring(3, packName.Length - 3).ToLower();
            //var method = st.GetFrame(1).GetMethod().Name;
            //// - 控制台调试输出当前执行的库名+方法名.
            //RYTLog.Log(string.Format("{0}:{1}", packName, method), true);

            #endregion

            int top = Lua.Lua_gettop(L);

            #region 参数个数验证

            // 验证参数个数
            var argsCount      = typeArray.Length; // 传入需验证的参数个数
            int canBeNullCount = 0;
            for (int argIndex = argsCount - 1; argIndex >= 0; argIndex--)
            {
                if (typeArray[argIndex].Contains("|"))
                {
                    canBeNullCount++;
                }
                else
                {
                    break;
                }
            }
            int minArgsCount = argsCount - canBeNullCount; //支持最小参数个数
            int maxArgsCount = argsCount;                  //支持最大参数个数
            if ((top - 1) < minArgsCount || (top - 1) > maxArgsCount)
            {
                string countStr = minArgsCount == maxArgsCount?minArgsCount.ToString() : minArgsCount.ToString() + "-" + maxArgsCount.ToString();

                //string message = string.Format("调用方法参数个数可能不正确,所传类型个数为{0},支持个数为{1},方法名为{2} : {3}", top - 1, countStr, packName, method);
                //ShowError(null, message, RYTLog.Const.LuaPortError);
            }

            #endregion

            for (int i = 0; i < typeArray.Length; i++)
            {
                bool bCrrect  = true;
                int  luaIndex = i + 2;

                if (luaIndex > top)
                {
                    break;
                }
                switch (typeArray[i])
                {
                case (LConst.String):
                    bCrrect = Lua.Lua_isstring(L, luaIndex);
                    break;

                case (LConst.NString):
                    bCrrect = Lua.Lua_isstring(L, luaIndex) || Lua.Lua_isnil(L, luaIndex);
                    break;

                case (LConst.Table):
                    bCrrect = Lua.Lua_istable(L, luaIndex);
                    break;

                case (LConst.NTable):
                    bCrrect = Lua.Lua_istable(L, luaIndex) || Lua.Lua_isnil(L, luaIndex);
                    break;

                case (LConst.Number):
                    bCrrect = Lua.Lua_isnumber(L, luaIndex);
                    break;

                case (LConst.NNumber):
                    bCrrect = Lua.Lua_isnumber(L, luaIndex) || Lua.Lua_isnil(L, luaIndex);
                    break;

                case (LConst.Integer):
                    bCrrect = Lua.Lua_isnumber(L, luaIndex);
                    break;

                case (LConst.NInteger):
                    bCrrect = Lua.Lua_isnumber(L, luaIndex) || Lua.Lua_isnil(L, luaIndex);
                    break;

                case (LConst.UserData):
                    bCrrect = Lua.Lua_isuserdata(L, luaIndex);
                    break;

                case (LConst.NUserData):
                    bCrrect = Lua.Lua_isuserdata(L, luaIndex) || Lua.Lua_isnil(L, luaIndex);
                    break;

                case (LConst.Boolean):
                    bCrrect = Lua.Lua_isbool(L, luaIndex);
                    break;

                case (LConst.NBoolean):
                    bCrrect = Lua.Lua_isbool(L, luaIndex) || Lua.Lua_isnil(L, luaIndex);
                    break;

                case (LConst.Function):
                    bCrrect = Lua.Lua_isfunction(L, luaIndex);
                    break;

                case (LConst.NFuction):
                    bCrrect = Lua.Lua_isfunction(L, luaIndex) || Lua.Lua_isnil(L, luaIndex);
                    break;

                case (LConst.LuaData):
                    bCrrect = Lua.Lua_isnumber(L, luaIndex) || Lua.Lua_isbool(L, luaIndex) || Lua.Lua_isstring(L, luaIndex) || Lua.Lua_istable(L, luaIndex);
                    break;
                }

                if (!bCrrect)
                {
                    bCheckPassed = false;
                    var errorType = LuaCommon.GetType(L, luaIndex);
                    //string message = string.Format("调用方法参数{0}不正确,所传类型为{1},应该为{2},方法名为{3} : {4}", luaIndex - 1, errorType, typeArray[i], packName, method);
                    //ShowError(null, message, RYTLog.Const.LuaPortError);
                }
            }

            return(LuaManager.MustCheckPass || bCheckPassed);
        }
示例#9
0
        static int alert(int L)
        {
            int count = Lua.Lua_gettop(L);

            if (LuaManager.ExceptionHandleAction != null)
            {
                string[] parms = new string[count - 1];
                for (int i = 0; i < parms.Length; i++)
                {
                    parms[i] = LConst.String;
                }
                if (count >= 4)
                {
                    parms[parms.Length - 1] = LConst.Function;
                }
                if (!LuaCommon.CheckAndShowArgsError(L, parms))
                {
                    return(0);
                }
            }
            String messagebody = Lua.Lua_tostring(L, 2).ToString();

            if (count == 2)
            {
                /*Page page = LuaManager.GetLuaManager(L).DetailV_ as Page;
                 * if(page !=null)
                 * {
                 *  page.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                 *  {
                 *      new MessageDialog(messagebody).ShowAsync();
                 *  });
                 * }*/
                //Thread.CurrentThread.ManagedThreadId

                var res = CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    var x = new MessageDialog(messagebody).ShowAsync();
                });

                //CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { });
                //    System.ServiceModel.Dispatcher.DispatchOperation(() =>
                //{
                //    var x = new MessageDialog(messagebody).ShowAsync();
                //});

                //Deployment.Current.Dispatcher.BeginInvoke(() =>
                //{
                //MessageBox.Show(messagebody, "提示:", MessageBoxButton.OK);
                //});
            }
            else if (count > 2)
            {
                Action <int> callbackAction = null;
                if (Lua.Lua_isfunction(L, -1))
                {
                    int callbackF = Lua.LuaL_ref(L, Lua._LUA_REGISTRYINDEX);
                    callbackAction = (result) =>
                    {
                        LuaManager.GetLuaManager(L).ExecuteCallBackFunctionWithAnyParams(callbackF, result);
                    };
                }
                List <string> btnList = new List <string>();
                for (int i = 3; i <= Lua.Lua_gettop(L); i++)
                {
                    btnList.Add(Lua.Lua_tostring(L, i));
                }
                object page = LuaManager.GetLuaManager(L).DetailV_;
                if (page != null)
                {
                    var mInfo = page.GetType().GetMethod("alert");
                    mInfo.Invoke(page, new object[] { callbackAction, messagebody, btnList });
                }
            }
            return(0);

            /*
             * if (count == 2 || count == 3)
             * {
             *  MessageBox.Show(messagebody, "提示:", MessageBoxButton.OK);
             * }
             * else if (count == 4)
             * {
             *  var btnName = Lua.Lua_tostring(L, 3).ToString();
             *  int callbackF = Lua.LuaL_ref(L, Lua._LUA_REGISTRYINDEX);
             *  if (callbackF > 0)
             *  {
             *      MessageBox.Show(messagebody, "提示:", MessageBoxButton.OK);
             *      LuaManager.Instance.ExecuteCallBackFunctionWithParam(callbackF, 0);
             *      //Lua.luaL_unref(lua, Lua._LUA_REGISTRYINDEX, callbackF);
             *  }
             *  else
             *  {
             *      MessageBox.Show(messagebody, "提示:", MessageBoxButton.OK);
             *  }
             * }
             * else if (count > 4)
             * {
             *  int callbackF = Lua.LuaL_ref(L, Lua._LUA_REGISTRYINDEX);
             *  if (callbackF > 0)
             *  {
             *      var result = MessageBox.Show(messagebody, "提示:", MessageBoxButton.OKCancel);
             *      LuaManager.Instance.ExecuteCallBackFunctionWithParam(callbackF, ConvertMessageBoxResult(result));
             *      //Lua.luaL_unref(lua, Lua._LUA_REGISTRYINDEX, callbackF);
             *  }
             *  else
             *  {
             *      MessageBox.Show(messagebody, "提示:", MessageBoxButton.OKCancel);
             *  }
             * }
             *
             * return 0;
             * */
        }
示例#10
0
        static int postAsyn(int L)
        {
            if (!LuaCommon.CheckAndShowArgsError(L, LConst.NTable, LConst.String, LConst.NString, LConst.NFuction, LConst.NTable))
            {
                Lua.Lua_pushnil(L);
                return(1);
            }

            int num = Lua.Lua_gettop(L);

            if (num >= 5)
            {
                Dictionary <String, String> headers = new Dictionary <string, string>();
                bool isTable = Lua.Lua_istable(L, 2);
                if (isTable)
                {
                    Lua.Lua_pushnil(L);
                    while (Lua.Lua_next(L, 2) != 0)
                    {
                        String value = Lua.Lua_tostring(L, -1).ToString();
                        String key   = Lua.Lua_tostring(L, -2).ToString();
                        headers[key] = value;
                        Lua.Lua_pop(L, 1);
                    }
                }

                String url  = Lua.Lua_tostring(L, 3).ToString();
                String body = string.Empty;
                if (Lua.Lua_isstring(L, 4))
                {
                    body = Lua.Lua_tostring(L, 4).ToString();
                }
                int callbackParams = Lua._LUA_REFNIL;
                if (num == 6)
                {
                    callbackParams = Lua.LuaL_ref(L, Lua._LUA_REGISTRYINDEX);// 将Lua函数需要的参数存储在REGISTRY中
                }
                int callbackF = Lua.LuaL_ref(L, Lua._LUA_REGISTRYINDEX);

                //object page = LuaManager.GetLuaManager(L).DetailV_;
                //MethodInfo methods = page.GetType().GetMethod("postAsyn");
                //Object[] pars = new Object[] { headers, url, body, callbackF, callbackParams };
                //var obj = methods.Invoke(page, pars);
                //if (obj == null)
                //{
                //    Lua.Lua_pushnil(L);
                //    return 1;
                //}
                //else
                //{
                //    Lua.Lua_pushlightuserdata(L,obj);
                //    return 1;
                //}
                url = "http://baike.baidu.com/cms/global/lemma_config.json";

                AsyncCallback getResponseCallBack = (ar) => {
                    var             re       = (HttpWebRequest)ar.AsyncState;
                    HttpWebResponse response = (HttpWebResponse)re.EndGetResponse(ar);
                    //状态码200
                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        using (var dis = response.GetResponseStream())
                        {
                            using (var reader = new StreamReader(dis))
                            {
                                var    encoding  = response.Headers["Content-Encoding"];
                                var    len       = response.ContentLength;
                                string resultStr = reader.ReadToEnd();
                            }
                        }
                    }
                };
                AsyncCallback getRequestCallBack = (ar) => {
                    var re = (WebRequest)ar.AsyncState;

                    //TODO:设置request header
                    // Just here
                    //----------------------

                    re.BeginGetResponse(getResponseCallBack, re);
                };

                HttpWebRequest request = WebRequest.CreateHttp(url);
                request.Method = "POST";
                request.BeginGetRequestStream(getRequestCallBack, request);
                //request.Method = "GET";
                //request.BeginGetResponse(getResponseCallBack, request);
            }
            return(1);
        }