Пример #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
        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;
             * */
        }
Пример #9
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);
        }