Util_Tips.lua 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. ---
  2. --- Generated by EmmyLua(https://github.com/EmmyLua)
  3. --- Created by PZM.
  4. --- DateTime: 2021/9/10 9:23
  5. ---
  6. require "Util/Dot2"
  7. require "Util/Misc"
  8. require "Util/TimerFunc"
  9. require "Util/MaterialUtil"
  10. require "Util/ColorUtil"
  11. require "Util/DebugFlagUtil"
  12. require "Util/ValueTypePool"
  13. require "Util/CronosUtil"
  14. ---@class Util
  15. Util = class()
  16. local this = Util
  17. function IsSubTypeOf(c,base)
  18. if c == base then
  19. return true
  20. end
  21. if c.__bases then
  22. for _, _base in ipairs(c.__bases) do
  23. if _base == base then
  24. return true
  25. end
  26. end
  27. end
  28. local b = getmetatable(c)
  29. if not b then
  30. return false
  31. end
  32. if b == base then
  33. return true
  34. end
  35. return IsSubTypeOf(b,base)
  36. end
  37. function IsSubTypeOfTryCatch(c,base,isTryCatchLog)
  38. local isSubType = false
  39. try
  40. {
  41. main = function()
  42. isSubType = IsSubTypeOf(c,base)
  43. end,
  44. catch = function(errors)
  45. isSubType = false
  46. if isTryCatchLog then
  47. logError(errors)
  48. end
  49. end
  50. }
  51. return isSubType
  52. end
  53. ---@param pool TablePool
  54. function DeepCopy(t,pool)
  55. --local InTable = {};
  56. local function Func(t)
  57. if type(t) ~= "table" then
  58. return t;
  59. end
  60. local NewTable =pool and pool:Pop() or {}
  61. --InTable[t] = NewTable
  62. for k,v in pairs(t) do
  63. NewTable[Func(k)] = Func(v)
  64. end
  65. return setmetatable(NewTable, getmetatable(t))
  66. end
  67. return Func(t)
  68. end
  69. function TableContainsKey(tbl, key)
  70. for k,v in pairs(tbl) do
  71. if k ==key then
  72. return true
  73. end
  74. end
  75. return false
  76. end