Exemplo n.º 1
0
        internal static int Print(RealStatePtr L)
        {
            try
            {
                int n = LuaAPI.lua_gettop(L);
                string s = String.Empty;

                if (0 != LuaAPI.xlua_getglobal(L, "tostring"))
                {
                    return LuaAPI.luaL_error(L, "can not get tostring in print:");
                }

                for (int i = 1; i <= n; i++)
                {
                    LuaAPI.lua_pushvalue(L, -1);  /* function to be called */
                    LuaAPI.lua_pushvalue(L, i);   /* value to print */
                    if (0 != LuaAPI.lua_pcall(L, 1, 1, 0))
                    {
                        return LuaAPI.lua_error(L);
                    }
                    s += LuaAPI.lua_tostring(L, -1);

                    if (i != n) s += "\t";

                    LuaAPI.lua_pop(L, 1);  /* pop result */
                }
                UnityEngine.Debug.Log("LUA: " + s);
                return 0;
            }
            catch (System.Exception e)
            {
                return LuaAPI.luaL_error(L, "c# exception in print:" + e);
            }
        }
Exemplo n.º 2
0
        internal static int Print(RealStatePtr L)
        {
            // For each argument we'll 'tostring' it
            int    n = LuaAPI.lua_gettop(L);
            string s = String.Empty;

            LuaAPI.lua_getglobal(L, "tostring");

            for (int i = 1; i <= n; i++)
            {
                LuaAPI.lua_pushvalue(L, -1);  /* function to be called */
                LuaAPI.lua_pushvalue(L, i);   /* value to print */
                if (0 != LuaAPI.lua_pcall(L, 1, 1, 0))
                {
                    return(LuaAPI.lua_error(L));
                }
                s += LuaAPI.lua_tostring(L, -1);

                if (i != n)
                {
                    s += "\t";
                }

                LuaAPI.lua_pop(L, 1);  /* pop result */
            }
            UnityEngine.Debug.Log("LUA: " + s);
            return(0);
        }
Exemplo n.º 3
0
        internal static int Print(RealStatePtr L)
        {
            try
            {
                int    n     = LuaAPI.lua_gettop(L);
                string s     = String.Empty;
                string color = "";
                if (0 != LuaAPI.xlua_getglobal(L, "tostring"))
                {
                    return(LuaAPI.luaL_error(L, "can not get tostring in print:"));
                }

                for (int i = 1; i <= n; i++)
                {
                    LuaAPI.lua_pushvalue(L, -1);  /* function to be called */
                    LuaAPI.lua_pushvalue(L, i);   /* value to print */
                    if (0 != LuaAPI.lua_pcall(L, 1, 1, 0))
                    {
                        return(LuaAPI.lua_error(L));
                    }
                    if (i == 1)
                    {
                        color = LuaAPI.lua_tostring(L, -1);
                    }
                    else
                    {
                        s += LuaAPI.lua_tostring(L, -1);
                        if (i != n)
                        {
                            s += "\t";
                        }
                    }
                    LuaAPI.lua_pop(L, 1);  /* pop result */
                }
                string stack = string.Empty;
#if UNITY_EDITOR
                int old_top = LuaAPI.lua_gettop(L);
                LuaAPI.xlua_getglobal(L, "_G");

                LuaAPI.lua_pushstring(L, "debug");
                LuaAPI.lua_rawget(L, -2);

                LuaAPI.lua_pushstring(L, "traceback");
                LuaAPI.lua_rawget(L, -2);

                int error = LuaAPI.lua_pcall(L, 0, 1, 0);
                if (error == 0)
                {
                    stack = LuaAPI.lua_tostring(L, -1);
                }
                LuaAPI.lua_settop(L, old_top);
#endif
                FairyStudy.LogUtil.InfoColor(color, "LUA: " + s + "\n");
                return(0);
            }
            catch (System.Exception e)
            {
                return(LuaAPI.luaL_error(L, "c# exception in print:" + e));
            }
        }
        private static int PrintBase(RealStatePtr L, UnityEngine.LogType type)
        {
            try
            {
                int    n = LuaAPI.lua_gettop(L);
                string s = String.Empty;

                if (0 != LuaAPI.xlua_getglobal(L, "tostring"))
                {
                    return(LuaAPI.luaL_error(L, "can not get tostring in print:"));
                }

                for (int i = 1; i <= n; i++)
                {
                    LuaAPI.lua_pushvalue(L, -1);  /* function to be called */
                    LuaAPI.lua_pushvalue(L, i);   /* value to print */
                    if (0 != LuaAPI.lua_pcall(L, 1, 1, 0))
                    {
                        return(LuaAPI.lua_error(L));
                    }
                    s += LuaAPI.lua_tostring(L, -1);

                    if (i != n)
                    {
                        s += "\t";
                    }

                    LuaAPI.lua_pop(L, 1);  /* pop result */
                }
                switch (type)
                {
                case UnityEngine.LogType.Error:
                    if (GLog.IsLogErrorEnabled)
                    {
                        GLog.LogError("LUA: " + s);
                    }
                    break;

                case UnityEngine.LogType.Warning:
                    if (GLog.IsLogWarningEnabled)
                    {
                        GLog.LogError("LUA: " + s);
                    }
                    break;

                default:
                    if (GLog.IsLogInfoEnabled)
                    {
                        GLog.LogInfo("LUA: " + s);
                    }
                    break;
                }
                return(0);
            }
            catch (System.Exception e)
            {
                return(LuaAPI.luaL_error(L, "c# exception in print:" + e));
            }
        }
