Пример #1
0
        private static int Print(IntPtr L)
        {
            try
            {
                int n  = LuaDLL.lua_gettop(L);
                var sb = new StringBuilder();

                //获得当前运行的函数的上一个调用层的信息,返回行数,把调用层的名称入栈
                int    line     = LuaDLL.jlua_where(L, 1);
                string filename = LuaDLL.lua_tostring(L, -1);

                LuaDLL.lua_settop(L, n);
                int offset = filename[0] == '@' ? 1 : 0;
                sb.Append('[').Append(filename, offset, filename.Length - offset).Append(':').Append(line).Append("]:");

                for (int i = 1; i <= n; i++)
                {
                    if (i > 1)
                    {
                        sb.Append("    ");
                    }

                    if (LuaDLL.lua_isstring(L, i) == 1)
                    {
                        sb.Append(LuaDLL.lua_tostring(L, i));
                    }
                    else if (LuaDLL.lua_isnil(L, i))
                    {
                        sb.Append("nil");
                    }
                    else if (LuaDLL.lua_isboolean(L, i))
                    {
                        sb.Append(LuaDLL.jlua_toboolean(L, i) ? "true" : "false");
                    }
                    else
                    {
                        IntPtr p = LuaDLL.lua_topointer(L, i);

                        if (p == IntPtr.Zero)
                        {
                            sb.Append("nil");
                        }
                        else
                        {
                            sb.Append(LuaDLL.luaL_typename(L, i)).Append(":0x").Append(p.ToString("X"));
                        }
                    }
                }
                Debug.Log(sb.ToString());
                return(0);
            }
            catch (Exception e)
            {
                throw e;
            }
        }