static string LuaWhere(IntPtr L) { int top = LuaAPI.lua_gettop(L); LuaAPI.luaL_where(L, 1); string str = LuaAPI.lua_tostring(L, -1); LuaAPI.lua_settop(L, top); return(str); }
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)); } }