Exemplo n.º 5
0
        public static int Compile(RealStatePtr L)
        {
            string snippet = LuaAPI.lua_tostring(L, 1);

            string code;

            try
            {
                code = ComposeCode(Parser.Parse(snippet));
            }
            catch (Exception e)
            {
                return(LuaAPI.luaL_error(L, String.Format("template compile error:{0}\r\n", e.Message)));
            }
            //UnityEngine.Debug.Log("code=" + code);
            if (LuaAPI.luaL_loadbuffer(L, code, "luatemplate") != 0)
            {
                return(LuaAPI.lua_error(L));
            }
            return(1);
        }
Exemplo n.º 6
0
        internal static int Print(RealStatePtr L)
        {
            try
            {
                int    n = LuaAPI.lua_gettop(L);
                string s = String.Empty;

                if (0 != LuaAPI.xlua_getglobal(L, "tostring"))
                {
                    return(LuaAPI.luaL_error(L, "can not get tostring in print:"));
                }

                for (int i = 1; i <= n; i++)
                {
                    LuaAPI.lua_pushvalue(L, -1);  /* function to be called */
                    LuaAPI.lua_pushvalue(L, i);   /* value to print */
                    if (0 != LuaAPI.lua_pcall(L, 1, 1, 0))
                    {
                        return(LuaAPI.lua_error(L));
                    }
                    s += LuaAPI.lua_tostring(L, -1);

                    if (i != n)
                    {
                        s += "\t";
                    }

                    LuaAPI.lua_pop(L, 1);  /* pop result */
                }
                //add by zhehua
                LuaTable debugTable = GameEntry.XLua.luaGlobal.Get <LuaTable>("debug");
                XLua.VoidReturnString tracebackFunc = debugTable.Get <XLua.VoidReturnString>("traceback");
                UnityEngine.Debug.Log(s + '\n' + tracebackFunc.Invoke());
                return(0);
            }
            catch (System.Exception e)
            {
                return(LuaAPI.luaL_error(L, "c# exception in print:" + e));
            }
        }
Exemplo n.º 7
0
        internal static int Print(RealStatePtr L)
        {
            try
            {
                int n = LuaAPI.lua_gettop(L);
                System.Text.StringBuilder s = new System.Text.StringBuilder();
                s.AppendFormat("[Lua] {0} ", LuaWhere(L));

                if (0 != LuaAPI.xlua_getglobal(L, "tostring"))
                {
                    return(LuaAPI.luaL_error(L, "can not get tostring in print:"));
                }

                for (int i = 1; i <= n; i++)
                {
                    LuaAPI.lua_pushvalue(L, -1);  /* function to be called */
                    LuaAPI.lua_pushvalue(L, i);   /* value to print */
                    if (0 != LuaAPI.lua_pcall(L, 1, 1, 0))
                    {
                        return(LuaAPI.lua_error(L));
                    }
                    s.Append(LuaAPI.lua_tostring(L, -1));

                    if (i != n)
                    {
                        s.Append("\t");
                    }

                    LuaAPI.lua_pop(L, 1);  /* pop result */
                }
                LoggerHelper.Debug(s.ToString());
                return(0);
            }
            catch (System.Exception e)
            {
                return(LuaAPI.luaL_error(L, "c# exception in print:" + e));
            }
        }
