在go中使用lua示例, 基于gopher-lua!
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

80 行
1.9 KiB

4 年前
  1. function GetClassName(name)
  2. for k,v in pairs(_G) do
  3. if name==v then
  4. return k
  5. end
  6. end
  7. end
  8. function CreateClass(name,basename)
  9. if _G[name] ~= nil then
  10. unilight.error("CreateClass被意外全局初始化,这里强制重置成类:"..name)
  11. return nil
  12. end
  13. _G[name] = {}
  14. local class = _G[name]
  15. if basename then
  16. local baseclass = _G[basename]
  17. if baseclass then
  18. for k,v in pairs(baseclass) do
  19. class[k] = v
  20. end
  21. else
  22. unilight.error("CreateClass error:" .. tostring(name) .. ":" .. tostring(basename))
  23. end
  24. end
  25. class.__classname = name
  26. function class:New(initclass)
  27. local new = initclass or {}
  28. setmetatable(new, { __index = self})
  29. return new
  30. end
  31. function class:SetClassName(cname)
  32. self.__classname = cname or self.__classname
  33. end
  34. function class:GetLogPrefix()
  35. local id = nil
  36. local name = ""
  37. if self.GetId then
  38. id = self:GetId()
  39. elseif self.id then
  40. id = self.id
  41. elseif self.Id then
  42. id = self.Id
  43. elseif self.tempid then
  44. id = self.tempid
  45. elseif self.Tempid then
  46. id = self.Tempid
  47. end
  48. if self.GetName then
  49. name = self:GetName()
  50. elseif self.name then
  51. name = self.name
  52. elseif self.Name then
  53. name = self.Name
  54. end
  55. local id = id or ""
  56. local name = name or ""
  57. return self.__classname .. "[" .. id .."," ..name.. "] "
  58. end
  59. function class:Debug(...)
  60. unilight.debug(self:GetLogPrefix() .. unpack(arg))
  61. end
  62. function class:Info(...)
  63. unilight.info(self:GetLogPrefix() .. unpack(arg))
  64. end
  65. function class:Warn(...)
  66. unilight.warn(self:GetLogPrefix() .. unpack(arg))
  67. end
  68. function class:Error(...)
  69. unilight.error(self:GetLogPrefix() .. unpack(arg))
  70. end
  71. function class:Stack(...)
  72. unilight.stack(self:GetLogPrefix() .. unpack(arg))
  73. end
  74. return class
  75. end
  76. --Class = CreateClass("Class")
  77. --new = Class:New()
  78. --new:Debug("whj")