示例#1
0
 static int closeKeyboard(int L)
 {
     try
     {
         object page = LuaManager.GetLuaManager(L).DetailV_;
         if (page != null)
         {
             var method = page.GetType().GetMethod("closeKeyboard");
             if (method != null)
             {
                 method.Invoke(page, null);
             }
         }
     }
     catch
     {
     }
     return(0);
 }
示例#2
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);
        }
示例#3
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);
        }
示例#4
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);
        }
示例#5
0
        public static void PushValueByType(int L, object value)
        {
            if (value == null)
            {
                Lua.Lua_pushnil(L);
            }
            else if (value is float)
            {
                Lua.Lua_pushnumber(L, (float)value);
            }
            else if (value is double)
            {
                Lua.Lua_pushnumber(L, (double)value);
            }
            else if (value is string)
            {
                Lua.Lua_pushstring(L, (string)value);
            }
            else if (value is bool)
            {
                if ((bool)value == true)
                {
                    Lua.Lua_pushboolean(L, 1);
                }
                else
                {
                    Lua.Lua_pushboolean(L, 0);
                }
            }
            else if (value is int)
            {
                Lua.Lua_pushinteger(L, (int)value);
            }
            else if (value is long)
            {
                Lua.Lua_pushnumber(L, (long)value);
            }

            else if (value is Dictionary <string, object> )
            {
                Lua.Lua_newtable(L);
                var paramDict = value as Dictionary <string, object>;
                foreach (var key in paramDict.Keys)
                {
                    Lua.Lua_pushstring(L, key);
                    PushValueByType(L, paramDict[key]);
                    Lua.Lua_rawset(L, -3);
                }
            }
            else if (value is Dictionary <string, Dictionary <string, object> > )
            {
                var paramDict = value as Dictionary <string, Dictionary <string, object> >;
                if (value != null && paramDict.Count > 0)
                {
                    Lua.Lua_newtable(L);
                    for (int i = 0; i < paramDict.Count; i++)
                    {
                        Lua.Lua_pushnumber(L, i + 1);

                        Lua.Lua_newtable(L);

                        foreach (var kv in paramDict[(i + 1).ToString()])
                        {
                            LuaManager.PushValueByType(L, kv.Key);
                            LuaManager.PushValueByType(L, kv.Value);

                            Lua.Lua_rawset(L, -3);
                        }

                        Lua.Lua_rawset(L, -3);
                    }
                }
            }
            else if (value is Dictionary <string, Dictionary <string, Dictionary <string, object> > > )
            {
                var paramDict = value as Dictionary <string, Dictionary <string, Dictionary <string, object> > >;
                if (value != null && paramDict.Count > 0)
                {
                    Lua.Lua_newtable(L);
                    for (int i = 0; i < paramDict.Count; i++)
                    {
                        foreach (var key in paramDict.Keys)
                        {
                            Lua.Lua_pushstring(L, key);
                            PushValueByType(L, paramDict[key]);
                            Lua.Lua_rawset(L, -3);
                        }
                    }
                }
            }
            else if (value is List <object> )
            {
                Lua.Lua_newtable(L);
                List <object> list = value as List <object>;
                for (int i = 1; i <= list.Count; i++)
                {
                    Lua.Lua_pushnumber(L, i);
                    PushValueByType(L, list[i - 1]);
                    Lua.Lua_rawset(L, -3);
                }
            }
            //else if (value is LuaCValue)
            //{
            //    Lua.Lua_rawgeti(L, Lua._LUA_REGISTRYINDEX, (value as LuaCValue).ValueIndex);
            //}
            else
            {
                Lua.Lua_pushlightuserdata(L, value);
            }
        }
示例#6
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;
             * */
        }