Exemplo n.º 8
0
        internal static int CollectLog(RealStatePtr L, out string s)
        {
            s = String.Empty;
            try
            {
                int n = LuaAPI.lua_gettop(L);

                if (0 != LuaAPI.xlua_getglobal(L, "tostring"))
                {
                    return(LuaAPI.luaL_error(L, "can not get tostring in print:"));
                }

                for (int i = 1; i <= n; i++)
                {
                    LuaAPI.lua_pushvalue(L, -1);  /* function to be called */
                    LuaAPI.lua_pushvalue(L, i);   /* value to print */
                    if (0 != LuaAPI.lua_pcall(L, 1, 1, 0))
                    {
                        return(LuaAPI.lua_error(L));
                    }
                    s += LuaAPI.lua_tostring(L, -1);

                    if (i != n)
                    {
                        s += "    ";
                    }

                    LuaAPI.lua_pop(L, 1);  /* pop result */
                }
                return(0);
            }
            catch (System.Exception e)
            {
                return(LuaAPI.luaL_error(L, "c# exception in print:" + e));
            }
        }
Exemplo n.º 9
0
        internal static int Print(RealStatePtr L)
        {
            try
            {
                int n = LuaAPI.lua_gettop(L);

                string s = string.Empty;
                if (0 != LuaAPI.xlua_getglobal(L, "tostring"))
                {
                    return(LuaAPI.luaL_error(L, "can not get tostring in print:"));
                }
#if UNITY_EDITOR
                LuaAPI.luaL_where(L, 1);
                string filenameAndLine = LuaAPI.lua_tostring(L, -1);
                LuaAPI.lua_settop(L, n);
                string filename = filenameAndLine.Split(':')[0];
                filename = filename.Replace(".", "/");
                int line = int.Parse(filenameAndLine.Split(':')[1]);
                s = string.Format("[{0}.lua:{1}]:", filename, line);

                for (int i = 1; i <= n; i++)
                {
                    s += LuaAPI.lua_tostring(L, i);
                    if (i != n)
                    {
                        s += "\t";
                    }

                    LuaAPI.lua_pop(L, 1);  /* pop result */
                }
#else
                for (int i = 1; i <= n; i++)
                {
                    LuaAPI.lua_pushvalue(L, -1);  /* function to be called */
                    LuaAPI.lua_pushvalue(L, i);   /* value to print */
                    if (0 != LuaAPI.lua_pcall(L, 1, 1, 0))
                    {
                        return(LuaAPI.lua_error(L));
                    }
                    s += LuaAPI.lua_tostring(L, i);
                    if (i != n)
                    {
                        s += "\t";
                    }

                    LuaAPI.lua_pop(L, 1);  /* pop result */
                }
#endif
                //                 for (int i = 1; i <= n; i++)
                //                 {
                //                     LuaAPI.lua_pushvalue(L, -1);  /* function to be called */
                //                     LuaAPI.lua_pushvalue(L, i);   /* value to print */
                //                     if (0 != LuaAPI.lua_pcall(L, 1, 1, 0))
                //                     {
                //                         return LuaAPI.lua_error(L);
                //                     }
                //                     s += LuaAPI.lua_tostring(L, i);
                //                     if (i != n) s += "\t";
                //
                //                     LuaAPI.lua_pop(L, 1);  /* pop result */
                //                 }



                Debugger.Log(s);
                return(0);
            }
            catch (System.Exception e)
            {
                Debugger.LogError(e);
                return(LuaAPI.luaL_error(L, "c# exception in print:" + e));
            }
        }