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

                LuaAPI.xlua_getglobal(L, "debug");
                LuaAPI.lua_getfield(L, -1, "traceback");
                LuaAPI.lua_pushstring(L, s);
                LuaAPI.lua_pushnumber(L, 2);
                LuaAPI.lua_pcall(L, 2, 1, 0);
                s = LuaAPI.lua_tostring(L, -1);
                LuaAPI.lua_pop(L, 1);

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