From 9f240c2ae229465bd8f19a010bb7065755964652 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BD=97=E5=AE=B6=E7=82=9C?= <2029049582@qq.com> Date: Tue, 15 Apr 2025 14:59:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E7=BB=93=E7=AE=97=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua_probject/base_project/Core/NetClient.lua | 64 +- lua_probject/base_project/Core/Queue.lua | 29 +- lua_probject/base_project/Core/bit.lua | 253 +- lua_probject/base_project/Core/string.lua | 59 +- lua_probject/base_project/FairyGUI.lua | 94 +- .../base_project/Game/ControllerManager.lua | 7 +- .../base_project/Game/Data/TableBG.lua | 12 +- .../base_project/Game/View/FamilyView.lua | 3 - .../base_project/Game/ViewManager.lua | 8 +- lua_probject/base_project/LuaDebug.lua | 919 +++---- lua_probject/base_project/LuaDebugjit.lua | 2404 +++++++++-------- lua_probject/base_project/Main.lua | 44 +- lua_probject/base_project/debug/LuaDebug.lua | 919 +++---- .../base_project/debug/LuaDebugjit.lua | 2404 +++++++++-------- .../extend/majiang/lichuan/EXClearingView.lua | 741 ++--- .../lichuan/EXClearingView_JiangXi.lua | 605 ----- .../majiang/lichuan/EXGameController.lua | 2 +- .../extend/majiang/lichuan/EXGameInfo.lua | 236 +- .../extend/majiang/lichuan/EXMainView.lua | 4 +- lua_probject/tolua_project/cjson/util.lua | 10 +- lua_probject/tolua_project/event.lua | 223 +- lua_probject/tolua_project/jit/bc.lua | 57 +- lua_probject/tolua_project/jit/dump.lua | 292 +- lua_probject/tolua_project/jit/v.lua | 21 +- lua_probject/tolua_project/jit/vmdef.lua | 701 +++-- lua_probject/tolua_project/jit/zone.lua | 9 +- lua_probject/tolua_project/lpeg/re.lua | 167 +- .../tolua_project/protobuf/decoder.lua | 41 +- .../tolua_project/protobuf/protobuf.lua | 196 +- .../tolua_project/protobuf/text_format.lua | 15 +- lua_probject/tolua_project/tolua.lua | 50 +- .../ART/base/Family/ui/Family_fui.bytes | Bin 29335 -> 29335 bytes .../Assets/ART/base/lobby/ui/Lobby_fui.bytes | Bin 114017 -> 106704 bytes .../ui/Main_Majiang_atlas0_4.png.meta | 2 +- .../main_majiang/ui/Main_Majiang_atlas0_5.png | Bin 988360 -> 494994 bytes .../ui/Main_Majiang_atlas0_5.png.meta | 2 +- .../ui/Main_Majiang_atlas_yry6yx.png | Bin 0 -> 169974 bytes .../ui/Main_Majiang_atlas_yry6yx.png.meta | 92 + .../ui/main_majiang_atlas0.png.meta | 2 +- .../ui/main_majiang_atlas0_1.png.meta | 2 +- .../ui/main_majiang_atlas0_2.png.meta | 2 +- .../ui/main_majiang_atlas0_3.png.meta | 2 +- .../ui/main_majiang_fui.bytes.meta | 2 +- .../majiang/jinxi/ui/Info_MJ_JinXi_fui.bytes | Bin 21276 -> 13135 bytes .../ui/Info_Poker_RunFastNew_fui.bytes | Bin 24018 -> 26998 bytes 45 files changed, 4950 insertions(+), 5745 deletions(-) delete mode 100644 lua_probject/extend_project/extend/majiang/lichuan/EXClearingView_JiangXi.lua create mode 100644 wb_unity_pro/Assets/ART/base/main_majiang/ui/Main_Majiang_atlas_yry6yx.png create mode 100644 wb_unity_pro/Assets/ART/base/main_majiang/ui/Main_Majiang_atlas_yry6yx.png.meta diff --git a/lua_probject/base_project/Core/NetClient.lua b/lua_probject/base_project/Core/NetClient.lua index b630cc13..d7449edb 100644 --- a/lua_probject/base_project/Core/NetClient.lua +++ b/lua_probject/base_project/Core/NetClient.lua @@ -2,7 +2,7 @@ --author:-- -- a net client -NetClient = { +NetClient= { } ConnectionProtocol = { @@ -59,21 +59,21 @@ local LuaNetClient = taurus.unity.LuaNetClient -- @param #string game -- @param #number protocol -- @return #NetClient the created NetClient -function NetClient.new(host, game, protocol) +function NetClient.new(host, game,protocol) local self = {} self.host = host or "" self.game = game or "" self.protocol = protocol or ConnectionProtocol.Tcp -- self.responseMap = {} - self.onevent = event("onevent", false) - self.onconnect = event("onconnect", false) - ---- print("222222222222222222222222222222222222222222 ",host," ",host," ",game," ",self.protocol) - - self.c__netClient = LuaNetClient(host, game, self, self.protocol) + self.onevent = event("onevent",false) + self.onconnect = event("onconnect",false) + --print("222222222222222222222222222222222222222222 ",host," ",host," ",game," ",self.protocol) + + self.c__netClient = LuaNetClient(host,game,self,self.protocol) self.c__netClient:SetCallBackListener(R.c__ondata) self.c__netClient:SetNetEventListener(R.c__onevent) self.c__netClient:SetNetConnectListener(R.c__onconnect) - setmetatable(self, { __index = R }) + setmetatable(self, {__index = R}) return self end @@ -83,17 +83,16 @@ function R.connect(self) end self.c__netClient:Connect() end - local TYPE_STRING = "string" local TYPE_FUNC = "function" local TYPE_TABLE = "table" local NULL_JSON = "{}" --- send -function R.send(self, cmd, data, callback) - if (debug_print) then - -- print("send host:" .. self.host) - end +function R.send(self,cmd, data, callback) + if(debug_print) then + print("send host:"..self.host) + end if self.c__netClient == nil then return end @@ -105,22 +104,23 @@ function R.send(self, cmd, data, callback) if data then str = json.encode(data) end - self.c__netClient:Send(cmd, str, callback) + self.c__netClient:Send(cmd,str,callback) end ----c#网络层回调函数 -function R.c__ondata(self, cmd, result, data, func) - local _response = nil +---c#网络层回调函数 +function R.c__ondata(self,cmd,result,data,func) + local _response = nil + if type(data) == TYPE_STRING and string.len(data) > 0 then _response = json.decode(data) end local new_response = {} new_response.ReturnCode = result new_response.Data = _response + - - if self.holdCallback ~= nil then + if self.holdCallback ~=nil then if self.holdCallback(new_response) then return end @@ -129,9 +129,9 @@ function R.c__ondata(self, cmd, result, data, func) func(new_response) end -function R.setSession(self, session) - printlog("setSession==>>>", session) - +function R.setSession(self,session) + printlog("setSession==>>>",session) + self.session = session if self.c__netClient == nil then return @@ -140,7 +140,7 @@ function R.setSession(self, session) end function R.getSession(self) - printlog("getSession===>>>", self.session) + printlog("getSession===>>>",self.session) return self.session end @@ -151,13 +151,15 @@ function R.getAveragePingTime(self) return self.c__netClient.AveragePingTime end + ---c#网络层回调函数 -function R.c__onevent(self, cmd, data) +function R.c__onevent(self,cmd,data) local new_response = {} local _response = data and json.decode(data) or nil new_response.Command = cmd new_response.Data = _response self.onevent(new_response) + end function R.clearActionQueue(self) @@ -168,19 +170,19 @@ function R.clearActionQueue(self) end ---c#网络层回调函数 -function R.c__onconnect(self, code) - if (debug_print) then - -- print("codeccccccccccccccccccccccccccccccccccccccc" .. code) +function R.c__onconnect(self,code) + if(debug_print) then + print("codeccccccccccccccccccccccccccccccccccccccc"..code) end self.onconnect(code) end function R.clearEvent(self) - self.onevent:Clear() - self.onconnect:Clear() + self.onevent:Clear() + self.onconnect:Clear() end -function R.setHold(self, func) +function R.setHold(self,func) self.holdcallback = func end @@ -188,5 +190,5 @@ function R.destroy(self) if self.c__netClient then self.c__netClient:Destroy() end self.onconnect:Clear() self.onevent:Clear() - self.c__netClient = nil + self.c__netClient=nil end diff --git a/lua_probject/base_project/Core/Queue.lua b/lua_probject/base_project/Core/Queue.lua index eaae3f2f..3f82dec6 100644 --- a/lua_probject/base_project/Core/Queue.lua +++ b/lua_probject/base_project/Core/Queue.lua @@ -2,8 +2,8 @@ Queue = {} function Queue.new(capacity) - local self = {} - setmetatable(self, { __index = Queue }) + local self = {} + setmetatable(self,{__index = Queue}) self.capacity = capacity self.queue = {} self.size_ = 0 @@ -20,12 +20,12 @@ function Queue:Enqueue(element) self.queue[self.rear] = element else local temp = (self.rear + 1) % self.capacity - ---- print("1111111111111111111====>>>>") - ---- print(temp) + --print("1111111111111111111====>>>>") + --print(temp) if temp == self.head then error("Error: capacity is full.") - ViewUtil.ErrorTip(10001, "Error: capacity is full.") - return + ViewUtil.ErrorTip(10001,"Error: capacity is full.") + return else self.rear = temp end @@ -33,11 +33,12 @@ function Queue:Enqueue(element) self.queue[self.rear] = element self.size_ = self.size_ + 1 end + end function Queue:Dequeue() if self:IsEmpty() then - ViewUtil.ErrorTip(10002, "Error: The Queue is empty.") + ViewUtil.ErrorTip(10002,"Error: The Queue is empty.") error("Error: The Queue is empty.") return end @@ -73,16 +74,16 @@ function Queue:dump() local first_flag = true while h ~= r do if first_flag == true then - str = "{" .. self.queue[h] + str = "{"..self.queue[h] h = (h + 1) % self.capacity first_flag = false else - str = str .. "," .. self.queue[h] + str = str..","..self.queue[h] h = (h + 1) % self.capacity end end - str = str .. "," .. self.queue[r] .. "}" - if (debug_print) then - -- print(str) - end -end + str = str..","..self.queue[r].."}" + if(debug_print) then + print(str) + end +end \ No newline at end of file diff --git a/lua_probject/base_project/Core/bit.lua b/lua_probject/base_project/Core/bit.lua index 25eb8454..2eb676d5 100644 --- a/lua_probject/base_project/Core/bit.lua +++ b/lua_probject/base_project/Core/bit.lua @@ -1,135 +1,136 @@ --[[ 位操作 ]] ---bit={data32={}} +--bit={data32={}} bit = bit or {} function bit.init32() bit.data32 = {} - for i = 1, 32 do - bit.data32[i] = 2 ^ (32 - i) - end + for i=1,32 do + bit.data32[i]=2^(32-i) + end end - bit.init32() + +function bit:d2b(arg) --bit:d2b + local tr={} + for i=1,32 do + if arg >= self.data32[i] then + tr[i]=1 + arg=arg-self.data32[i] + else + tr[i]=0 + end + end + return tr +end + +function bit:b2d(arg) --bit:b2d + local nr=0 + for i=1,32 do + if arg[i] ==1 then + nr=nr+2^(32-i) + end + end + return nr +end + +function bit:_xor(a,b) --bit:xor + local op1=self:d2b(a) + local op2=self:d2b(b) + local r={} + + for i=1,32 do + if op1[i]==op2[i] then + r[i]=0 + else + r[i]=1 + end + end + return self:b2d(r) +end + +function bit:_and(a,b) --bit:_and + local op1=self:d2b(a) + local op2=self:d2b(b) + local r={} -function bit:d2b(arg) --bit:d2b - local tr = {} - for i = 1, 32 do - if arg >= self.data32[i] then - tr[i] = 1 - arg = arg - self.data32[i] - else - tr[i] = 0 - end - end - return tr -end - -function bit:b2d(arg) --bit:b2d - local nr = 0 - for i = 1, 32 do - if arg[i] == 1 then - nr = nr + 2 ^ (32 - i) - end - end - return nr -end - -function bit:_xor(a, b) --bit:xor - local op1 = self:d2b(a) - local op2 = self:d2b(b) - local r = {} - - for i = 1, 32 do - if op1[i] == op2[i] then - r[i] = 0 - else - r[i] = 1 - end - end - return self:b2d(r) -end - -function bit:_and(a, b) --bit:_and - local op1 = self:d2b(a) - local op2 = self:d2b(b) - local r = {} - - for i = 1, 32 do - if op1[i] == 1 and op2[i] == 1 then - r[i] = 1 - else - r[i] = 0 - end - end - return self:b2d(r) -end - -function bit:_or(a, b) --bit:_or - local op1 = self:d2b(a) - local op2 = self:d2b(b) - local r = {} - - for i = 1, 32 do - if op1[i] == 1 or op2[i] == 1 then - r[i] = 1 - else - r[i] = 0 - end - end - return self:b2d(r) -end - -function bit:_not(a) --bit:_not - local op1 = self:d2b(a) - local r = {} - - for i = 1, 32 do - if op1[i] == 1 then - r[i] = 0 - else - r[i] = 1 - end - end - return self:b2d(r) -end - -function bit:_rshift(a, n) --bit:_rshift - local op1 = self:d2b(a) - local r = self:d2b(0) - - if n < 32 and n > 0 then - for i = 1, n do - for i = 31, 1, -1 do - op1[i + 1] = op1[i] - end - op1[1] = 0 - end - r = op1 - end - return self:b2d(r) -end - -function bit:_lshift(a, n) --bit:_lshift - local op1 = self:d2b(a) - local r = self:d2b(0) - - if n < 32 and n > 0 then - for i = 1, n do - for i = 1, 31 do - op1[i] = op1[i + 1] - end - op1[32] = 0 - end - r = op1 - end - return self:b2d(r) -end - -function bit:print(ta) - local sr = "" - for i = 1, 32 do - sr = sr .. ta[i] - end - -- print(sr) -end + for i=1,32 do + if op1[i]==1 and op2[i]==1 then + r[i]=1 + else + r[i]=0 + end + end + return self:b2d(r) + +end + +function bit:_or(a,b) --bit:_or + local op1=self:d2b(a) + local op2=self:d2b(b) + local r={} + + for i=1,32 do + if op1[i]==1 or op2[i]==1 then + r[i]=1 + else + r[i]=0 + end + end + return self:b2d(r) +end + +function bit:_not(a) --bit:_not + local op1=self:d2b(a) + local r={} + + for i=1,32 do + if op1[i]==1 then + r[i]=0 + else + r[i]=1 + end + end + return self:b2d(r) +end + +function bit:_rshift(a,n) --bit:_rshift + local op1=self:d2b(a) + local r=self:d2b(0) + + if n < 32 and n > 0 then + for i=1,n do + for i=31,1,-1 do + op1[i+1]=op1[i] + end + op1[1]=0 + end + r=op1 + end + return self:b2d(r) +end + +function bit:_lshift(a,n) --bit:_lshift + local op1=self:d2b(a) + local r=self:d2b(0) + + if n < 32 and n > 0 then + for i=1,n do + for i=1,31 do + op1[i]=op1[i+1] + end + op1[32]=0 + end + r=op1 + end + return self:b2d(r) +end + + +function bit:print(ta) + local sr="" + for i=1,32 do + sr=sr..ta[i] + end + print(sr) +end \ No newline at end of file diff --git a/lua_probject/base_project/Core/string.lua b/lua_probject/base_project/Core/string.lua index c7b7b3c6..8a5d1995 100644 --- a/lua_probject/base_project/Core/string.lua +++ b/lua_probject/base_project/Core/string.lua @@ -1,3 +1,5 @@ + + string._htmlspecialchars_set = {} string._htmlspecialchars_set["&"] = "&" string._htmlspecialchars_set["\""] = """ @@ -8,7 +10,7 @@ string._htmlspecialchars_set[">"] = ">" --[[-- 将特殊字符转为 HTML 转义符 ~~~ lua --- print(string.htmlspecialchars("")) +print(string.htmlspecialchars("")) -- 输出 <ABC> ~~~ @param string input 输入字符串 @@ -24,7 +26,7 @@ end --[[-- 将 HTML 转义符还原为特殊字符,功能与 string.htmlspecialchars() 正好相反 ~~~ lua --- print(string.restorehtmlspecialchars("<ABC>")) +print(string.restorehtmlspecialchars("<ABC>")) -- 输出 ~~~ @param string input 输入字符串 @@ -40,7 +42,7 @@ end --[[-- 将字符串中的 \n 换行符转换为 HTML 标记 ~~~ lua --- print(string.nl2br("Hello\nWorld")) +print(string.nl2br("Hello\nWorld")) -- 输出 -- Hello
World ~~~ @@ -54,7 +56,7 @@ end --[[-- 将字符串中的特殊字符和 \n 换行符转换为 HTML 转移符和标记 ~~~ lua --- print(string.nl2br("\nWorld")) +print(string.nl2br("\nWorld")) -- 输出 -- <Hello>
World ~~~ @@ -86,10 +88,10 @@ local res = string.split(input, "-+-") function string.split(input, delimiter) input = tostring(input) delimiter = tostring(delimiter) - if (delimiter == '') then return false end - local pos, arr = 0, {} + if (delimiter=='') then return false end + local pos,arr = 0, {} -- for each divider found - for st, sp in function() return string.find(input, delimiter, pos, true) end do + for st,sp in function() return string.find(input, delimiter, pos, true) end do table.insert(arr, string.sub(input, pos, st - 1)) pos = sp + 1 end @@ -101,7 +103,7 @@ end 去除输入字符串头部的空白字符,返回结果 ~~~ lua local input = " ABC" --- print(string.ltrim(input)) +print(string.ltrim(input)) -- 输出 ABC,输入字符串前面的两个空格被去掉了 ~~~ 空白字符包括: @@ -121,7 +123,7 @@ end 去除输入字符串尾部的空白字符,返回结果 ~~~ lua local input = "ABC " --- print(string.ltrim(input)) +print(string.ltrim(input)) -- 输出 ABC,输入字符串最后的两个空格被去掉了 ~~~ @param string input 输入字符串 @@ -147,7 +149,7 @@ end 将字符串的第一个字符转为大写,返回结果 ~~~ lua local input = "hello" --- print(string.ucfirst(input)) +print(string.ucfirst(input)) -- 输出 Hello ~~~ @param string input 输入字符串 @@ -165,7 +167,7 @@ end 将字符串转换为符合 URL 传递要求的格式,并返回转换结果 ~~~ lua local input = "hello world" --- print(string.urlencode(input)) +print(string.urlencode(input)) -- 输出 -- hello%20world ~~~ @@ -186,7 +188,7 @@ end 将 URL 中的特殊字符还原,并返回结果 ~~~ lua local input = "hello%20world" --- print(string.urldecode(input)) +print(string.urldecode(input)) -- 输出 -- hello world ~~~ @@ -195,9 +197,9 @@ local input = "hello%20world" @see string.urlencode ]] function string.urldecode(input) - input = string.gsub(input, "+", " ") - input = string.gsub(input, "%%(%x%x)", function(h) return string.char(checknumber(h, 16)) end) - input = string.gsub(input, "\r\n", "\n") + input = string.gsub (input, "+", " ") + input = string.gsub (input, "%%(%x%x)", function(h) return string.char(checknumber(h,16)) end) + input = string.gsub (input, "\r\n", "\n") return input end @@ -205,7 +207,7 @@ end 计算 UTF8 字符串的长度,每一个中文算一个字符 ~~~ lua local input = "你好World" --- print(string.utf8len(input)) +print(string.utf8len(input)) -- 输出 7 ~~~ @param string input 输入字符串 @@ -217,7 +219,7 @@ function string.utf8len(input) local len = string.len(input) local left = len local cnt = 0 - local arr = { 0, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc } + local arr = {0, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc} while left ~= 0 do local tmp = string.byte(input, -left) local i = #arr @@ -241,15 +243,15 @@ end ]] function string.utf8sub(input, index, endIndex) if input == nil or type(input) ~= "string" then return nil end - if not endIndex then + if not endIndex then endIndex = index index = 1 end - local len = string.len(input) - local left = len - local cnt = 0 + local len = string.len(input) + local left = len + local cnt = 0 local head, tail = 0, 0 - local arr = { 0, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc } + local arr = {0, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc} while left ~= 0 do if cnt + 1 == index then head = len - left + 1 @@ -276,7 +278,7 @@ end --[[-- 将数值格式化为包含千分位分隔符的字符串 ~~~ lua --- print(string.formatnumberthousands(1924235)) +print(string.formatnumberthousands(1924235)) -- 输出 1,924,235 ~~~ @param number num 数值 @@ -292,11 +294,12 @@ function string.formatnumberthousands(num) return formatted end -function string.concat(...) + +function string.concat( ... ) local str = {} - local tem = { ... } - for _, v in ipairs(tem) do + local tem = {...} + for _,v in ipairs(tem) do str[#str + 1] = v end - return table.concat(str, "") -end + return table.concat(str , "") +end \ No newline at end of file diff --git a/lua_probject/base_project/FairyGUI.lua b/lua_probject/base_project/FairyGUI.lua index 5f16e661..17cb674e 100644 --- a/lua_probject/base_project/FairyGUI.lua +++ b/lua_probject/base_project/FairyGUI.lua @@ -1,46 +1,46 @@ -EventContext = FairyGUI.EventContext -EventListener = FairyGUI.EventListener +EventContext = FairyGUI.EventContext +EventListener = FairyGUI.EventListener EventDispatcher = FairyGUI.EventDispatcher -InputEvent = FairyGUI.InputEvent -NTexture = FairyGUI.NTexture -Container = FairyGUI.Container -Image = FairyGUI.Image -Stage = FairyGUI.Stage -Controller = FairyGUI.Controller -GObject = FairyGUI.GObject -GGraph = FairyGUI.GGraph -GGroup = FairyGUI.GGroup -GImage = FairyGUI.GImage -GLoader = FairyGUI.GLoader -GMovieClip = FairyGUI.GMovieClip -TextFormat = FairyGUI.TextFormat -GTextField = FairyGUI.GTextField -GRichTextField = FairyGUI.GRichTextField -GTextInput = FairyGUI.GTextInput -GComponent = FairyGUI.GComponent -GList = FairyGUI.GList -GRoot = FairyGUI.GRoot -GLabel = FairyGUI.GLabel -GButton = FairyGUI.GButton -GComboBox = FairyGUI.GComboBox -GProgressBar = FairyGUI.GProgressBar -GSlider = FairyGUI.GSlider -PopupMenu = FairyGUI.PopupMenu -ScrollPane = FairyGUI.ScrollPane -Transition = FairyGUI.Transition -UIPackage = FairyGUI.UIPackage -Window = FairyGUI.Window -GObjectPool = FairyGUI.GObjectPool -Relations = FairyGUI.Relations -RelationType = FairyGUI.RelationType -UIPanel = FairyGUI.UIPanel -UIPainter = FairyGUI.UIPainter -TypingEffect = FairyGUI.TypingEffect -GTween = FairyGUI.GTween -GTweener = FairyGUI.GTweener -EaseType = FairyGUI.EaseType +InputEvent = FairyGUI.InputEvent +NTexture = FairyGUI.NTexture +Container = FairyGUI.Container +Image = FairyGUI.Image +Stage = FairyGUI.Stage +Controller = FairyGUI.Controller +GObject = FairyGUI.GObject +GGraph = FairyGUI.GGraph +GGroup = FairyGUI.GGroup +GImage = FairyGUI.GImage +GLoader = FairyGUI.GLoader +GMovieClip = FairyGUI.GMovieClip +TextFormat = FairyGUI.TextFormat +GTextField = FairyGUI.GTextField +GRichTextField = FairyGUI.GRichTextField +GTextInput = FairyGUI.GTextInput +GComponent = FairyGUI.GComponent +GList = FairyGUI.GList +GRoot = FairyGUI.GRoot +GLabel = FairyGUI.GLabel +GButton = FairyGUI.GButton +GComboBox = FairyGUI.GComboBox +GProgressBar = FairyGUI.GProgressBar +GSlider = FairyGUI.GSlider +PopupMenu = FairyGUI.PopupMenu +ScrollPane = FairyGUI.ScrollPane +Transition = FairyGUI.Transition +UIPackage = FairyGUI.UIPackage +Window = FairyGUI.Window +GObjectPool = FairyGUI.GObjectPool +Relations = FairyGUI.Relations +RelationType = FairyGUI.RelationType +UIPanel = FairyGUI.UIPanel +UIPainter = FairyGUI.UIPainter +TypingEffect = FairyGUI.TypingEffect +GTween = FairyGUI.GTween +GTweener = FairyGUI.GTweener +EaseType = FairyGUI.EaseType -fgui = {} +fgui = {} --[[ 用于继承FairyGUI的Window类,同时派生的Window类可以继续被继承。可以重写的方法有(与Window类里的同名方法含义完全相同) @@ -48,11 +48,11 @@ OnInit、DoHideAnimation、DoShowAnimation、OnShown、OnHide。 例子: MyWinClass = fgui.window_class() function MyWinClass:ctor() - -- print('MyWinClass-ctor') + print('MyWinClass-ctor') self.contentPane = UIPackage.CreateObject("Basics", "WindowA") end function MyWinClass:OnShown() - -- print('MyWinClass-onShown') + print('MyWinClass-onShown') end local win = MyWinClass.New() win:Show() @@ -74,7 +74,7 @@ function fgui.window_class(base) tolua.setpeer(ins, t) ins:SetLuaPeer(t) if t.ctor then - t.ctor(ins, ...) + t.ctor(ins,...) end return ins @@ -92,12 +92,12 @@ MyButton = fgui.extension_class(GButton) fgui.register_extension("ui://包名/我的按钮", MyButton) function MyButton:ctor() --当组件构建完成时此方法被调用 - -- print(self:GetChild("n1")) + print(self:GetChild("n1")) end --添加自定义的方法和字段 function MyButton:Test() - -- print('test') + print('test') end local get = tolua.initget(MyButton) @@ -133,7 +133,7 @@ function fgui.extension_class(base) o.Extend = function(ins) local t = {} setmetatable(t, o) - tolua.setpeer(ins, t) + tolua.setpeer(ins,t) return t end diff --git a/lua_probject/base_project/Game/ControllerManager.lua b/lua_probject/base_project/Game/ControllerManager.lua index 394d1bd3..2b38dbdc 100644 --- a/lua_probject/base_project/Game/ControllerManager.lua +++ b/lua_probject/base_project/Game/ControllerManager.lua @@ -30,9 +30,9 @@ function ControllerManager.Init() _controllerMap[GroupMgrController] = GroupMgrController.new() local hostIp = GetGameInfo("login_url") - if (debug_print) then - -- print("hostIp:::" .. hostIp) - end + if(debug_print) then + print("hostIp:::"..hostIp) + end ControllerManager.WebClient = NetClient.new(hostIp, "majiang", ConnectionProtocol.Web) --ControllerManager.GroupClient = nil--NetClient.new("http://192.168.0.1:8081/", "web_group", ConnectionProtocol.Web) end @@ -76,7 +76,6 @@ function ControllerManager.SetGameNetClient(client) end function ControllerManager.OnConnect(code) - -- print("=======================================ControllerManager", code) if (code ~= SocketCode.Connect) then ControllerManager.SetGameNetClient(nil) if code ~= SocketCode.DisconnectByServer then diff --git a/lua_probject/base_project/Game/Data/TableBG.lua b/lua_probject/base_project/Game/Data/TableBG.lua index 981b630e..909a5dd7 100644 --- a/lua_probject/base_project/Game/Data/TableBG.lua +++ b/lua_probject/base_project/Game/Data/TableBG.lua @@ -49,12 +49,12 @@ end function TableBG.GetTableBG(game_id) local id = -1 local json_data = Utils.LoadLocalFile(DataManager.SelfUser.account_id .. DataManager.SelfUser.invite_code) - -- -- print(DataManager.SelfUser.invite_code, DataManager.SelfUser.account_id) - if json_data ~= nil then - local config_data = json.decode(json_data) - id = GetBG(config_data, game_id) - end - return id + -- print(DataManager.SelfUser.invite_code, DataManager.SelfUser.account_id) + if json_data ~= nil then + local config_data = json.decode(json_data) + id = GetBG(config_data, game_id) + end + return id end function TableBG.LoadTableBG(id, game_id, main_view, config) diff --git a/lua_probject/base_project/Game/View/FamilyView.lua b/lua_probject/base_project/Game/View/FamilyView.lua index 79bdc7ab..34683f42 100644 --- a/lua_probject/base_project/Game/View/FamilyView.lua +++ b/lua_probject/base_project/Game/View/FamilyView.lua @@ -303,9 +303,6 @@ function M:UpdateFamilyRoom(fgCtr, id) } end local roomList = self._group.rooms - -- print("=========================playList,rooms") - pt(playList) - pt(roomList) local roomCtr = ControllerManager.GetController(RoomController) list_room.itemRenderer = function(index, obj) if index < #roomList then diff --git a/lua_probject/base_project/Game/ViewManager.lua b/lua_probject/base_project/Game/ViewManager.lua index 3ae02610..1a0e3c7d 100644 --- a/lua_probject/base_project/Game/ViewManager.lua +++ b/lua_probject/base_project/Game/ViewManager.lua @@ -53,7 +53,7 @@ local function __NetTip(txt_msg) end local function __OnGameConnectAction(state) - ---- print("state:"..state) + --print("state:"..state) NetResetConnectWindow.CloseNetReset() if state == SocketCode.Connect then ViewManager.ChangeView(ViewManager.View_Main, DataManager.CurrenRoom.game_id) @@ -150,14 +150,14 @@ function ViewManager.ChangeView(id, game_id, callback) end function ViewManager.OnApplicationPause() - -- -- print("game pause") - if (_currenView ~= nil) then + -- print("game pause") + if (_currenView ~= nil) then _currenView:OnApplicationPause() end end function ViewManager.OnApplicationActive() - -- -- print("game active") + -- print("game active") if (_currenView ~= nil) then _currenView:OnApplicationActive() end diff --git a/lua_probject/base_project/LuaDebug.lua b/lua_probject/base_project/LuaDebug.lua index f75f210a..f7481d24 100644 --- a/lua_probject/base_project/LuaDebug.lua +++ b/lua_probject/base_project/LuaDebug.lua @@ -1,7 +1,7 @@ -local debugger_reLoadFile = nil -xpcall(function() +local debugger_reLoadFile =nil +xpcall(function() debugger_reLoadFile = require("luaideReLoadFile") -end, function() +end,function() debugger_reLoadFile = function() print("未实现代码重载") end end) local debugger_stackInfo = nil @@ -21,27 +21,27 @@ local setfenv = setfenv if (not setfenv) then setfenv = function(fn, env) - local i = 1 - while true do - local name = debug.getupvalue(fn, i) - if name == "_ENV" then - debug.upvaluejoin( - fn, - i, - (function() - return env - end), - 1 - ) - break - elseif not name then - break - end - - i = i + 1 + local i = 1 + while true do + local name = debug.getupvalue(fn, i) + if name == "_ENV" then + debug.upvaluejoin( + fn, + i, + (function() + return env + end), + 1 + ) + break + elseif not name then + break end - return fn + + i = i + 1 end + return fn + end end local ZZBase64 = {} local LuaDebugTool_ = nil @@ -154,50 +154,50 @@ local function createSocket() sinkt["close-when-done"] = function(sock) - return base.setmetatable( - { - getfd = function() - return sock:getfd() - end, - dirty = function() - return sock:dirty() + return base.setmetatable( + { + getfd = function() + return sock:getfd() + end, + dirty = function() + return sock:dirty() + end + }, + { + __call = function(self, chunk, err) + if not chunk then + sock:close() + return 1 + else + return sock:send(chunk) end - }, - { - __call = function(self, chunk, err) - if not chunk then - sock:close() - return 1 - else - return sock:send(chunk) - end - end - } - ) - end + end + } + ) + end sinkt["keep-open"] = function(sock) - return base.setmetatable( - { - getfd = function() - return sock:getfd() - end, - dirty = function() - return sock:dirty() + return base.setmetatable( + { + getfd = function() + return sock:getfd() + end, + dirty = function() + return sock:dirty() + end + }, + { + __call = function(self, chunk, err) + if chunk then + return sock:send(chunk) + else + return 1 end - }, - { - __call = function(self, chunk, err) - if chunk then - return sock:send(chunk) - else - return 1 - end - end - } - ) - end + end + } + ) + end sinkt["default"] = sinkt["keep-open"] @@ -205,63 +205,63 @@ local function createSocket() sourcet["by-length"] = function(sock, length) - return base.setmetatable( - { - getfd = function() - return sock:getfd() - end, - dirty = function() - return sock:dirty() + return base.setmetatable( + { + getfd = function() + return sock:getfd() + end, + dirty = function() + return sock:dirty() + end + }, + { + __call = function() + if length <= 0 then + return nil end - }, - { - __call = function() - if length <= 0 then - return nil - end - local size = math.min(socket.BLOCKSIZE, length) - local chunk, err = sock:receive(size) - if err then - return nil, err - end - length = length - string.len(chunk) - return chunk + local size = math.min(socket.BLOCKSIZE, length) + local chunk, err = sock:receive(size) + if err then + return nil, err end - } - ) - end + length = length - string.len(chunk) + return chunk + end + } + ) + end sourcet["until-closed"] = function(sock) - local done - return base.setmetatable( - { - getfd = function() - return sock:getfd() - end, - dirty = function() - return sock:dirty() + local done + return base.setmetatable( + { + getfd = function() + return sock:getfd() + end, + dirty = function() + return sock:dirty() + end + }, + { + __call = function() + if done then + return nil end - }, - { - __call = function() - if done then - return nil - end - local chunk, err, partial = sock:receive(socket.BLOCKSIZE) - if not err then - return chunk - elseif err == "closed" then - sock:close() - done = 1 - return partial - else - return nil, err - end + local chunk, err, partial = sock:receive(socket.BLOCKSIZE) + if not err then + return chunk + elseif err == "closed" then + sock:close() + done = 1 + return partial + else + return nil, err end - } - ) - end + end + } + ) + end sourcet["default"] = sourcet["until-closed"] @@ -278,7 +278,7 @@ local function createJson() ----------------------------------------------------------------------------- -- Module declaration ----------------------------------------------------------------------------- - local json = {} -- Public namespace + local json = {} -- Public namespace local json_private = {} -- Private namespace -- Public constants @@ -392,7 +392,6 @@ local function createJson() function json.null() return json.null -- so json.null() will also return null ;-) end - ----------------------------------------------------------------------------- -- Internal, PRIVATE functions. -- Following a Python-like convention, I have prefixed all these 'PRIVATE' @@ -450,8 +449,8 @@ local function createJson() -- @return object, int The object (true, false or nil) and the position at which the next character should be -- scanned. function decode_scanConstant(s, startPos) - local consts = { ["true"] = true, ["false"] = false, ["null"] = nil } - local constNames = { "true", "false", "null" } + local consts = {["true"] = true, ["false"] = false, ["null"] = nil} + local constNames = {"true", "false", "null"} for i, k in pairs(constNames) do if string.sub(s, startPos, startPos + string.len(k) - 1) == k then @@ -600,7 +599,7 @@ local function createJson() assert( string.find(s, startChar, j + 1), "String decoding failed: missing closing " .. - startChar .. " at position " .. j .. "(for string at position " .. startPos .. ")" + startChar .. " at position " .. j .. "(for string at position " .. startPos .. ")" ) return table.concat(t, ""), j + 2 -- END SoniEx2 @@ -676,13 +675,13 @@ local function createJson() if v ~= (t.n or #t) then return false end -- False if n does not hold the number of elements - else -- Else of (k=='n') + else -- Else of (k=='n') if isEncodable(v) then return false end end -- End of (k~='n') - end -- End of k,v not an indexed pair - end -- End of loop across all pairs + end -- End of k,v not an indexed pair + end -- End of loop across all pairs return true, maxIndex end @@ -705,7 +704,7 @@ local breakInfoSocket = nil local json = createJson() local LuaDebugger = { fileMaps = {}, - Run = true, --表示正常运行只检测断点 + Run = true, --表示正常运行只检测断点 StepIn = false, StepInLevel = 0, StepNext = false, @@ -777,17 +776,17 @@ function print(...) end if (LuaDebugger.isProntToConsole == 1 or LuaDebugger.isProntToConsole == 2) then if (debug_server) then - local arg = { ... } --这里的...和{}符号中间需要有空格号,否则会出错 + local arg = {...} --这里的...和{}符号中间需要有空格号,否则会出错 local str = "" if (#arg == 0) then - arg = { "nil" } + arg = {"nil"} end for k, v in pairs(arg) do str = str .. tostring(v) .. "\t" end local sendMsg = { event = LuaDebugger.event.C2S_LuaPrint, - data = { msg = ZZBase64.encode(str), type = 1 } + data = {msg = ZZBase64.encode(str), type = 1} } local sendStr = json.encode(sendMsg) debug_server:send(sendStr .. "__debugger_k0204__") @@ -801,48 +800,46 @@ function luaIdePrintWarn(...) end if (LuaDebugger.isProntToConsole == 1 or LuaDebugger.isProntToConsole == 2) then if (debug_server) then - local arg = { ... } --这里的...和{}符号中间需要有空格号,否则会出错 + local arg = {...} --这里的...和{}符号中间需要有空格号,否则会出错 local str = "" if (#arg == 0) then - arg = { "nil" } + arg = {"nil"} end for k, v in pairs(arg) do str = str .. tostring(v) .. "\t" end local sendMsg = { event = LuaDebugger.event.C2S_LuaPrint, - data = { msg = ZZBase64.encode(str), type = 2 } + data = {msg = ZZBase64.encode(str), type = 2} } local sendStr = json.encode(sendMsg) debug_server:send(sendStr .. "__debugger_k0204__") end end end - function luaIdePrintErr(...) if (LuaDebugger.isProntToConsole == 1 or LuaDebugger.isProntToConsole == 3) then debugger_print(...) end if (LuaDebugger.isProntToConsole == 1 or LuaDebugger.isProntToConsole == 2) then if (debug_server) then - local arg = { ... } --这里的...和{}符号中间需要有空格号,否则会出错 + local arg = {...} --这里的...和{}符号中间需要有空格号,否则会出错 local str = "" if (#arg == 0) then - arg = { "nil" } + arg = {"nil"} end for k, v in pairs(arg) do str = str .. tostring(v) .. "\t" end local sendMsg = { event = LuaDebugger.event.C2S_LuaPrint, - data = { msg = ZZBase64.encode(str), type = 3 } + data = {msg = ZZBase64.encode(str), type = 3} } local sendStr = json.encode(sendMsg) debug_server:send(sendStr .. "__debugger_k0204__") end end end - --@endregion --@region 辅助方法 @@ -879,7 +876,7 @@ local function debugger_getFilePathInfo(file) file = file:gsub("/.\\", "/") file = file:gsub("\\", "/") file = file:gsub("//", "/") - + if file:find("@") == 1 then file = file:sub(2) @@ -980,7 +977,7 @@ local function debugger_dump(value, desciption, nesting) return tostring(v) end local traceback = debugger_strSplit(debug.traceback("", 2), "\n") - -- print("dump from: " .. debugger_strTrim(traceback[3])) + print("dump from: " .. debugger_strTrim(traceback[3])) local function _dump(value, desciption, indent, nest, keylen) desciption = desciption or "" local spc = "" @@ -1029,28 +1026,30 @@ local function debugger_dump(value, desciption, nesting) end _dump(value, desciption, "- ", 1) for i, line in ipairs(result) do - -- print(line) + print(line) end end --@endregion local function debugger_valueToString(v) - local vtype = type(v) + local vtype = type(v) local vstr = nil if (vtype == "userdata") then if (LuaDebugger.isFoxGloryProject) then - return "userdata", vtype + + return "userdata",vtype + else return tostring(v), vtype end elseif (vtype == "table" or vtype == "function" or vtype == "boolean") then local value = vtype - xpcall(function() + xpcall(function() value = tostring(v) - end, function() + end,function() value = vtype end) return value, vtype - elseif (vtype == "number" or vtype == "string") then + elseif (vtype == "number" or vtype == "string" ) then return v, vtype else return tostring(v), vtype @@ -1058,12 +1057,12 @@ local function debugger_valueToString(v) end local function debugger_setVarInfo(name, value) local valueStr, valueType = debugger_valueToString(value) - local nameStr, nameType = debugger_valueToString(name) - if (valueStr == nil) then + local nameStr,nameType = debugger_valueToString(name) + if(valueStr == nil) then valueStr = valueType end local valueInfo = { - name = nameStr, + name =nameStr, valueType = valueType, valueStr = ZZBase64.encode(valueStr) } @@ -1101,64 +1100,64 @@ local function debugger_getvalue(f) i = i + 1 end - return { locals = locals, ups = ups } + return {locals = locals, ups = ups} end --获取堆栈 debugger_stackInfo = function(ignoreCount, event) - local datas = {} - local stack = {} - local varInfos = {} - local funcs = {} - local index = 0 - for i = ignoreCount, 100 do - local source = getinfo(i) - local isadd = true - if (i == ignoreCount) then - local file = source.source - if (file:find(LuaDebugger.DebugLuaFie)) then - return - end - if (file == "=[C]") then - isadd = false - end + local datas = {} + local stack = {} + local varInfos = {} + local funcs = {} + local index = 0 + for i = ignoreCount, 100 do + local source = getinfo(i) + local isadd = true + if (i == ignoreCount) then + local file = source.source + if (file:find(LuaDebugger.DebugLuaFie)) then + return end - if not source then - break - end - if (isadd) then - local fullName, dir, fileName = debugger_getFilePathInfo(source.source) - local info = { - src = fullName, - scoreName = source.name, - currentline = source.currentline, - linedefined = source.linedefined, - what = source.what, - nameWhat = source.namewhat - } - index = i - local vars = debugger_getvalue(i + 1) - table.insert(stack, info) - table.insert(varInfos, vars) - table.insert(funcs, source.func) - end - if source.what == "main" then - break + if (file == "=[C]") then + isadd = false end end - - local stackInfo = { stack = stack, vars = varInfos, funcs = funcs } - local data = { - stack = stackInfo.stack, - vars = stackInfo.vars, - funcs = stackInfo.funcs, - event = event, - funcsLength = #stackInfo.funcs, - upFunc = getinfo(ignoreCount - 3, "f").func - } - LuaDebugger.currentTempFunc = data.funcs[1] - return data - end + if not source then + break + end + if (isadd) then + local fullName, dir, fileName = debugger_getFilePathInfo(source.source) + local info = { + src = fullName, + scoreName = source.name, + currentline = source.currentline, + linedefined = source.linedefined, + what = source.what, + nameWhat = source.namewhat + } + index = i + local vars = debugger_getvalue(i + 1) + table.insert(stack, info) + table.insert(varInfos, vars) + table.insert(funcs, source.func) + end + if source.what == "main" then + break + end + end + + local stackInfo = {stack = stack, vars = varInfos, funcs = funcs} + local data = { + stack = stackInfo.stack, + vars = stackInfo.vars, + funcs = stackInfo.funcs, + event = event, + funcsLength = #stackInfo.funcs, + upFunc = getinfo(ignoreCount - 3, "f").func + } + LuaDebugger.currentTempFunc = data.funcs[1] + return data +end --===========================点断信息================================================== --根据不同的游戏引擎进行定时获取断点信息 @@ -1168,37 +1167,37 @@ local function debugger_receiveDebugBreakInfo() if (jit) then if (LuaDebugger.debugLuaType ~= "jit") then local msg = "当前luajit版本为: " .. jit.version .. " 请使用LuaDebugjit 进行调试!" - -- print(msg) + print(msg) end end if (breakInfoSocket) then local msg, status = breakInfoSocket:receive() - if (LuaDebugger.isLaunch and status == "closed") then - os.exit() + if(LuaDebugger.isLaunch and status == "closed") then + os.exit() end if (msg) then local netData = json.decode(msg) if netData.event == LuaDebugger.event.S2C_SetBreakPoints then debugger_setBreak(netData.data) elseif netData.event == LuaDebugger.event.S2C_LoadLuaScript then - LuaDebugger.loadScriptBody = netData.data + LuaDebugger.loadScriptBody = netData.data debugger_exeLuaString() - debugger_sendMsg(breakInfoSocket, LuaDebugger.event.C2S_LoadLuaScript, LuaDebugger.loadScriptBody) + debugger_sendMsg(breakInfoSocket,LuaDebugger.event.C2S_LoadLuaScript,LuaDebugger.loadScriptBody) elseif netData.event == LuaDebugger.event.S2C_ReLoadFile then LuaDebugger.reLoadFileBody = netData.data LuaDebugger.isReLoadFile = false - LuaDebugger.reLoadFileBody.isReLoad = debugger_reLoadFile(LuaDebugger.reLoadFileBody) - -- print("重载结果:",LuaDebugger.reLoadFileBody.isReLoad) + LuaDebugger.reLoadFileBody.isReLoad = debugger_reLoadFile(LuaDebugger.reLoadFileBody) + print("重载结果:",LuaDebugger.reLoadFileBody.isReLoad) LuaDebugger.reLoadFileBody.script = nil debugger_sendMsg( breakInfoSocket, LuaDebugger.event.C2S_ReLoadFile, { stack = LuaDebugger.reLoadFileBody - + } - ) - end + ) + end end end end @@ -1222,76 +1221,76 @@ local function splitFilePath(path) end debugger_setBreak = function(datas) - local breakInfos = LuaDebugger.breakInfos - for i, data in ipairs(datas) do - data.fileName = string.lower(data.fileName) - data.serverPath = string.lower(data.serverPath) - local breakInfo = breakInfos[data.fileName] - if (not breakInfo) then - breakInfos[data.fileName] = {} - breakInfo = breakInfos[data.fileName] - end - if (not data.breakDatas or #data.breakDatas == 0) then - breakInfo[data.serverPath] = nil - else - local fileBreakInfo = breakInfo[data.serverPath] - if (not fileBreakInfo) then - fileBreakInfo = { - pathNames = splitFilePath(data.serverPath), - --命中次數判斷計數器 - hitCounts = {} - } - breakInfo[data.serverPath] = fileBreakInfo - end - local lineInfos = {} - for li, breakData in ipairs(data.breakDatas) do - lineInfos[breakData.line] = breakData - if (breakData.hitCondition and breakData.hitCondition ~= "") then - breakData.hitCondition = tonumber(breakData.hitCondition) - else - breakData.hitCondition = 0 - end - if (not fileBreakInfo.hitCounts[breakData.line]) then - fileBreakInfo.hitCounts[breakData.line] = 0 - end - end - fileBreakInfo.lines = lineInfos - --這裡添加命中次數判斷 - for line, count in pairs(fileBreakInfo.hitCounts) do - if (not lineInfos[line]) then - fileBreakInfo.hitCounts[line] = nil - end - end - end - local count = 0 - for i, linesInfo in pairs(breakInfo) do - count = count + 1 - end - if (count == 0) then - breakInfos[data.fileName] = nil - end + local breakInfos = LuaDebugger.breakInfos + for i, data in ipairs(datas) do + data.fileName = string.lower(data.fileName) + data.serverPath = string.lower(data.serverPath) + local breakInfo = breakInfos[data.fileName] + if (not breakInfo) then + breakInfos[data.fileName] = {} + breakInfo = breakInfos[data.fileName] end - --debugger_dump(breakInfos, "breakInfos", 6) - --检查是否需要断点 - local isHook = false - for k, v in pairs(breakInfos) do - isHook = true - break - end - - --这样做的原因是为了最大限度的使手机调试更加流畅 注意这里会连续的进行n次 - if (isHook) then - if (not LuaDebugger.isHook) then - debug.sethook(debug_hook, "lrc") - end - LuaDebugger.isHook = true + if (not data.breakDatas or #data.breakDatas == 0) then + breakInfo[data.serverPath] = nil else - if (LuaDebugger.isHook) then - debug.sethook() + local fileBreakInfo = breakInfo[data.serverPath] + if (not fileBreakInfo) then + fileBreakInfo = { + pathNames = splitFilePath(data.serverPath), + --命中次數判斷計數器 + hitCounts = {} + } + breakInfo[data.serverPath] = fileBreakInfo end - LuaDebugger.isHook = false + local lineInfos = {} + for li, breakData in ipairs(data.breakDatas) do + lineInfos[breakData.line] = breakData + if (breakData.hitCondition and breakData.hitCondition ~= "") then + breakData.hitCondition = tonumber(breakData.hitCondition) + else + breakData.hitCondition = 0 + end + if (not fileBreakInfo.hitCounts[breakData.line]) then + fileBreakInfo.hitCounts[breakData.line] = 0 + end + end + fileBreakInfo.lines = lineInfos + --這裡添加命中次數判斷 + for line, count in pairs(fileBreakInfo.hitCounts) do + if (not lineInfos[line]) then + fileBreakInfo.hitCounts[line] = nil + end + end + end + local count = 0 + for i, linesInfo in pairs(breakInfo) do + count = count + 1 + end + if (count == 0) then + breakInfos[data.fileName] = nil end end + --debugger_dump(breakInfos, "breakInfos", 6) + --检查是否需要断点 + local isHook = false + for k, v in pairs(breakInfos) do + isHook = true + break + end + + --这样做的原因是为了最大限度的使手机调试更加流畅 注意这里会连续的进行n次 + if (isHook) then + if (not LuaDebugger.isHook) then + debug.sethook(debug_hook, "lrc") + end + LuaDebugger.isHook = true + else + if (LuaDebugger.isHook) then + debug.sethook() + end + LuaDebugger.isHook = false + end +end local function debugger_checkFileIsBreak(fileName) return LuaDebugger.breakInfos[fileName] end @@ -1323,30 +1322,31 @@ function debugger_conditionStr(condition, vars, callBack) currentTabble[k] = v end end - setmetatable(currentTabble, { __index = _G }) + setmetatable(currentTabble, {__index = _G}) local fun = loadstring("return " .. condition) setfenv(fun, currentTabble) return fun() end local status, - msg = + msg = xpcall( - loadScript, - function(error) - -- print(error) - end - ) + loadScript, + function(error) + print(error) + end + ) if (status and msg) then callBack() end end - --执行lua字符串 debugger_exeLuaString = function() + local function loadScript() + local script = LuaDebugger.loadScriptBody.script if (LuaDebugger.loadScriptBody.isBreak) then - local currentTabble = { _G = _G } + local currentTabble = {_G = _G} local frameId = LuaDebugger.loadScriptBody.frameId frameId = frameId local func = LuaDebugger.currentDebuggerData.funcs[frameId] @@ -1359,8 +1359,8 @@ debugger_exeLuaString = function() for k, v in pairs(locals) do currentTabble[k] = v end - setmetatable(currentTabble, { __index = _G }) - + setmetatable(currentTabble, {__index = _G}) + local fun = loadstring(script) setfenv(fun, currentTabble) fun() @@ -1370,51 +1370,54 @@ debugger_exeLuaString = function() end end local status, - msg = + msg = xpcall( - loadScript, - function(error) - -- debugger_sendMsg(debug_server, LuaDebugger.event.C2S_LoadLuaScript, LuaDebugger.loadScriptBody) - end - ) - LuaDebugger.loadScriptBody.script = nil + loadScript, + function(error) + + -- debugger_sendMsg(debug_server, LuaDebugger.event.C2S_LoadLuaScript, LuaDebugger.loadScriptBody) + end + ) + LuaDebugger.loadScriptBody.script = nil if (LuaDebugger.loadScriptBody.isBreak) then - LuaDebugger.serVarLevel = LuaDebugger.serVarLevel + 1 - LuaDebugger.currentDebuggerData = debugger_stackInfo(LuaDebugger.serVarLevel, LuaDebugger.event - .C2S_HITBreakPoint) - LuaDebugger.loadScriptBody.stack = LuaDebugger.currentDebuggerData.stack - end + LuaDebugger.serVarLevel = LuaDebugger.serVarLevel+1 + LuaDebugger.currentDebuggerData = debugger_stackInfo(LuaDebugger.serVarLevel, LuaDebugger.event.C2S_HITBreakPoint) + LuaDebugger.loadScriptBody.stack = LuaDebugger.currentDebuggerData.stack + end LuaDebugger.loadScriptBody.complete = true + end --@region 调试中修改变量值 --根据key 值在 value 查找 -local function debugger_getTablekey(key, keyType, value) - if (keyType == -1) then +local function debugger_getTablekey(key,keyType,value) + if(keyType == -1) then return key - elseif (keyType == 1) then + elseif(keyType == 1) then return tonumber(key) - elseif (keyType == 2) then + elseif(keyType == 2) then local valueKey = nil - for k, v in pairs(value) do + for k,v in pairs(value) do local nameType = type(k) - if (nameType == "userdata" or nameType == "table") then + if(nameType == "userdata" or nameType == "table") then if (not LuaDebugger.isFoxGloryProject) then valueKey = tostring(k) - if (key == valueKey) then + if(key == valueKey) then return k end break end end end + end end local function debugger_setVarValue(server, data) + local newValue = nil - local level = LuaDebugger.serVarLevel + LuaDebugger.setVarBody.frameId + local level = LuaDebugger.serVarLevel+LuaDebugger.setVarBody.frameId local firstKeyName = data.keys[1] --@region vars check local localValueChangeIndex = -1 @@ -1429,7 +1432,7 @@ local function debugger_setVarValue(server, data) if not name then break end - if (firstKeyName == name) then + if(firstKeyName == name) then localValueChangeIndex = i oldValue = value end @@ -1443,11 +1446,11 @@ local function debugger_setVarValue(server, data) local ups = {} while func do -- check for func as it may be nil for tail calls local name, value = debug.getupvalue(func, i) - + if not name then break end - if (localValueChangeIndex == -1 and firstKeyName == name) then + if(localValueChangeIndex == -1 and firstKeyName == name) then upValueFun = func oldValue = value upValueChangeIndex = i @@ -1459,9 +1462,9 @@ local function debugger_setVarValue(server, data) end i = i + 1 end - --@endregion - local vars = { locals = locals, ups = ups } - +--@endregion + local vars = {locals = locals, ups = ups} + local function loadScript() local currentTabble = {} local locals = vars.locals @@ -1477,56 +1480,58 @@ local function debugger_setVarValue(server, data) currentTabble[k] = v end end - setmetatable(currentTabble, { __index = _G }) + setmetatable(currentTabble, {__index = _G}) local fun = loadstring("return " .. data.value) setfenv(fun, currentTabble) newValue = fun() end local status, - msg = + msg = xpcall( - loadScript, - function(error) - -- print(error, "============================") - end - ) - + loadScript, + function(error) + print(error, "============================") + end + ) + local i = 1 - + -- local 查找并替换 local keyLength = #data.keys - - if (keyLength == 1) then - if (localValueChangeIndex ~= -1) then + + if(keyLength == 1) then + if(localValueChangeIndex ~= -1) then + debug.setlocal(level, localValueChangeIndex, newValue) - elseif (upValueFun ~= nil) then - debug.setupvalue(upValueFun, upValueChangeIndex, newValue) + elseif(upValueFun ~= nil) then + debug.setupvalue( upValueFun, upValueChangeIndex, newValue ) else --全局变量查找 - if (_G[firstKeyName]) then + if(_G[firstKeyName]) then _G[firstKeyName] = newValue end end else - if (not oldValue) then - if (_G[firstKeyName]) then + if(not oldValue) then + if(_G[firstKeyName]) then oldValue = _G[firstKeyName] end end local tempValue = oldValue - for i = 2, keyLength - 1 do - if (tempValue) then - oldValue = oldValue[debugger_getTablekey(data.keys[i], data.numberTypes[i], oldValue)] + for i=2,keyLength-1 do + if(tempValue) then + oldValue = oldValue[debugger_getTablekey(data.keys[i],data.numberTypes[i],oldValue)] end end - if (tempValue) then - oldValue[debugger_getTablekey(data.keys[keyLength], data.numberTypes[keyLength], oldValue)] = newValue + if(tempValue) then + oldValue[debugger_getTablekey(data.keys[keyLength],data.numberTypes[keyLength],oldValue)] = newValue end end - local varInfo = debugger_setVarInfo(data.varName, newValue) + local varInfo = debugger_setVarInfo(data.varName, newValue) data.varInfo = varInfo - LuaDebugger.serVarLevel = LuaDebugger.serVarLevel + 1 + LuaDebugger.serVarLevel = LuaDebugger.serVarLevel+1 LuaDebugger.currentDebuggerData = debugger_stackInfo(LuaDebugger.serVarLevel, LuaDebugger.event.C2S_HITBreakPoint) + end --@endregion @@ -1536,44 +1541,44 @@ end --调试修改变量值统一的 _resume checkSetVar = function() - if (LuaDebugger.isSetVar) then - LuaDebugger.isSetVar = false - debugger_setVarValue(debug_server, LuaDebugger.setVarBody) - LuaDebugger.serVarLevel = LuaDebugger.serVarLevel + 1 - _resume(coro_debugger, LuaDebugger.setVarBody) - xpcall( - checkSetVar, - function(error) - -- print("设置变量", error) - end - ) - elseif (LuaDebugger.isLoadLuaScript) then - LuaDebugger.isLoadLuaScript = false - debugger_exeLuaString() - LuaDebugger.serVarLevel = LuaDebugger.serVarLevel + 1 - _resume(coro_debugger, LuaDebugger.reLoadFileBody) - xpcall( - checkSetVar, - function(error) - -- print("执行代码", error) - end - ) - elseif (LuaDebugger.isReLoadFile) then - LuaDebugger.isReLoadFile = false - LuaDebugger.reLoadFileBody.isReLoad = debugger_reLoadFile(LuaDebugger.reLoadFileBody) - -- print("重载结果:",LuaDebugger.reLoadFileBody.isReLoad) - LuaDebugger.reLoadFileBody.script = nil - LuaDebugger.serVarLevel = LuaDebugger.serVarLevel + 1 - _resume(coro_debugger, LuaDebugger.reLoadFileBody) - xpcall( - checkSetVar, - function(error) - -- print("重新加载文件", error) - end - ) - end + if (LuaDebugger.isSetVar) then + LuaDebugger.isSetVar = false + debugger_setVarValue(debug_server,LuaDebugger.setVarBody) + LuaDebugger.serVarLevel = LuaDebugger.serVarLevel+1 + _resume(coro_debugger, LuaDebugger.setVarBody) + xpcall( + checkSetVar, + function(error) + print("设置变量", error) + end + ) + elseif(LuaDebugger.isLoadLuaScript) then + LuaDebugger.isLoadLuaScript = false + debugger_exeLuaString() + LuaDebugger.serVarLevel = LuaDebugger.serVarLevel+1 + _resume(coro_debugger, LuaDebugger.reLoadFileBody) + xpcall( + checkSetVar, + function(error) + print("执行代码", error) + end + ) + elseif(LuaDebugger.isReLoadFile) then + LuaDebugger.isReLoadFile = false + LuaDebugger.reLoadFileBody.isReLoad = debugger_reLoadFile(LuaDebugger.reLoadFileBody) + print("重载结果:",LuaDebugger.reLoadFileBody.isReLoad) + LuaDebugger.reLoadFileBody.script = nil + LuaDebugger.serVarLevel = LuaDebugger.serVarLevel+1 + _resume(coro_debugger, LuaDebugger.reLoadFileBody) + xpcall( + checkSetVar, + function(error) + print("重新加载文件", error) + end + ) end - +end + local function getSource(source) @@ -1593,7 +1598,7 @@ local function debugger_GeVarInfoBytUserData(server, var) local fileds = LuaDebugTool.getUserDataInfo(var) local varInfos = {} - + --c# vars for i = 1, fileds.Count do @@ -1614,18 +1619,18 @@ end local function debugger_getValueByScript(value, script) local val = nil local status, - msg = + msg = xpcall( - function() - local fun = loadstring("return " .. script) - setfenv(fun, value) - val = fun() - end, - function(error) - -- print(error, "====>") - val = nil - end - ) + function() + local fun = loadstring("return " .. script) + setfenv(fun, value) + val = fun() + end, + function(error) + print(error, "====>") + val = nil + end + ) return val end @@ -1730,7 +1735,7 @@ end local function debugger_searchVarByKeys(value, keys, searckKeys) local index, val = debugger_getVarByKeys(value, searckKeys, 1) - if (not LuaDebugTool or not LuaDebugTool.getCSharpValue or type(LuaDebugTool.getCSharpValue) ~= "function") then + if (not LuaDebugTool or not LuaDebugTool.getCSharpValue or type(LuaDebugTool.getCSharpValue) ~= "function") then return index, val end if (val) then @@ -1858,9 +1863,9 @@ local function debugger_sendTableValues(value, server, variablesReference, debug if (valueType == "userdata") then m = getmetatable(value) - + vinfos = debugger_sendTableField(value, vinfos, server, variablesReference, debugSpeedIndex, valueType) - + if (LuaDebugTool) then local varInfos = debugger_GeVarInfoBytUserData(server, value, variablesReference, debugSpeedIndex) @@ -1889,6 +1894,7 @@ local function debugger_sendTableValues(value, server, variablesReference, debug vinfos = {} end end + end else m = getmetatable(value) @@ -1938,6 +1944,7 @@ local function debugger_getBreakVar(body, server) if (value) then local valueType = type(value) if (valueType == "table" or valueType == "userdata") then + debugger_sendTableValues(value, server, variablesReference, debugSpeedIndex) else if (valueType == "function") then @@ -1972,9 +1979,9 @@ local function debugger_getBreakVar(body, server) xpcall( exe, function(error) - -- -- print("获取变量错误 错误消息-----------------") - -- -- print(error) - -- -- print(debug.traceback("", 2)) + -- print("获取变量错误 错误消息-----------------") + -- print(error) + -- print(debug.traceback("", 2)) debugger_sendMsg( server, LuaDebugger.event.C2S_ReqVar, @@ -2011,24 +2018,25 @@ local function debugger_loop(server) while true do local line, status = server:receive() if (status == "closed") then - if (LuaDebugger.isLaunch) then - os.exit() - else - debug.sethook() - coroutine.yield() - end + if(LuaDebugger.isLaunch) then + os.exit() + else + debug.sethook() + coroutine.yield() + end end if (line) then local netData = json.decode(line) local event = netData.event local body = netData.data if (event == LuaDebugger.event.S2C_DebugClose) then - if (LuaDebugger.isLaunch) then - os.exit() - else - debug.sethook() - coroutine.yield() - end + if(LuaDebugger.isLaunch) then + os.exit() + else + debug.sethook() + coroutine.yield() + end + elseif event == LuaDebugger.event.S2C_SetBreakPoints then --设置断点信息 local function setB() @@ -2037,7 +2045,7 @@ local function debugger_loop(server) xpcall( setB, function(error) - -- print(error) + print(error) end ) elseif event == LuaDebugger.event.S2C_RUN then --开始运行 @@ -2129,8 +2137,8 @@ local function debugger_loop(server) stack = data, eventType = data.eventType } - ) - elseif event == LuaDebugger.event.S2C_ReLoadFile then + ) + elseif event == LuaDebugger.event.S2C_ReLoadFile then LuaDebugger.isReLoadFile = true LuaDebugger.reLoadFileBody = body local data = coroutine.yield() @@ -2148,26 +2156,29 @@ local function debugger_loop(server) end coro_debugger = coroutine.create(debugger_loop) debug_hook = function(event, line) - if (not LuaDebugger.isHook) then + + if(not LuaDebugger.isHook) then return end - - if (LuaDebugger.Run) then - if (event == "line") then + + if(LuaDebugger.Run) then + if(event == "line") then local isCheck = false for k, breakInfo in pairs(LuaDebugger.breakInfos) do + for bk, linesInfo in pairs(breakInfo) do - if (linesInfo.lines and linesInfo.lines[line]) then + + if(linesInfo.lines and linesInfo.lines[line]) then isCheck = true break end end - if (isCheck) then - break - end + if(isCheck) then + break + end end - if (not isCheck) then + if(not isCheck) then return end else @@ -2189,8 +2200,8 @@ debug_hook = function(event, line) else if (LuaDebugger.currentDebuggerData.funcs[2] == tempFun) then local data = debugger_stackInfo(3, LuaDebugger.event.C2S_StepInResponse) - --挂起等待调试器作出反应 - + --挂起等待调试器作出反应 + _resume(coro_debugger, data) checkSetVar() end @@ -2198,7 +2209,7 @@ debug_hook = function(event, line) return end -- debugger_dump(LuaDebugger,"LuaDebugger") - -- -- print(LuaDebugger.StepNextLevel,"LuaDebugger.StepNextLevel") + -- print(LuaDebugger.StepNextLevel,"LuaDebugger.StepNextLevel") local file = nil if (event == "call") then -- end @@ -2206,7 +2217,7 @@ debug_hook = function(event, line) if (not LuaDebugger.Run) then LuaDebugger.StepNextLevel = LuaDebugger.StepNextLevel + 1 end - -- -- print("stepIn",LuaDebugger.StepNextLevel) + -- print("stepIn",LuaDebugger.StepNextLevel) local stepInfo = getinfo(2, "S") local source = stepInfo.source @@ -2243,11 +2254,12 @@ debug_hook = function(event, line) LuaDebugger.currentFileName = file end file = LuaDebugger.currentFileName - + --判断断点 local breakInfo = LuaDebugger.breakInfos[file] local breakData = nil if (breakInfo) then + local ischeck = false for k, lineInfo in pairs(breakInfo) do local lines = lineInfo.lines @@ -2256,7 +2268,7 @@ debug_hook = function(event, line) break end end - + if (ischeck) then --并且在断点中 local info = stepInfo @@ -2264,7 +2276,7 @@ debug_hook = function(event, line) info = getinfo(2) end local hitPathNames = splitFilePath(LuaDebugger.currentLineFile) - + local hitCounts = {} local debugHitCounts = nil for k, lineInfo in pairs(breakInfo) do @@ -2276,7 +2288,7 @@ debug_hook = function(event, line) --判断路径 hitCounts[k] = 0 local hitPathNamesCount = #hitPathNames - + local pathNamesCount = #pathNames local checkCount = 0; while (true) do @@ -2287,13 +2299,13 @@ debug_hook = function(event, line) end pathNamesCount = pathNamesCount - 1 hitPathNamesCount = hitPathNamesCount - 1 - checkCount = checkCount + 1 - + checkCount = checkCount+1 + if (pathNamesCount <= 0 or hitPathNamesCount <= 0) then break end end - if (checkCount > 0) then + if(checkCount>0) then break; end else @@ -2342,8 +2354,8 @@ debug_hook = function(event, line) local data = debugger_stackInfo(3, LuaDebugger.event.C2S_NextResponse) -- 挂起等待调试器作出反应 if (data) then - LuaDebugger.currentTempFunc = data.funcs[1] - + LuaDebugger.currentTempFunc = data.funcs[1] + _resume(coro_debugger, data) checkSetVar() return @@ -2372,8 +2384,8 @@ end local function debugger_xpcall() --调用 coro_debugger 并传入 参数 local data = debugger_stackInfo(4, LuaDebugger.event.C2S_HITBreakPoint) - if (data.stack and data.stack[1]) then - data.stack[1].isXpCall = true + if(data.stack and data.stack[1]) then + data.stack[1].isXpCall = true end --挂起等待调试器作出反应 _resume(coro_debugger, data) @@ -2384,8 +2396,8 @@ local function start() local fullName, dirName, fileName = debugger_getFilePathInfo(getinfo(1).source) LuaDebugger.DebugLuaFie = fileName local socket = createSocket() - -- print(controller_host) - -- print(controller_port) + print(controller_host) + print(controller_port) local server = socket.connect(controller_host, controller_port) debug_server = server @@ -2415,33 +2427,33 @@ local function start() debug.sethook(debug_hook, "lrc") end, function(error) - -- print("error:", error) + print("error:", error) end ) if (jit) then if (LuaDebugger.debugLuaType ~= "jit") then - -- print("error======================================================") + print("error======================================================") local msg = "当前luajit版本为: " .. jit.version .. " 请使用LuaDebugjit 进行调试!" - -- print(msg) + print(msg) end end - _resume(coro_debugger, server) + _resume(coro_debugger, server) end end end function StartDebug(host, port) if (not host) then - -- print("error host nil") + print("error host nil") end if (not port) then - -- print("error prot nil") + print("error prot nil") end if (type(host) ~= "string") then - -- print("error host not string") + print("error host not string") end if (type(port) ~= "number") then - -- print("error host not number") + print("error host not number") end controller_host = host controller_port = port @@ -2449,7 +2461,7 @@ function StartDebug(host, port) start, function(error) -- body - -- print(error) + print(error) end ) return debugger_receiveDebugBreakInfo, debugger_xpcall @@ -2466,25 +2478,25 @@ ZZBase64.__code = { 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/', }; ZZBase64.__decode = {} -for k, v in pairs(ZZBase64.__code) do - ZZBase64.__decode[string.byte(v, 1)] = k - 1 +for k,v in pairs(ZZBase64.__code) do + ZZBase64.__decode[string.byte(v,1)] = k - 1 end function ZZBase64.encode(text) - local len = string.len(text) - local left = len % 3 - len = len - left - local res = {} - local index = 1 + local len = string.len(text) + local left = len % 3 + len = len - left + local res = {} + local index = 1 for i = 1, len, 3 do - local a = string.byte(text, i) + local a = string.byte(text, i ) local b = string.byte(text, i + 1) local c = string.byte(text, i + 2) -- num = a<<16 + b<<8 + c local num = a * 65536 + b * 256 + c for j = 1, 4 do --tmp = num >> ((4 -j) * 6) - local tmp = math.floor(num / (2 ^ ((4 - j) * 6))) + local tmp = math.floor(num / (2 ^ ((4-j) * 6))) --curPos = tmp&0x3f local curPos = tmp % 64 + 1 res[index] = ZZBase64.__code[curPos] @@ -2504,7 +2516,7 @@ function ZZBase64.__left2(res, index, text, len) local num1 = string.byte(text, len + 1) num1 = num1 * 1024 --lshift 10 local num2 = string.byte(text, len + 2) - num2 = num2 * 4 --lshift 2 + num2 = num2 * 4 --lshift 2 local num = num1 + num2 local tmp1 = math.floor(num / 4096) --rShift 12 @@ -2521,13 +2533,13 @@ function ZZBase64.__left2(res, index, text, len) res[index + 3] = "=" end -function ZZBase64.__left1(res, index, text, len) +function ZZBase64.__left1(res, index,text, len) local num = string.byte(text, len + 1) num = num * 16 local tmp = math.floor(num / 64) local curPos = tmp % 64 + 1 - res[index] = ZZBase64.__code[curPos] + res[index ] = ZZBase64.__code[curPos] curPos = num % 64 + 1 res[index + 1] = ZZBase64.__code[curPos] @@ -2550,11 +2562,11 @@ function ZZBase64.decode(text) local res = {} local index = 1 local decode = ZZBase64.__decode - for i = 1, len, 4 do - local a = decode[string.byte(text, i)] - local b = decode[string.byte(text, i + 1)] - local c = decode[string.byte(text, i + 2)] - local d = decode[string.byte(text, i + 3)] + for i =1, len, 4 do + local a = decode[string.byte(text,i )] + local b = decode[string.byte(text,i + 1)] + local c = decode[string.byte(text,i + 2)] + local d = decode[string.byte(text,i + 3)] --num = a<<18 + b<<12 + c<<6 + d local num = a * 262144 + b * 4096 + c * 64 + d @@ -2563,7 +2575,7 @@ function ZZBase64.decode(text) num = math.floor(num / 256) local f = string.char(num % 256) num = math.floor(num / 256) - res[index] = string.char(num % 256) + res[index ] = string.char(num % 256) res[index + 1] = f res[index + 2] = e index = index + 3 @@ -2599,4 +2611,7 @@ function ZZBase64.__decodeLeft2(res, index, text, len) res[index] = string.char(num) end + + + return StartDebug diff --git a/lua_probject/base_project/LuaDebugjit.lua b/lua_probject/base_project/LuaDebugjit.lua index c5a8613b..6ba9f888 100644 --- a/lua_probject/base_project/LuaDebugjit.lua +++ b/lua_probject/base_project/LuaDebugjit.lua @@ -1,7 +1,7 @@ -local debugger_reLoadFile = nil -xpcall(function() +local debugger_reLoadFile =nil +xpcall(function() debugger_reLoadFile = require("luaideReLoadFile") -end, function() +end,function() debugger_reLoadFile = function() print("未实现代码重载") end end) local sethook = debug.sethook @@ -13,165 +13,165 @@ local checkSetVar = nil local loadstring_ = nil local debugger_sendMsg = nil if (loadstring) then - loadstring_ = loadstring +loadstring_ = loadstring else - loadstring_ = load +loadstring_ = load end local ZZBase64 = {} local LuaDebugTool_ = nil if (LuaDebugTool) then - LuaDebugTool_ = LuaDebugTool + LuaDebugTool_ = LuaDebugTool elseif (CS and CS.LuaDebugTool) then - LuaDebugTool_ = CS.LuaDebugTool + LuaDebugTool_ = CS.LuaDebugTool end local LuaDebugTool = LuaDebugTool_ local loadstring = loadstring_ local getinfo = debug.getinfo local function createSocket() - local base = _G - local string = require("string") - local math = require("math") - local socket = require("socket.core") + local base = _G + local string = require("string") + local math = require("math") + local socket = require("socket.core") + + local _M = socket + + ----------------------------------------------------------------------------- + -- Exported auxiliar functions + ----------------------------------------------------------------------------- + function _M.connect4(address, port, laddress, lport) + return socket.connect(address, port, laddress, lport, "inet") + end + + function _M.connect6(address, port, laddress, lport) + return socket.connect(address, port, laddress, lport, "inet6") + end - local _M = socket - - ----------------------------------------------------------------------------- - -- Exported auxiliar functions - ----------------------------------------------------------------------------- - function _M.connect4(address, port, laddress, lport) - return socket.connect(address, port, laddress, lport, "inet") - end - - function _M.connect6(address, port, laddress, lport) - return socket.connect(address, port, laddress, lport, "inet6") - end - - if (not _M.connect) then - function _M.connect(address, port, laddress, lport) - local sock, err = socket.tcp() - if not sock then + if (not _M.connect) then + function _M.connect(address, port, laddress, lport) + local sock, err = socket.tcp() + if not sock then return nil, err - end - if laddress then - local res, err = sock:bind(laddress, lport, -1) - if not res then + end + if laddress then + local res, err = sock:bind(laddress, lport, -1) + if not res then return nil, err end - end - local res, err = sock:connect(address, port) - if not res then + end + local res, err = sock:connect(address, port) + if not res then return nil, err end - return sock - end - end - function _M.bind(host, port, backlog) - if host == "*" then + return sock + end + end + function _M.bind(host, port, backlog) + if host == "*" then host = "0.0.0.0" end local addrinfo, err = socket.dns.getaddrinfo(host) if not addrinfo then return nil, err end - local sock, res - err = "no info on address" - for i, alt in base.ipairs(addrinfo) do - if alt.family == "inet" then - sock, err = socket.tcp4() - else - sock, err = socket.tcp6() - end - if not sock then + local sock, res + err = "no info on address" + for i, alt in base.ipairs(addrinfo) do + if alt.family == "inet" then + sock, err = socket.tcp4() + else + sock, err = socket.tcp6() + end + if not sock then return nil, err end - sock:setoption("reuseaddr", true) - res, err = sock:bind(alt.addr, port) - if not res then - sock:close() - else - res, err = sock:listen(backlog) - if not res then - sock:close() - else - return sock - end - end - end - return nil, err - end - - _M.try = _M.newtry() - - function _M.choose(table) - return function(name, opt1, opt2) - if base.type(name) ~= "string" then - name, opt1, opt2 = "default", name, opt1 - end - local f = table[name or "nil"] - if not f then + sock:setoption("reuseaddr", true) + res, err = sock:bind(alt.addr, port) + if not res then + sock:close() + else + res, err = sock:listen(backlog) + if not res then + sock:close() + else + return sock + end + end + end + return nil, err + end + + _M.try = _M.newtry() + + function _M.choose(table) + return function(name, opt1, opt2) + if base.type(name) ~= "string" then + name, opt1, opt2 = "default", name, opt1 + end + local f = table[name or "nil"] + if not f then base.error("unknown key (" .. base.tostring(name) .. ")", 3) else return f(opt1, opt2) end - end - end - - ----------------------------------------------------------------------------- - -- Socket sources and sinks, conforming to LTN12 - ----------------------------------------------------------------------------- - -- create namespaces inside LuaSocket namespace - local sourcet, sinkt = {}, {} - _M.sourcet = sourcet - _M.sinkt = sinkt - - _M.BLOCKSIZE = 2048 - - sinkt["close-when-done"] = + end + end + + ----------------------------------------------------------------------------- + -- Socket sources and sinks, conforming to LTN12 + ----------------------------------------------------------------------------- + -- create namespaces inside LuaSocket namespace + local sourcet, sinkt = {}, {} + _M.sourcet = sourcet + _M.sinkt = sinkt + + _M.BLOCKSIZE = 2048 + + sinkt["close-when-done"] = function(sock) - return base.setmetatable( - { - getfd = function() - return sock:getfd() - end, - dirty = function() - return sock:dirty() + return base.setmetatable( + { + getfd = function() + return sock:getfd() + end, + dirty = function() + return sock:dirty() + end + }, + { + __call = function(self, chunk, err) + if not chunk then + sock:close() + return 1 + else + return sock:send(chunk) end - }, - { - __call = function(self, chunk, err) - if not chunk then - sock:close() - return 1 - else - return sock:send(chunk) - end - end - } - ) - end + end + } + ) + end sinkt["keep-open"] = function(sock) - return base.setmetatable( - { - getfd = function() - return sock:getfd() - end, - dirty = function() - return sock:dirty() + return base.setmetatable( + { + getfd = function() + return sock:getfd() + end, + dirty = function() + return sock:dirty() + end + }, + { + __call = function(self, chunk, err) + if chunk then + return sock:send(chunk) + else + return 1 end - }, - { - __call = function(self, chunk, err) - if chunk then - return sock:send(chunk) - else - return 1 - end - end - } - ) - end + end + } + ) + end sinkt["default"] = sinkt["keep-open"] @@ -179,133 +179,133 @@ local function createSocket() sourcet["by-length"] = function(sock, length) - return base.setmetatable( - { - getfd = function() - return sock:getfd() - end, - dirty = function() - return sock:dirty() + return base.setmetatable( + { + getfd = function() + return sock:getfd() + end, + dirty = function() + return sock:dirty() + end + }, + { + __call = function() + if length <= 0 then + return nil end - }, - { - __call = function() - if length <= 0 then - return nil - end - local size = math.min(socket.BLOCKSIZE, length) - local chunk, err = sock:receive(size) - if err then - return nil, err - end - length = length - string.len(chunk) - return chunk + local size = math.min(socket.BLOCKSIZE, length) + local chunk, err = sock:receive(size) + if err then + return nil, err end - } - ) - end + length = length - string.len(chunk) + return chunk + end + } + ) + end sourcet["until-closed"] = function(sock) - local done - return base.setmetatable( - { - getfd = function() - return sock:getfd() - end, - dirty = function() - return sock:dirty() + local done + return base.setmetatable( + { + getfd = function() + return sock:getfd() + end, + dirty = function() + return sock:dirty() + end + }, + { + __call = function() + if done then + return nil end - }, - { - __call = function() - if done then - return nil - end - local chunk, err, partial = sock:receive(socket.BLOCKSIZE) - if not err then - return chunk - elseif err == "closed" then - sock:close() - done = 1 - return partial - else - return nil, err - end + local chunk, err, partial = sock:receive(socket.BLOCKSIZE) + if not err then + return chunk + elseif err == "closed" then + sock:close() + done = 1 + return partial + else + return nil, err end - } - ) - end - - sourcet["default"] = sourcet["until-closed"] - - _M.source = _M.choose(sourcet) - - return _M + end + } + ) + end + + sourcet["default"] = sourcet["until-closed"] + + _M.source = _M.choose(sourcet) + + return _M end local function createJson() - local math = require("math") - local string = require("string") - local table = require("table") - local object = nil - ----------------------------------------------------------------------------- - -- Module declaration - ----------------------------------------------------------------------------- - local json = {} -- Public namespace + local math = require("math") + local string = require("string") + local table = require("table") + local object = nil + ----------------------------------------------------------------------------- + -- Module declaration + ----------------------------------------------------------------------------- + local json = {} -- Public namespace local json_private = {} -- Private namespace + + -- Public constants + json.EMPTY_ARRAY = {} + json.EMPTY_OBJECT = {} + -- Public functions - -- Public constants - json.EMPTY_ARRAY = {} - json.EMPTY_OBJECT = {} - -- Public functions - - -- Private functions - local decode_scanArray - local decode_scanComment - local decode_scanConstant - local decode_scanNumber - local decode_scanObject - local decode_scanString - local decode_scanWhitespace - local encodeString - local isArray - local isEncodable - - ----------------------------------------------------------------------------- - -- PUBLIC FUNCTIONS - ----------------------------------------------------------------------------- - --- Encodes an arbitrary Lua object / variable. - -- @param v The Lua object / variable to be JSON encoded. - -- @return String containing the JSON encoding in internal Lua string format (i.e. not unicode) - function json.encode(v) - -- Handle nil values - if v == nil then - return "null" - end - - local vtype = type(v) - - -- Handle strings - if vtype == "string" then + -- Private functions + local decode_scanArray + local decode_scanComment + local decode_scanConstant + local decode_scanNumber + local decode_scanObject + local decode_scanString + local decode_scanWhitespace + local encodeString + local isArray + local isEncodable + + ----------------------------------------------------------------------------- + -- PUBLIC FUNCTIONS + ----------------------------------------------------------------------------- + --- Encodes an arbitrary Lua object / variable. + -- @param v The Lua object / variable to be JSON encoded. + -- @return String containing the JSON encoding in internal Lua string format (i.e. not unicode) + function json.encode(v) + -- Handle nil values + if v == nil then + return "null" + end + + local vtype = type(v) + + -- Handle strings + if vtype == "string" then return '"' .. json_private.encodeString(v) .. '"' -- Need to handle encoding in string end - - -- Handle booleans - if vtype == "number" or vtype == "boolean" then + + -- Handle booleans + if vtype == "number" or vtype == "boolean" then return tostring(v) end - - -- Handle tables - if vtype == "table" then - local rval = {} - -- Consider arrays separately - local bArray, maxCount = isArray(v) - if bArray then - for i = 1, maxCount do - table.insert(rval, json.encode(v[i])) - end - else -- An object, not an array + + -- Handle tables + if vtype == "table" then + local rval = {} + -- Consider arrays separately + local bArray, maxCount = isArray(v) + if bArray then + for i = 1, maxCount do + table.insert(rval, json.encode(v[i])) + end + else -- An object, not an array for i, j in pairs(v) do if isEncodable(i) and isEncodable(j) then table.insert(rval, '"' .. json_private.encodeString(i) .. '":' .. json.encode(j)) @@ -317,23 +317,23 @@ local function createJson() else return "{" .. table.concat(rval, ",") .. "}" end - end - - -- Handle null values - if vtype == "function" and v == json.null then + end + + -- Handle null values + if vtype == "function" and v == json.null then return "null" end assert(false, "encode attempt to encode unsupported type " .. vtype .. ":" .. tostring(v)) end - - --- Decodes a JSON string and returns the decoded value as a Lua data structure / value. - -- @param s The string to scan. - -- @param [startPos] Optional starting position where the JSON string is located. Defaults to 1. - -- @param Lua object, number The object that was scanned, as a Lua table / string / number / boolean or nil, - -- and the position of the first character after - -- the scanned JSON object. - function json.decode(s, startPos) + + --- Decodes a JSON string and returns the decoded value as a Lua data structure / value. + -- @param s The string to scan. + -- @param [startPos] Optional starting position where the JSON string is located. Defaults to 1. + -- @param Lua object, number The object that was scanned, as a Lua table / string / number / boolean or nil, + -- and the position of the first character after + -- the scanned JSON object. + function json.decode(s, startPos) startPos = startPos and startPos or 1 startPos = decode_scanWhitespace(s, startPos) assert(startPos <= string.len(s), "Unterminated JSON encoded object found at position in [" .. s .. "]") @@ -366,19 +366,18 @@ local function createJson() function json.null() return json.null -- so json.null() will also return null ;-) end - - ----------------------------------------------------------------------------- - -- Internal, PRIVATE functions. - -- Following a Python-like convention, I have prefixed all these 'PRIVATE' - -- functions with an underscore. - ----------------------------------------------------------------------------- - --- Scans an array from JSON into a Lua object - -- startPos begins at the start of the array. - -- Returns the array and the next starting position - -- @param s The string being scanned. - -- @param startPos The starting position for the scan. - -- @return table, int The scanned array as a table, and the position of the next character to scan. - function decode_scanArray(s, startPos) + ----------------------------------------------------------------------------- + -- Internal, PRIVATE functions. + -- Following a Python-like convention, I have prefixed all these 'PRIVATE' + -- functions with an underscore. + ----------------------------------------------------------------------------- + --- Scans an array from JSON into a Lua object + -- startPos begins at the start of the array. + -- Returns the array and the next starting position + -- @param s The string being scanned. + -- @param startPos The starting position for the scan. + -- @return table, int The scanned array as a table, and the position of the next character to scan. + function decode_scanArray(s, startPos) local array = {} -- The return value local stringLen = string.len(s) assert( @@ -424,8 +423,8 @@ local function createJson() -- @return object, int The object (true, false or nil) and the position at which the next character should be -- scanned. function decode_scanConstant(s, startPos) - local consts = { ["true"] = true, ["false"] = false, ["null"] = nil } - local constNames = { "true", "false", "null" } + local consts = {["true"] = true, ["false"] = false, ["null"] = nil} + local constNames = {"true", "false", "null"} for i, k in pairs(constNames) do if string.sub(s, startPos, startPos + string.len(k) - 1) == k then @@ -574,7 +573,7 @@ local function createJson() assert( string.find(s, startChar, j + 1), "String decoding failed: missing closing " .. - startChar .. " at position " .. j .. "(for string at position " .. startPos .. ")" + startChar .. " at position " .. j .. "(for string at position " .. startPos .. ")" ) return table.concat(t, ""), j + 2 -- END SoniEx2 @@ -650,13 +649,13 @@ local function createJson() if v ~= (t.n or #t) then return false end -- False if n does not hold the number of elements - else -- Else of (k=='n') + else -- Else of (k=='n') if isEncodable(v) then return false end end -- End of (k~='n') - end -- End of k,v not an indexed pair - end -- End of loop across all pairs + end -- End of k,v not an indexed pair + end -- End of loop across all pairs return true, maxIndex end @@ -678,64 +677,64 @@ local debug_server = nil local breakInfoSocket = nil local json = createJson() local LuaDebugger = { - fileMaps = {}, - Run = true, --表示正常运行只检测断点 - StepIn = false, - StepNext = false, - StepOut = false, - breakInfos = {}, - runTimeType = nil, - isHook = true, - pathCachePaths = {}, - isProntToConsole = 1, - isDebugPrint = true, - hookType = "lrc", - stepNextFun = nil, - DebugLuaFie = "", - runLineCount = 0, - --分割字符串缓存 - splitFilePaths = {}, - version = "0.9.3", + fileMaps = {}, + Run = true, --表示正常运行只检测断点 + StepIn = false, + StepNext = false, + StepOut = false, + breakInfos = {}, + runTimeType = nil, + isHook = true, + pathCachePaths = {}, + isProntToConsole = 1, + isDebugPrint = true, + hookType = "lrc", + stepNextFun = nil, + DebugLuaFie = "", + runLineCount = 0, + --分割字符串缓存 + splitFilePaths = {}, + version="0.9.3", serVarLevel = 4 } local debug_hook = nil local _resume = coroutine.resume coroutine.resume = function(co, ...) - if (LuaDebugger.isHook) then + if (LuaDebugger.isHook) then if coroutine.status(co) ~= "dead" then debug.sethook(co, debug_hook, "lrc") - end + end end return _resume(co, ...) end LuaDebugger.event = { - S2C_SetBreakPoints = 1, - C2S_SetBreakPoints = 2, - S2C_RUN = 3, - C2S_HITBreakPoint = 4, - S2C_ReqVar = 5, - C2S_ReqVar = 6, - --单步跳过请求 - S2C_NextRequest = 7, - --单步跳过反馈 - C2S_NextResponse = 8, - -- 单步跳过 结束 没有下一步 - C2S_NextResponseOver = 9, - --单步跳入 - S2C_StepInRequest = 10, - C2S_StepInResponse = 11, - --单步跳出 - S2C_StepOutRequest = 12, - --单步跳出返回 - C2S_StepOutResponse = 13, - --打印 - C2S_LuaPrint = 14, - S2C_LoadLuaScript = 16, - C2S_SetSocketName = 17, - C2S_LoadLuaScript = 18, - C2S_DebugXpCall = 20, - S2C_DebugClose = 21, + S2C_SetBreakPoints = 1, + C2S_SetBreakPoints = 2, + S2C_RUN = 3, + C2S_HITBreakPoint = 4, + S2C_ReqVar = 5, + C2S_ReqVar = 6, + --单步跳过请求 + S2C_NextRequest = 7, + --单步跳过反馈 + C2S_NextResponse = 8, + -- 单步跳过 结束 没有下一步 + C2S_NextResponseOver = 9, + --单步跳入 + S2C_StepInRequest = 10, + C2S_StepInResponse = 11, + --单步跳出 + S2C_StepOutRequest = 12, + --单步跳出返回 + C2S_StepOutResponse = 13, + --打印 + C2S_LuaPrint = 14, + S2C_LoadLuaScript = 16, + C2S_SetSocketName = 17, + C2S_LoadLuaScript = 18, + C2S_DebugXpCall = 20, + S2C_DebugClose = 21, S2C_SerVar = 24, C2S_SerVar = 25, S2C_ReLoadFile = 26, @@ -743,27 +742,27 @@ LuaDebugger.event = { } --@region print function print(...) - if (LuaDebugger.isProntToConsole == 1 or LuaDebugger.isProntToConsole == 3) then + if (LuaDebugger.isProntToConsole == 1 or LuaDebugger.isProntToConsole == 3) then debugger_print(...) end if (LuaDebugger.isProntToConsole == 1 or LuaDebugger.isProntToConsole == 2) then if (debug_server) then - local arg = { ... } --这里的...和{}符号中间需要有空格号,否则会出错 + local arg = {...} --这里的...和{}符号中间需要有空格号,否则会出错 local str = "" if (#arg == 0) then - arg = { "nil" } - end - for k, v in pairs(arg) do - str = str .. tostring(v) .. "\t" - end - local sendMsg = { - event = LuaDebugger.event.C2S_LuaPrint, - data = { msg = ZZBase64.encode(str), type = 1 } - } - local sendStr = json.encode(sendMsg) - debug_server:send(sendStr .. "__debugger_k0204__") - end - end + arg = {"nil"} + end + for k, v in pairs(arg) do + str = str .. tostring(v) .. "\t" + end + local sendMsg = { + event = LuaDebugger.event.C2S_LuaPrint, + data = {msg = ZZBase64.encode(str), type = 1} + } + local sendStr = json.encode(sendMsg) + debug_server:send(sendStr .. "__debugger_k0204__") + end + end end function luaIdePrintWarn(...) @@ -772,48 +771,46 @@ function luaIdePrintWarn(...) end if (LuaDebugger.isProntToConsole == 1 or LuaDebugger.isProntToConsole == 2) then if (debug_server) then - local arg = { ... } --这里的...和{}符号中间需要有空格号,否则会出错 + local arg = {...} --这里的...和{}符号中间需要有空格号,否则会出错 local str = "" if (#arg == 0) then - arg = { "nil" } - end - for k, v in pairs(arg) do - str = str .. tostring(v) .. "\t" - end - local sendMsg = { - event = LuaDebugger.event.C2S_LuaPrint, - data = { msg = ZZBase64.encode(str), type = 2 } - } - local sendStr = json.encode(sendMsg) - debug_server:send(sendStr .. "__debugger_k0204__") - end - end + arg = {"nil"} + end + for k, v in pairs(arg) do + str = str .. tostring(v) .. "\t" + end + local sendMsg = { + event = LuaDebugger.event.C2S_LuaPrint, + data = {msg = ZZBase64.encode(str), type = 2} + } + local sendStr = json.encode(sendMsg) + debug_server:send(sendStr .. "__debugger_k0204__") + end + end end - function luaIdePrintErr(...) if (LuaDebugger.isProntToConsole == 1 or LuaDebugger.isProntToConsole == 3) then debugger_print(...) end if (LuaDebugger.isProntToConsole == 1 or LuaDebugger.isProntToConsole == 2) then if (debug_server) then - local arg = { ... } --这里的...和{}符号中间需要有空格号,否则会出错 + local arg = {...} --这里的...和{}符号中间需要有空格号,否则会出错 local str = "" if (#arg == 0) then - arg = { "nil" } - end - for k, v in pairs(arg) do - str = str .. tostring(v) .. "\t" - end - local sendMsg = { - event = LuaDebugger.event.C2S_LuaPrint, - data = { msg = ZZBase64.encode(str), type = 3 } - } - local sendStr = json.encode(sendMsg) - debug_server:send(sendStr .. "__debugger_k0204__") - end - end + arg = {"nil"} + end + for k, v in pairs(arg) do + str = str .. tostring(v) .. "\t" + end + local sendMsg = { + event = LuaDebugger.event.C2S_LuaPrint, + data = {msg = ZZBase64.encode(str), type = 3} + } + local sendStr = json.encode(sendMsg) + debug_server:send(sendStr .. "__debugger_k0204__") + end + end end - --@endregion --@region 辅助方法 @@ -844,23 +841,23 @@ local function debugger_convertParentDir(dir) end end -local function debugger_getFilePathInfo(file) - local fileName = nil +local function debugger_getFilePathInfo(file) + local fileName = nil local dir = nil file = file:gsub("/.\\", "/") - file = file:gsub("\\", "/") - file = file:gsub("//", "/") + file = file:gsub("\\", "/") + file = file:gsub("//", "/") + - - if file:find("@") == 1 then + if file:find("@") == 1 then file = file:sub(2) - end - local findex = file:find("%./") - if (findex == 1) then + end + local findex = file:find("%./") + if (findex == 1) then file = file:sub(3) end - file = debugger_convertParentDir(file) + file = debugger_convertParentDir(file) local fileLength = string.len(file) local suffixNames = { ".lua", @@ -889,8 +886,8 @@ local function debugger_getFilePathInfo(file) end local fileNameStartIndex = debugger_lastIndex(file, "/") if (fileNameStartIndex) then - fileName = string.sub(file, fileNameStartIndex + 1) - + fileName = string.sub(file, fileNameStartIndex + 1) + dir = string.sub(file, 1, fileNameStartIndex) file = dir .. fileName else @@ -901,12 +898,12 @@ local function debugger_getFilePathInfo(file) else dir = string.sub(file, 1, fileNameStartIndex) dir = dir:gsub("%.", "/") - fileName = string.sub(file, fileNameStartIndex + 1) - file = dir .. fileName + fileName = string.sub(file, fileNameStartIndex + 1) + file = dir .. fileName end - end + end - return file, dir, fileName + return file, dir, fileName end --@endregion @@ -918,25 +915,25 @@ end local function debugger_strSplit(input, delimiter) - input = tostring(input) - delimiter = tostring(delimiter) - if (delimiter == "") then + input = tostring(input) + delimiter = tostring(delimiter) + if (delimiter == "") then return false end - local pos, arr = 0, {} - -- for each divider found - for st, sp in function() + local pos, arr = 0, {} + -- for each divider found + for st, sp in function() return string.find(input, delimiter, pos, true) - end do - table.insert(arr, string.sub(input, pos, st - 1)) - pos = sp + 1 - end - table.insert(arr, string.sub(input, pos)) - return arr + end do + table.insert(arr, string.sub(input, pos, st - 1)) + pos = sp + 1 + end + table.insert(arr, string.sub(input, pos)) + return arr end local function debugger_strTrim(input) - input = string.gsub(input, "^[ \t\n\r]+", "") - return string.gsub(input, "[ \t\n\r]+$", "") + input = string.gsub(input, "^[ \t\n\r]+", "") + return string.gsub(input, "[ \t\n\r]+$", "") end local function debugger_dump(value, desciption, nesting) if type(nesting) ~= "number" then @@ -951,7 +948,7 @@ local function debugger_dump(value, desciption, nesting) return tostring(v) end local traceback = debugger_strSplit(debug.traceback("", 2), "\n") - -- print("dump from: " .. debugger_strTrim(traceback[3])) + print("dump from: " .. debugger_strTrim(traceback[3])) local function _dump(value, desciption, indent, nest, keylen) desciption = desciption or "" local spc = "" @@ -1000,7 +997,7 @@ local function debugger_dump(value, desciption, nesting) end _dump(value, desciption, "- ", 1) for i, line in ipairs(result) do - -- print(line) + print(line) end end --@endregion @@ -1008,24 +1005,27 @@ local function debugger_valueToString(v) local vtype = type(v) local vstr = nil if (vtype == "userdata") then - if (LuaDebugger.isFoxGloryProject) then - return "userdata", vtype + if (LuaDebugger.isFoxGloryProject ) then + + return "userdata",vtype + else return tostring(v), vtype end elseif (vtype == "table" or vtype == "function" or vtype == "boolean") then local value = vtype - xpcall(function() - if (LuaDebugger.isFoxGloryProject) then + xpcall(function() + if(LuaDebugger.isFoxGloryProject) then value = vtype else value = tostring(v) end - end, function() + + end,function() value = vtype end) return value, vtype - elseif (vtype == "number" or vtype == "string") then + elseif (vtype == "number" or vtype == "string" ) then return v, vtype else return tostring(v), vtype @@ -1033,12 +1033,12 @@ local function debugger_valueToString(v) end local function debugger_setVarInfo(name, value) local valueStr, valueType = debugger_valueToString(value) - local nameStr, nameType = debugger_valueToString(name) - if (valueStr == nil) then + local nameStr,nameType = debugger_valueToString(name) + if(valueStr == nil) then valueStr = valueType end local valueInfo = { - name = nameStr, + name =nameStr, valueType = valueType, valueStr = ZZBase64.encode(valueStr) } @@ -1047,282 +1047,283 @@ local function debugger_setVarInfo(name, value) end local function debugger_getvalue(f) - local i = 1 - local locals = {} - -- get locals - while true do - local name, value = debug.getlocal(f, i) - if not name then + local i = 1 + local locals = {} + -- get locals + while true do + local name, value = debug.getlocal(f, i) + if not name then break end if (name ~= "(*temporary)") then - locals[name] = value - end - i = i + 1 - end - local func = getinfo(f, "f").func - i = 1 - local ups = {} - while func do -- check for func as it may be nil for tail calls - local name, value = debug.getupvalue(func, i) - if not name then + locals[name] = value + end + i = i + 1 + end + local func = getinfo(f, "f").func + i = 1 + local ups = {} + while func do -- check for func as it may be nil for tail calls + local name, value = debug.getupvalue(func, i) + if not name then break end if (name == "_ENV") then - ups["_ENV_"] = value - else - ups[name] = value - end - i = i + 1 - end + ups["_ENV_"] = value + else + ups[name] = value + end + i = i + 1 + end - return { locals = locals, ups = ups } + return {locals = locals, ups = ups} end --获取堆栈 debugger_stackInfo = function(ignoreCount, event) - local datas = {} - local stack = {} - local varInfos = {} - local funcs = {} - local index = 0 - for i = ignoreCount, 100 do - local source = getinfo(i) - local isadd = true - if (i == ignoreCount) then - local file = source.source - if (file:find(LuaDebugger.DebugLuaFie)) then - return - end - if (file == "=[C]") then - isadd = false - end - end - if not source then - break - end - if (isadd) then - local fullName, dir, fileName = debugger_getFilePathInfo(source.source) - local info = { - src = fullName, - scoreName = source.name, - currentline = source.currentline, - linedefined = source.linedefined, - what = source.what, - nameWhat = source.namewhat - } - index = i - local vars = debugger_getvalue(i + 1) - table.insert(stack, info) - table.insert(varInfos, vars) - table.insert(funcs, source.func) - end - if source.what == "main" then - break - end + local datas = {} + local stack = {} + local varInfos = {} + local funcs = {} + local index = 0 + for i = ignoreCount, 100 do + local source = getinfo(i) + local isadd = true + if (i == ignoreCount) then + local file = source.source + if (file:find(LuaDebugger.DebugLuaFie)) then + return + end + if (file == "=[C]") then + isadd = false + end + end + if not source then + break + end + if (isadd) then + local fullName, dir, fileName = debugger_getFilePathInfo(source.source) + local info = { + src = fullName, + scoreName = source.name, + currentline = source.currentline, + linedefined = source.linedefined, + what = source.what, + nameWhat = source.namewhat + } + index = i + local vars = debugger_getvalue(i + 1) + table.insert(stack, info) + table.insert(varInfos, vars) + table.insert(funcs, source.func) + end + if source.what == "main" then + break end + end - local stackInfo = { stack = stack, vars = varInfos, funcs = funcs } - local data = { - stack = stackInfo.stack, - vars = stackInfo.vars, - funcs = stackInfo.funcs, - event = event, - funcsLength = #stackInfo.funcs, - upFunc = getinfo(ignoreCount - 3, "f").func - } + local stackInfo = {stack = stack, vars = varInfos, funcs = funcs} + local data = { + stack = stackInfo.stack, + vars = stackInfo.vars, + funcs = stackInfo.funcs, + event = event, + funcsLength = #stackInfo.funcs, + upFunc = getinfo(ignoreCount - 3, "f").func + } - return data - end + return data +end --==============================工具方法 end====================================================== --===========================点断信息================================================== --根据不同的游戏引擎进行定时获取断点信息 --CCDirector:sharedDirector():getScheduler() local debugger_setBreak = nil local function debugger_receiveDebugBreakInfo() - if (not jit) then - if (_VERSION) then - -- print("当前lua版本为: ".._VERSION.." 请使用 -----LuaDebug.lua----- 进行调试!") - else - -- print("当前为lua版本,请使用-----LuaDebug.lua-----进行调试!") - end - end - if (breakInfoSocket) then + if(not jit) then + if(_VERSION)then + print("当前lua版本为: ".._VERSION.." 请使用 -----LuaDebug.lua----- 进行调试!") + else + print("当前为lua版本,请使用-----LuaDebug.lua-----进行调试!") + end + end + if (breakInfoSocket) then local msg, status = breakInfoSocket:receive() - if (LuaDebugger.isLaunch == true and status == "closed") then + if(LuaDebugger.isLaunch == true and status == "closed") then os.exit() end - if (msg) then - local netData = json.decode(msg) - if netData.event == LuaDebugger.event.S2C_SetBreakPoints then - debugger_setBreak(netData.data) - elseif netData.event == LuaDebugger.event.S2C_LoadLuaScript then - LuaDebugger.loadScriptBody = netData.data + if (msg) then + local netData = json.decode(msg) + if netData.event == LuaDebugger.event.S2C_SetBreakPoints then + debugger_setBreak(netData.data) + elseif netData.event == LuaDebugger.event.S2C_LoadLuaScript then + LuaDebugger.loadScriptBody = netData.data debugger_exeLuaString() - debugger_sendMsg(breakInfoSocket, LuaDebugger.event.C2S_LoadLuaScript, LuaDebugger.loadScriptBody) + debugger_sendMsg(breakInfoSocket,LuaDebugger.event.C2S_LoadLuaScript,LuaDebugger.loadScriptBody) elseif netData.event == LuaDebugger.event.S2C_ReLoadFile then LuaDebugger.reLoadFileBody = netData.data LuaDebugger.isReLoadFile = false - LuaDebugger.reLoadFileBody.isReLoad = debugger_reLoadFile(LuaDebugger.reLoadFileBody) + LuaDebugger.reLoadFileBody.isReLoad = debugger_reLoadFile(LuaDebugger.reLoadFileBody) LuaDebugger.reLoadFileBody.script = nil - + debugger_sendMsg( breakInfoSocket, LuaDebugger.event.C2S_ReLoadFile, { stack = LuaDebugger.reLoadFileBody - + } - ) - end - end - end + ) + end + end + end end local function splitFilePath(path) - if (LuaDebugger.splitFilePaths[path]) then - return LuaDebugger.splitFilePaths[path] - end - local pos, arr = 0, {} - -- for each divider found - for st, sp in function() + if (LuaDebugger.splitFilePaths[path]) then + return LuaDebugger.splitFilePaths[path] + end + local pos, arr = 0, {} + -- for each divider found + for st, sp in function() return string.find(path, "/", pos, true) - end do - local pathStr = string.sub(path, pos, st - 1) - table.insert(arr, pathStr) - pos = sp + 1 - end - local pathStr = string.sub(path, pos) - table.insert(arr, pathStr) - LuaDebugger.splitFilePaths[path] = arr - return arr + end do + local pathStr = string.sub(path, pos, st - 1) + table.insert(arr, pathStr) + pos = sp + 1 + end + local pathStr = string.sub(path, pos) + table.insert(arr, pathStr) + LuaDebugger.splitFilePaths[path] = arr + return arr +end +debugger_setBreak = + function(datas) + local breakInfos = LuaDebugger.breakInfos + for i, data in ipairs(datas) do + data.fileName = string.lower(data.fileName) + data.serverPath = string.lower(data.serverPath) + local breakInfo = breakInfos[data.fileName] + if (not breakInfo) then + breakInfos[data.fileName] = {} + breakInfo = breakInfos[data.fileName] + end + if (not data.breakDatas or #data.breakDatas == 0) then + breakInfo[data.serverPath] = nil + else + local fileBreakInfo = breakInfo[data.serverPath] + if (not fileBreakInfo) then + fileBreakInfo = { + pathNames = splitFilePath(data.serverPath), + --命中次數判斷計數器 + hitCounts = {} + } + breakInfo[data.serverPath] = fileBreakInfo + end + local lineInfos = {} + for li, breakData in ipairs(data.breakDatas) do + lineInfos[breakData.line] = breakData + if (breakData.hitCondition and breakData.hitCondition ~= "") then + breakData.hitCondition = tonumber(breakData.hitCondition) + else + breakData.hitCondition = 0 + end + if (not fileBreakInfo.hitCounts[breakData.line]) then + fileBreakInfo.hitCounts[breakData.line] = 0 + end + end + fileBreakInfo.lines = lineInfos + --這裡添加命中次數判斷 + for line, count in pairs(fileBreakInfo.hitCounts) do + if (not lineInfos[line]) then + fileBreakInfo.hitCounts[line] = nil + end + end + end + local count = 0 + for i, linesInfo in pairs(breakInfo) do + count = count + 1 + end + if (count == 0) then + breakInfos[data.fileName] = nil + end + end + --debugger_dump(breakInfos, "breakInfos", 6) + --检查是否需要断点 + local isHook = false + for k, v in pairs(breakInfos) do + isHook = true + break + end + + --这样做的原因是为了最大限度的使手机调试更加流畅 注意这里会连续的进行n次 + if (isHook) then + if (not LuaDebugger.isHook) then + debug.sethook(debug_hook, "lrc") + end + LuaDebugger.isHook = true + else + if (LuaDebugger.isHook) then + debug.sethook() + end + LuaDebugger.isHook = false + end end -debugger_setBreak = - function(datas) - local breakInfos = LuaDebugger.breakInfos - for i, data in ipairs(datas) do - data.fileName = string.lower(data.fileName) - data.serverPath = string.lower(data.serverPath) - local breakInfo = breakInfos[data.fileName] - if (not breakInfo) then - breakInfos[data.fileName] = {} - breakInfo = breakInfos[data.fileName] - end - if (not data.breakDatas or #data.breakDatas == 0) then - breakInfo[data.serverPath] = nil - else - local fileBreakInfo = breakInfo[data.serverPath] - if (not fileBreakInfo) then - fileBreakInfo = { - pathNames = splitFilePath(data.serverPath), - --命中次數判斷計數器 - hitCounts = {} - } - breakInfo[data.serverPath] = fileBreakInfo - end - local lineInfos = {} - for li, breakData in ipairs(data.breakDatas) do - lineInfos[breakData.line] = breakData - if (breakData.hitCondition and breakData.hitCondition ~= "") then - breakData.hitCondition = tonumber(breakData.hitCondition) - else - breakData.hitCondition = 0 - end - if (not fileBreakInfo.hitCounts[breakData.line]) then - fileBreakInfo.hitCounts[breakData.line] = 0 - end - end - fileBreakInfo.lines = lineInfos - --這裡添加命中次數判斷 - for line, count in pairs(fileBreakInfo.hitCounts) do - if (not lineInfos[line]) then - fileBreakInfo.hitCounts[line] = nil - end - end - end - local count = 0 - for i, linesInfo in pairs(breakInfo) do - count = count + 1 - end - if (count == 0) then - breakInfos[data.fileName] = nil - end - end - --debugger_dump(breakInfos, "breakInfos", 6) - --检查是否需要断点 - local isHook = false - for k, v in pairs(breakInfos) do - isHook = true - break - end - - --这样做的原因是为了最大限度的使手机调试更加流畅 注意这里会连续的进行n次 - if (isHook) then - if (not LuaDebugger.isHook) then - debug.sethook(debug_hook, "lrc") - end - LuaDebugger.isHook = true - else - if (LuaDebugger.isHook) then - debug.sethook() - end - LuaDebugger.isHook = false - end - end local function debugger_checkFileIsBreak(fileName) - return LuaDebugger.breakInfos[fileName] + return LuaDebugger.breakInfos[fileName] end --=====================================断点信息 end ---------------------------------------------- local controller_host = "192.168.1.102" local controller_port = 7003 debugger_sendMsg = function(serverSocket, eventName, data) - local sendMsg = { - event = eventName, - data = data - } - local sendStr = json.encode(sendMsg) - serverSocket:send(sendStr .. "__debugger_k0204__") + local sendMsg = { + event = eventName, + data = data + } + local sendStr = json.encode(sendMsg) + serverSocket:send(sendStr .. "__debugger_k0204__") end -function debugger_conditionStr(condition, vars, callBack) - local function loadScript() - local currentTabble = {} - - local locals = vars[1].locals - local ups = vars[1].ups - if (ups) then - for k, v in pairs(ups) do - currentTabble[k] = v - end - end - - if (locals) then - for k, v in pairs(locals) do - currentTabble[k] = v - end - end - setmetatable(currentTabble, { __index = _G }) - local fun = loadstring("return " .. condition) - setfenv(fun, currentTabble) - return fun() - end - local status, - msg = +function debugger_conditionStr(condition, vars, callBack) + local function loadScript() + local currentTabble = {} + + local locals = vars[1].locals + local ups = vars[1].ups + if (ups) then + for k, v in pairs(ups) do + currentTabble[k] = v + end + end + + if (locals) then + for k, v in pairs(locals) do + currentTabble[k] = v + end + end + setmetatable(currentTabble, {__index = _G}) + local fun = loadstring("return " .. condition) + setfenv(fun, currentTabble) + return fun() + end + local status, + msg = xpcall( - loadScript, - function(error) - -- print(error) - end - ) + loadScript, + function(error) + print(error) + end + ) if (status and msg) then callBack() end end - --执行lua字符串 debugger_exeLuaString = function() + local function loadScript() + local script = LuaDebugger.loadScriptBody.script if (LuaDebugger.loadScriptBody.isBreak) then - local currentTabble = { _G = _G } + local currentTabble = {_G = _G} local frameId = LuaDebugger.loadScriptBody.frameId frameId = frameId local func = LuaDebugger.currentDebuggerData.funcs[frameId] @@ -1335,8 +1336,8 @@ debugger_exeLuaString = function() for k, v in pairs(locals) do currentTabble[k] = v end - setmetatable(currentTabble, { __index = _G }) - + setmetatable(currentTabble, {__index = _G}) + local fun = loadstring(script) setfenv(fun, currentTabble) fun() @@ -1346,51 +1347,54 @@ debugger_exeLuaString = function() end end local status, - msg = + msg = xpcall( - loadScript, - function(error) - -- debugger_sendMsg(debug_server, LuaDebugger.event.C2S_LoadLuaScript, LuaDebugger.loadScriptBody) - end - ) - LuaDebugger.loadScriptBody.script = nil + loadScript, + function(error) + + -- debugger_sendMsg(debug_server, LuaDebugger.event.C2S_LoadLuaScript, LuaDebugger.loadScriptBody) + end + ) + LuaDebugger.loadScriptBody.script = nil if (LuaDebugger.loadScriptBody.isBreak) then - LuaDebugger.serVarLevel = LuaDebugger.serVarLevel + 1 - LuaDebugger.currentDebuggerData = debugger_stackInfo(LuaDebugger.serVarLevel, LuaDebugger.event - .C2S_HITBreakPoint) - LuaDebugger.loadScriptBody.stack = LuaDebugger.currentDebuggerData.stack - end + LuaDebugger.serVarLevel = LuaDebugger.serVarLevel+1 + LuaDebugger.currentDebuggerData = debugger_stackInfo(LuaDebugger.serVarLevel, LuaDebugger.event.C2S_HITBreakPoint) + LuaDebugger.loadScriptBody.stack = LuaDebugger.currentDebuggerData.stack + end LuaDebugger.loadScriptBody.complete = true + end --@region 调试中修改变量值 --根据key 值在 value 查找 -local function debugger_getTablekey(key, keyType, value) - if (keyType == -1) then +local function debugger_getTablekey(key,keyType,value) + if(keyType == -1) then return key - elseif (keyType == 1) then + elseif(keyType == 1) then return tonumber(key) - elseif (keyType == 2) then + elseif(keyType == 2) then local valueKey = nil - for k, v in pairs(value) do + for k,v in pairs(value) do local nameType = type(k) - if (nameType == "userdata" or nameType == "table") then + if(nameType == "userdata" or nameType == "table") then if (not LuaDebugger.isFoxGloryProject) then valueKey = tostring(k) - if (key == valueKey) then + if(key == valueKey) then return k end break end end end + end end local function debugger_setVarValue(server, data) + local newValue = nil - local level = LuaDebugger.serVarLevel + LuaDebugger.setVarBody.frameId + local level = LuaDebugger.serVarLevel+LuaDebugger.setVarBody.frameId local firstKeyName = data.keys[1] --@region vars check local localValueChangeIndex = -1 @@ -1405,7 +1409,7 @@ local function debugger_setVarValue(server, data) if not name then break end - if (firstKeyName == name) then + if(firstKeyName == name) then localValueChangeIndex = i oldValue = value end @@ -1419,11 +1423,11 @@ local function debugger_setVarValue(server, data) local ups = {} while func do -- check for func as it may be nil for tail calls local name, value = debug.getupvalue(func, i) - + if not name then break end - if (localValueChangeIndex == -1 and firstKeyName == name) then + if(localValueChangeIndex == -1 and firstKeyName == name) then upValueFun = func oldValue = value upValueChangeIndex = i @@ -1435,9 +1439,9 @@ local function debugger_setVarValue(server, data) end i = i + 1 end - --@endregion - local vars = { locals = locals, ups = ups } - +--@endregion + local vars = {locals = locals, ups = ups} + local function loadScript() local currentTabble = {} local locals = vars.locals @@ -1453,56 +1457,58 @@ local function debugger_setVarValue(server, data) currentTabble[k] = v end end - setmetatable(currentTabble, { __index = _G }) + setmetatable(currentTabble, {__index = _G}) local fun = loadstring("return " .. data.value) setfenv(fun, currentTabble) newValue = fun() end local status, - msg = + msg = xpcall( - loadScript, - function(error) - -- print(error, "============================") - end - ) - + loadScript, + function(error) + print(error, "============================") + end + ) + local i = 1 - + -- local 查找并替换 local keyLength = #data.keys - - if (keyLength == 1) then - if (localValueChangeIndex ~= -1) then + + if(keyLength == 1) then + if(localValueChangeIndex ~= -1) then + debug.setlocal(level, localValueChangeIndex, newValue) - elseif (upValueFun ~= nil) then - debug.setupvalue(upValueFun, upValueChangeIndex, newValue) + elseif(upValueFun ~= nil) then + debug.setupvalue( upValueFun, upValueChangeIndex, newValue ) else --全局变量查找 - if (_G[firstKeyName]) then + if(_G[firstKeyName]) then _G[firstKeyName] = newValue end end else - if (not oldValue) then - if (_G[firstKeyName]) then + if(not oldValue) then + if(_G[firstKeyName]) then oldValue = _G[firstKeyName] end end local tempValue = oldValue - for i = 2, keyLength - 1 do - if (tempValue) then - oldValue = oldValue[debugger_getTablekey(data.keys[i], data.numberTypes[i], oldValue)] + for i=2,keyLength-1 do + if(tempValue) then + oldValue = oldValue[debugger_getTablekey(data.keys[i],data.numberTypes[i],oldValue)] end end - if (tempValue) then - oldValue[debugger_getTablekey(data.keys[keyLength], data.numberTypes[keyLength], oldValue)] = newValue + if(tempValue) then + oldValue[debugger_getTablekey(data.keys[keyLength],data.numberTypes[keyLength],oldValue)] = newValue end end - local varInfo = debugger_setVarInfo(data.varName, newValue) + local varInfo = debugger_setVarInfo(data.varName, newValue) data.varInfo = varInfo - LuaDebugger.serVarLevel = LuaDebugger.serVarLevel + 1 + LuaDebugger.serVarLevel = LuaDebugger.serVarLevel+1 LuaDebugger.currentDebuggerData = debugger_stackInfo(LuaDebugger.serVarLevel, LuaDebugger.event.C2S_HITBreakPoint) + end --@endregion @@ -1512,107 +1518,107 @@ end --调试修改变量值统一的 _resume checkSetVar = function() - if (LuaDebugger.isSetVar) then - LuaDebugger.isSetVar = false - debugger_setVarValue(debug_server, LuaDebugger.setVarBody) - LuaDebugger.serVarLevel = LuaDebugger.serVarLevel + 1 - _resume(coro_debugger, LuaDebugger.setVarBody) - xpcall( - checkSetVar, - function(error) - -- print("设置变量", error) - end - ) - elseif (LuaDebugger.isLoadLuaScript) then - LuaDebugger.isLoadLuaScript = false - debugger_exeLuaString() - LuaDebugger.serVarLevel = LuaDebugger.serVarLevel + 1 - _resume(coro_debugger, LuaDebugger.reLoadFileBody) - xpcall( - checkSetVar, - function(error) - -- print("执行代码", error) - end - ) - elseif (LuaDebugger.isReLoadFile) then - LuaDebugger.isReLoadFile = false - LuaDebugger.reLoadFileBody.isReLoad = debugger_reLoadFile(LuaDebugger.reLoadFileBody) - -- print("重载结果:",LuaDebugger.reLoadFileBody.isReLoad) - LuaDebugger.reLoadFileBody.script = nil - LuaDebugger.serVarLevel = LuaDebugger.serVarLevel + 1 - _resume(coro_debugger, LuaDebugger.reLoadFileBody) - xpcall( - checkSetVar, - function(error) - -- print("重新加载文件", error) - end - ) - end + if (LuaDebugger.isSetVar) then + LuaDebugger.isSetVar = false + debugger_setVarValue(debug_server,LuaDebugger.setVarBody) + LuaDebugger.serVarLevel = LuaDebugger.serVarLevel+1 + _resume(coro_debugger, LuaDebugger.setVarBody) + xpcall( + checkSetVar, + function(error) + print("设置变量", error) + end + ) + elseif(LuaDebugger.isLoadLuaScript) then + LuaDebugger.isLoadLuaScript = false + debugger_exeLuaString() + LuaDebugger.serVarLevel = LuaDebugger.serVarLevel+1 + _resume(coro_debugger, LuaDebugger.reLoadFileBody) + xpcall( + checkSetVar, + function(error) + print("执行代码", error) + end + ) + elseif(LuaDebugger.isReLoadFile) then + LuaDebugger.isReLoadFile = false + LuaDebugger.reLoadFileBody.isReLoad = debugger_reLoadFile(LuaDebugger.reLoadFileBody) + print("重载结果:",LuaDebugger.reLoadFileBody.isReLoad) + LuaDebugger.reLoadFileBody.script = nil + LuaDebugger.serVarLevel = LuaDebugger.serVarLevel+1 + _resume(coro_debugger, LuaDebugger.reLoadFileBody) + xpcall( + checkSetVar, + function(error) + print("重新加载文件", error) + end + ) end - +end + local function getSource(source) - source = string.lower(source) + source = string.lower(source) if (LuaDebugger.pathCachePaths[source]) then - LuaDebugger.currentLineFile = LuaDebugger.pathCachePaths[source] - return LuaDebugger.pathCachePaths[source] - end + LuaDebugger.currentLineFile = LuaDebugger.pathCachePaths[source] + return LuaDebugger.pathCachePaths[source] + end - local fullName, dir, fileName = debugger_getFilePathInfo(source) - LuaDebugger.currentLineFile = fullName - LuaDebugger.pathCachePaths[source] = fileName + local fullName, dir, fileName = debugger_getFilePathInfo(source) + LuaDebugger.currentLineFile = fullName + LuaDebugger.pathCachePaths[source] = fileName - return fileName + return fileName end local function debugger_GeVarInfoBytUserData(server, var) - local fileds = LuaDebugTool.getUserDataInfo(var) + local fileds = LuaDebugTool.getUserDataInfo(var) + + local varInfos = {} - local varInfos = {} - - - --c# vars - for i = 1, fileds.Count do - local filed = fileds[i - 1] - local valueInfo = { - name = filed.name, - valueType = filed.valueType, - valueStr = ZZBase64.encode(filed.valueStr), - isValue = filed.isValue, - csharp = true - } - - table.insert(varInfos, valueInfo) - end - return varInfos -end + + --c# vars + for i = 1, fileds.Count do + local filed = fileds[i - 1] + local valueInfo = { + name = filed.name, + valueType = filed.valueType, + valueStr = ZZBase64.encode(filed.valueStr), + isValue = filed.isValue, + csharp = true + } + + table.insert(varInfos, valueInfo) + end + return varInfos +end local function debugger_getValueByScript(value, script) - local val = nil - local status, - msg = - xpcall( - function() - local fun = loadstring("return " .. script) - setfenv(fun, value) - val = fun() - end, - function(error) - -- print(error, "====>") - val = nil - end - ) + local val = nil + local status, + msg = + xpcall( + function() + local fun = loadstring("return " .. script) + setfenv(fun, value) + val = fun() + end, + function(error) + print(error, "====>") + val = nil + end + ) - return val + return val end -local function debugger_getVarByKeys(value, keys, index) - local str = "" - local keyLength = #keys - for i = index, keyLength do - local key = keys[i] - if (key == "[metatable]") then - else - if (i == index) then +local function debugger_getVarByKeys(value, keys, index) + local str = "" + local keyLength = #keys + for i = index, keyLength do + local key = keys[i] + if (key == "[metatable]") then + else + if (i == index) then if (string.find(key, "%.")) then if (str == "") then i = index + 1 @@ -1624,10 +1630,10 @@ local function debugger_getVarByKeys(value, keys, index) return debugger_getVarByKeys(value, keys, i) else - str = key - end - else - if (string.find(key, "%[")) then + str = key + end + else + if (string.find(key, "%[")) then str = str .. key elseif (type(key) == "string") then if (string.find(key, "table:") or string.find(key, "userdata:") or string.find(key, "function:")) then @@ -1706,7 +1712,7 @@ end local function debugger_searchVarByKeys(value, keys, searckKeys) local index, val = debugger_getVarByKeys(value, searckKeys, 1) - if (not LuaDebugTool or not LuaDebugTool.getCSharpValue or type(LuaDebugTool.getCSharpValue) ~= "function") then + if (not LuaDebugTool or not LuaDebugTool.getCSharpValue or type(LuaDebugTool.getCSharpValue) ~= "function") then return index, val end if (val) then @@ -1739,6 +1745,7 @@ end return ]] local function debugger_getmetatable(value, metatable, vinfos, server, variablesReference, debugSpeedIndex, metatables) + for i, mtable in ipairs(metatables) do if (metatable == mtable) then return vinfos @@ -1787,13 +1794,14 @@ local function debugger_getmetatable(value, metatable, vinfos, server, variables end end end - + local m = getmetatable(metatable) if (m) then return debugger_getmetatable(value, m, vinfos, server, variablesReference, debugSpeedIndex, metatables) else return vinfos end + end local function debugger_sendTableField(luatable, vinfos, server, variablesReference, debugSpeedIndex, valueType) if (valueType == "userdata") then @@ -1832,12 +1840,12 @@ local function debugger_sendTableValues(value, server, variablesReference, debug local valueType = type(value) local userDataInfos = {} local m = nil - + if (valueType == "userdata") then m = getmetatable(value) - + vinfos = debugger_sendTableField(value, vinfos, server, variablesReference, debugSpeedIndex, valueType) - + if (LuaDebugTool) then local varInfos = debugger_GeVarInfoBytUserData(server, value, variablesReference, debugSpeedIndex) @@ -1866,6 +1874,7 @@ local function debugger_sendTableValues(value, server, variablesReference, debug vinfos = {} end end + end else m = getmetatable(value) @@ -1889,55 +1898,56 @@ end --获取lua 变量的方法 local function debugger_getBreakVar(body, server) - local variablesReference = body.variablesReference - local debugSpeedIndex = body.debugSpeedIndex - local vinfos = {} - local function exe() - local frameId = body.frameId + local variablesReference = body.variablesReference + local debugSpeedIndex = body.debugSpeedIndex + local vinfos = {} + local function exe() + local frameId = body.frameId local type_ = body.type local keys = body.keys - --找到对应的var - local vars = nil - if (type_ == 1) then - vars = LuaDebugger.currentDebuggerData.vars[frameId + 1] - vars = vars.locals - elseif (type_ == 2) then - vars = LuaDebugger.currentDebuggerData.vars[frameId + 1] - vars = vars.ups - elseif (type_ == 3) then - vars = _G - end - if (#keys == 0) then - debugger_sendTableValues(vars, server, variablesReference, debugSpeedIndex) - return - end - local index, value = debugger_searchVarByKeys(vars, keys, keys) - if (value) then - local valueType = type(value) + --找到对应的var + local vars = nil + if (type_ == 1) then + vars = LuaDebugger.currentDebuggerData.vars[frameId + 1] + vars = vars.locals + elseif (type_ == 2) then + vars = LuaDebugger.currentDebuggerData.vars[frameId + 1] + vars = vars.ups + elseif (type_ == 3) then + vars = _G + end + if (#keys == 0) then + debugger_sendTableValues(vars, server, variablesReference, debugSpeedIndex) + return + end + local index, value = debugger_searchVarByKeys(vars, keys, keys) + if (value) then + local valueType = type(value) if (valueType == "table" or valueType == "userdata") then - debugger_sendTableValues(value, server, variablesReference, debugSpeedIndex) - else + + debugger_sendTableValues(value, server, variablesReference, debugSpeedIndex) + else if (valueType == "function") then - if (LuaDebugger.isFoxGloryProject) then - value = "function" + if(LuaDebugger.isFoxGloryProject) then + value = "function" else value = tostring(value) end - end - debugger_sendMsg( + end + debugger_sendMsg( server, LuaDebugger.event.C2S_ReqVar, { - variablesReference = variablesReference, - debugSpeedIndex = debugSpeedIndex, - vars = ZZBase64.encode(value), - isComplete = 1, - varType = valueType - } + variablesReference = variablesReference, + debugSpeedIndex = debugSpeedIndex, + vars = ZZBase64.encode(value), + isComplete = 1, + varType = valueType + } ) - end - else - debugger_sendMsg( + end + else + debugger_sendMsg( server, LuaDebugger.event.C2S_ReqVar, { @@ -1948,14 +1958,14 @@ local function debugger_getBreakVar(body, server) varType = "nil" } ) - end - end - xpcall( + end + end + xpcall( exe, function(error) - -- -- print("获取变量错误 错误消息-----------------") - -- -- print(error) - -- -- print(debug.traceback("", 2)) + -- print("获取变量错误 错误消息-----------------") + -- print(error) + -- print(debug.traceback("", 2)) debugger_sendMsg( server, LuaDebugger.event.C2S_ReqVar, @@ -1977,62 +1987,64 @@ local function debugger_getBreakVar(body, server) ) end local function ResetDebugInfo() - LuaDebugger.Run = false - LuaDebugger.StepIn = false - LuaDebugger.StepNext = false - LuaDebugger.StepOut = false + LuaDebugger.Run = false + LuaDebugger.StepIn = false + LuaDebugger.StepNext = false + LuaDebugger.StepOut = false + end local function debugger_loop(server) - server = debug_server - --命令 - local command - local eval_env = {} - local arg - while true do - local line, status = server:receive() - if (status == "closed") then - if (LuaDebugger.isLaunch) then + server = debug_server + --命令 + local command + local eval_env = {} + local arg + while true do + local line, status = server:receive() + if (status == "closed") then + if(LuaDebugger.isLaunch) then os.exit() else debug.sethook() coroutine.yield() end - end - if (line) then - local netData = json.decode(line) - local event = netData.event + end + if (line) then + local netData = json.decode(line) + local event = netData.event local body = netData.data if (event == LuaDebugger.event.S2C_DebugClose) then - if (LuaDebugger.isLaunch) then - os.exit() - else - debug.sethook() - coroutine.yield() - end - elseif event == LuaDebugger.event.S2C_SetBreakPoints then - --设置断点信息 - local function setB() - debugger_setBreak(body) - end - xpcall( + if(LuaDebugger.isLaunch) then + os.exit() + else + debug.sethook() + coroutine.yield() + end + + elseif event == LuaDebugger.event.S2C_SetBreakPoints then + --设置断点信息 + local function setB() + debugger_setBreak(body) + end + xpcall( setB, function(error) - -- print(error) + print(error) end ) - elseif event == LuaDebugger.event.S2C_RUN then --开始运行 - LuaDebugger.runTimeType = body.runTimeType - LuaDebugger.isProntToConsole = body.isProntToConsole + elseif event == LuaDebugger.event.S2C_RUN then --开始运行 + LuaDebugger.runTimeType = body.runTimeType + LuaDebugger.isProntToConsole = body.isProntToConsole LuaDebugger.isFoxGloryProject = body.isFoxGloryProject LuaDebugger.isLaunch = body.isLaunch - ResetDebugInfo() - LuaDebugger.currentDebuggerData = nil - LuaDebugger.Run = true + ResetDebugInfo() + LuaDebugger.currentDebuggerData = nil + LuaDebugger.Run = true LuaDebugger.tempRunFlag = true - LuaDebugger.currentLine = nil - local data = coroutine.yield() - LuaDebugger.serVarLevel = 4 - LuaDebugger.currentDebuggerData = data + LuaDebugger.currentLine= nil + local data = coroutine.yield() + LuaDebugger.serVarLevel = 4 + LuaDebugger.currentDebuggerData = data debugger_sendMsg( server, data.event, @@ -2040,58 +2052,58 @@ local function debugger_loop(server) stack = data.stack } ) - elseif event == LuaDebugger.event.S2C_ReqVar then -- 获取变量信息 - --请求数据信息 - debugger_getBreakVar(body, server) - elseif event == LuaDebugger.event.S2C_NextRequest then -- 设置单步跳过 - ResetDebugInfo() - LuaDebugger.StepNext = true - --设置当前文件名和当前行数 - local data = coroutine.yield() - LuaDebugger.serVarLevel = 4 - --重置调试信息 - LuaDebugger.currentDebuggerData = data - debugger_sendMsg( + elseif event == LuaDebugger.event.S2C_ReqVar then -- 获取变量信息 + --请求数据信息 + debugger_getBreakVar(body, server) + elseif event == LuaDebugger.event.S2C_NextRequest then -- 设置单步跳过 + ResetDebugInfo() + LuaDebugger.StepNext = true + --设置当前文件名和当前行数 + local data = coroutine.yield() + LuaDebugger.serVarLevel = 4 + --重置调试信息 + LuaDebugger.currentDebuggerData = data + debugger_sendMsg( server, data.event, { stack = data.stack } ) - elseif (event == LuaDebugger.event.S2C_StepInRequest) then --单步跳入 - --单步跳入 - ResetDebugInfo() - LuaDebugger.StepIn = true - - local data = coroutine.yield() - LuaDebugger.serVarLevel = 4 - --重置调试信息 - LuaDebugger.currentDebuggerData = data - debugger_sendMsg( + elseif (event == LuaDebugger.event.S2C_StepInRequest) then --单步跳入 + --单步跳入 + ResetDebugInfo() + LuaDebugger.StepIn = true + + local data = coroutine.yield() + LuaDebugger.serVarLevel = 4 + --重置调试信息 + LuaDebugger.currentDebuggerData = data + debugger_sendMsg( server, data.event, { - stack = data.stack, - eventType = data.eventType - } - ) - elseif (event == LuaDebugger.event.S2C_StepOutRequest) then - --单步跳出 - ResetDebugInfo() - LuaDebugger.StepOut = true - local data = coroutine.yield() - LuaDebugger.serVarLevel = 4 - --重置调试信息 - LuaDebugger.currentDebuggerData = data - debugger_sendMsg( + stack = data.stack, + eventType = data.eventType + } + ) + elseif (event == LuaDebugger.event.S2C_StepOutRequest) then + --单步跳出 + ResetDebugInfo() + LuaDebugger.StepOut = true + local data = coroutine.yield() + LuaDebugger.serVarLevel = 4 + --重置调试信息 + LuaDebugger.currentDebuggerData = data + debugger_sendMsg( server, data.event, { - stack = data.stack, - eventType = data.eventType - } - ) - elseif event == LuaDebugger.event.S2C_LoadLuaScript then + stack = data.stack, + eventType = data.eventType + } + ) + elseif event == LuaDebugger.event.S2C_LoadLuaScript then LuaDebugger.loadScriptBody = body LuaDebugger.isLoadLuaScript = true local data = coroutine.yield() @@ -2111,8 +2123,8 @@ local function debugger_loop(server) stack = data, eventType = data.eventType } - ) - elseif event == LuaDebugger.event.S2C_ReLoadFile then + ) + elseif event == LuaDebugger.event.S2C_ReLoadFile then LuaDebugger.isReLoadFile = true LuaDebugger.reLoadFileBody = body local data = coroutine.yield() @@ -2123,321 +2135,340 @@ local function debugger_loop(server) stack = data, eventType = data.eventType } - ) - end - end - end + ) + end + end + end end coro_debugger = coroutine.create(debugger_loop) debug_hook = function(event, line) - if (not LuaDebugger.isHook) then - return - end - if (LuaDebugger.Run) then - if (event == "line") then - local isCheck = false - for k, breakInfo in pairs(LuaDebugger.breakInfos) do - for bk, linesInfo in pairs(breakInfo) do - if (linesInfo.lines and linesInfo.lines[line]) then - isCheck = true - break - end - end - if (isCheck) then - break - end - end + if(not LuaDebugger.isHook) then + return + end - if (not isCheck) then - return - end - end - end + if(LuaDebugger.Run) then + if(event == "line") then + local isCheck = false + for k, breakInfo in pairs(LuaDebugger.breakInfos) do + for bk, linesInfo in pairs(breakInfo) do + + if(linesInfo.lines and linesInfo.lines[line]) then + isCheck = true + break + end + end + if(isCheck) then + break + end + end + + if(not isCheck) then + return + end + + end + end + + + local file = nil + if(event == "line") then + + local funs = nil + local funlength =0 + if(LuaDebugger.currentDebuggerData) then + funs = LuaDebugger.currentDebuggerData.funcs + funlength = #funs + end + local stepInfo = getinfo(2) + local tempFunc = stepInfo.func + local source = stepInfo.source + file = getSource(source); + if(source == "=[C]" or source:find(LuaDebugger.DebugLuaFie)) then return end + if(funlength > 0 and funs[1] == tempFunc and LuaDebugger.currentLine ~= line) then + LuaDebugger.runLineCount = LuaDebugger.runLineCount+1 + end + local breakInfo = LuaDebugger.breakInfos[file] + local breakData = nil + local ischeck = false + if(breakInfo) then + + for k, lineInfo in pairs(breakInfo) do + local lines = lineInfo.lines + if(lines and lines[line]) then + ischeck = true + break + end + end + end + local isHit = false + if(ischeck) then - local file = nil - if (event == "line") then - local funs = nil - local funlength = 0 - if (LuaDebugger.currentDebuggerData) then - funs = LuaDebugger.currentDebuggerData.funcs - funlength = #funs - end - local stepInfo = getinfo(2) - local tempFunc = stepInfo.func - local source = stepInfo.source - file = getSource(source); - if (source == "=[C]" or source:find(LuaDebugger.DebugLuaFie)) then return end - if (funlength > 0 and funs[1] == tempFunc and LuaDebugger.currentLine ~= line) then - LuaDebugger.runLineCount = LuaDebugger.runLineCount + 1 - end - local breakInfo = LuaDebugger.breakInfos[file] - local breakData = nil - local ischeck = false - if (breakInfo) then - for k, lineInfo in pairs(breakInfo) do - local lines = lineInfo.lines - if (lines and lines[line]) then - ischeck = true - break - end - end - end - local isHit = false - if (ischeck) then --并且在断点中 - local info = stepInfo - local source = string.lower(info.source) - local fullName, dir, fileName = debugger_getFilePathInfo(source) - local hitPathNames = splitFilePath(fullName) + local info = stepInfo + local source = string.lower( info.source ) + local fullName,dir,fileName = debugger_getFilePathInfo(source) + local hitPathNames = splitFilePath(fullName) + + local hitCounts = {} + local debugHitCounts = nil + for k, lineInfo in pairs(breakInfo) do - local hitCounts = {} - local debugHitCounts = nil - for k, lineInfo in pairs(breakInfo) do local lines = lineInfo.lines - local pathNames = lineInfo.pathNames - debugHitCounts = lineInfo.hitCounts - if (lines and lines[line]) then - breakData = lines[line] - --判断路径 - hitCounts[k] = 0 - local hitPathNamesCount = #hitPathNames - local pathNamesCount = #pathNames - local checkCount = 0; - while (true) do - if (pathNames[pathNamesCount] ~= hitPathNames[hitPathNamesCount]) then - break - else - hitCounts[k] = hitCounts[k] + 1 - end - pathNamesCount = pathNamesCount - 1 - hitPathNamesCount = hitPathNamesCount - 1 - checkCount = checkCount + 1 - if (pathNamesCount <= 0 or hitPathNamesCount <= 0) then - break - end - end - if (checkCount > 0) then - break; - end - else - breakData = nil - end - end - if (breakData) then - local hitFieName = "" - local maxCount = 0 - for k, v in pairs(hitCounts) do - if (v > maxCount) then - maxCount = v - hitFieName = k; - end - end - local hitPathNamesLength = #hitPathNames - if (hitPathNamesLength == 1 or (hitPathNamesLength > 1 and maxCount > 1)) then - if (hitFieName ~= "") then + local pathNames = lineInfo.pathNames + debugHitCounts = lineInfo.hitCounts + if(lines and lines[line]) then + breakData = lines[line] + --判断路径 + hitCounts[k] = 0 + local hitPathNamesCount = #hitPathNames + local pathNamesCount = #pathNames + local checkCount = 0; + while(true) do + if (pathNames[pathNamesCount] ~= hitPathNames[hitPathNamesCount]) then + break + else + hitCounts[k] = hitCounts[k] + 1 + end + pathNamesCount = pathNamesCount - 1 + hitPathNamesCount = hitPathNamesCount - 1 + checkCount = checkCount+1 + if(pathNamesCount <= 0 or hitPathNamesCount <= 0) then + break + end + end + if(checkCount>0) then + break; + end + else + breakData = nil + end + end + if(breakData) then + local hitFieName = "" + local maxCount = 0 + for k, v in pairs(hitCounts) do + if(v > maxCount) then + maxCount = v + hitFieName = k; + end + end + local hitPathNamesLength = #hitPathNames + if (hitPathNamesLength == 1 or (hitPathNamesLength > 1 and maxCount > 1)) then + if(hitFieName ~= "") then + local hitCount = breakData.hitCondition - local clientHitCount = debugHitCounts[breakData.line] - clientHitCount = clientHitCount + 1 - debugHitCounts[breakData.line] = clientHitCount - if (funs and funs[1] == tempFunc and LuaDebugger.runLineCount == 0) then - LuaDebugger.runLineCount = 0 - elseif (LuaDebugger.tempRunFlag and LuaDebugger.currentLine == line) then - LuaDebugger.runLineCount = 0 - LuaDebugger.tempRunFlag = nil - elseif (clientHitCount >= hitCount) then - isHit = true - end - end - end - end - end - if (LuaDebugger.StepOut) then - if (funlength == 1) then - ResetDebugInfo(); - LuaDebugger.Run = true - return - else - if (funs[2] == tempFunc) then - local data = debugger_stackInfo(3, LuaDebugger.event.C2S_StepInResponse) - -- -- print("StepIn 挂起") - --挂起等待调试器作出反应 + local clientHitCount = debugHitCounts[breakData.line] + clientHitCount = clientHitCount + 1 + debugHitCounts[breakData.line] = clientHitCount + if(funs and funs[1] == tempFunc and LuaDebugger.runLineCount == 0) then + LuaDebugger.runLineCount = 0 + elseif(LuaDebugger.tempRunFlag and LuaDebugger.currentLine == line) then + LuaDebugger.runLineCount = 0 + LuaDebugger.tempRunFlag = nil + elseif(clientHitCount >= hitCount) then + isHit = true + end + + end + end + end + end + if(LuaDebugger.StepOut) then + if(funlength == 1) then + ResetDebugInfo(); + LuaDebugger.Run = true + return + else + if(funs[2] == tempFunc) then + local data = debugger_stackInfo(3, LuaDebugger.event.C2S_StepInResponse) + -- print("StepIn 挂起") + --挂起等待调试器作出反应 _resume(coro_debugger, data) checkSetVar() - return - end - end - end - - if (LuaDebugger.StepIn) then - if (funs[1] == tempFunc and LuaDebugger.runLineCount == 0) then - return - end - local data = debugger_stackInfo(3, LuaDebugger.event.C2S_StepInResponse) - -- -- print("StepIn 挂起") - --挂起等待调试器作出反应 + return + end + end + end + + if(LuaDebugger.StepIn) then + if(funs[1] == tempFunc and LuaDebugger.runLineCount == 0) then + return + end + local data = debugger_stackInfo(3, LuaDebugger.event.C2S_StepInResponse) + -- print("StepIn 挂起") + --挂起等待调试器作出反应 _resume(coro_debugger, data) checkSetVar() - return - end - - if (LuaDebugger.StepNext) then - local isNext = false - if (funs) then - for i, f in ipairs(funs) do - if (tempFunc == f) then - if (LuaDebugger.currentLine == line) then - return - end - isNext = true - break; - end - end + return + end + + if(LuaDebugger.StepNext ) then + local isNext = false + if(funs) then + for i,f in ipairs(funs) do + if(tempFunc == f) then + if(LuaDebugger.currentLine == line) then + return + end + isNext =true + break; + end + end else - isNext = true - end - if (isNext) then - local data = debugger_stackInfo(3, LuaDebugger.event.C2S_NextResponse) - LuaDebugger.runLineCount = 0 - LuaDebugger.currentLine = line - --挂起等待调试器作出反应 + + isNext =true + end + if(isNext) then + local data = debugger_stackInfo(3, LuaDebugger.event.C2S_NextResponse) + LuaDebugger.runLineCount = 0 + LuaDebugger.currentLine = line + --挂起等待调试器作出反应 _resume(coro_debugger, data) checkSetVar() - return - end - end + return + end + end + + local sevent = nil + - local sevent = nil + --断点判断 + if(isHit) then + - - --断点判断 - if (isHit) then - LuaDebugger.runLineCount = 0 - LuaDebugger.currentLine = line - sevent = LuaDebugger.event.C2S_HITBreakPoint - --调用 coro_debugger 并传入 参数 - local data = debugger_stackInfo(3, sevent) - --挂起等待调试器作出反应 - if (breakData and breakData.condition) then - debugger_conditionStr(breakData.condition, data.vars, function() + LuaDebugger.runLineCount = 0 + LuaDebugger.currentLine = line + sevent = LuaDebugger.event.C2S_HITBreakPoint + --调用 coro_debugger 并传入 参数 + local data = debugger_stackInfo(3, sevent) + --挂起等待调试器作出反应 + if(breakData and breakData.condition) then + debugger_conditionStr(breakData.condition,data.vars,function() _resume(coro_debugger, data) checkSetVar() - end) - else - --挂起等待调试器作出反应 + end) + else + --挂起等待调试器作出反应 _resume(coro_debugger, data) checkSetVar() - end - end - end + end + end + end end local function debugger_xpcall() - --调用 coro_debugger 并传入 参数 + --调用 coro_debugger 并传入 参数 local data = debugger_stackInfo(4, LuaDebugger.event.C2S_HITBreakPoint) - if (data.stack and data.stack[1]) then - data.stack[1].isXpCall = true + if(data.stack and data.stack[1]) then + data.stack[1].isXpCall = true end - --挂起等待调试器作出反应 + --挂起等待调试器作出反应 _resume(coro_debugger, data) checkSetVar() end --调试开始 local function start() - local socket = createSocket() - -- print(controller_host) - -- print(controller_port) + + local socket = createSocket() + print(controller_host) + print(controller_port) + + local fullName,dirName,fileName = debugger_getFilePathInfo(getinfo(1).source) + LuaDebugger.DebugLuaFie = fileName + local server = socket.connect(controller_host, controller_port) + debug_server = server; + if server then + --创建breakInfo socket + socket = createSocket() + breakInfoSocket = socket.connect(controller_host, controller_port) + if(breakInfoSocket) then + breakInfoSocket:settimeout(0) + debugger_sendMsg(breakInfoSocket, LuaDebugger.event.C2S_SetSocketName, { + name = "breakPointSocket" + }) + + + debugger_sendMsg(server, LuaDebugger.event.C2S_SetSocketName, { + name = "mainSocket", + version = LuaDebugger.version - local fullName, dirName, fileName = debugger_getFilePathInfo(getinfo(1).source) - LuaDebugger.DebugLuaFie = fileName - local server = socket.connect(controller_host, controller_port) - debug_server = server; - if server then - --创建breakInfo socket - socket = createSocket() - breakInfoSocket = socket.connect(controller_host, controller_port) - if (breakInfoSocket) then - breakInfoSocket:settimeout(0) - debugger_sendMsg(breakInfoSocket, LuaDebugger.event.C2S_SetSocketName, { - name = "breakPointSocket" - }) - - - debugger_sendMsg(server, LuaDebugger.event.C2S_SetSocketName, { - name = "mainSocket", - version = LuaDebugger.version - - }) - xpcall(function() - sethook(debug_hook, "lrc") - end, function(error) - -- print("error:", error) - end) - if (not jit) then - if (_VERSION) then - -- print("当前lua版本为: ".._VERSION.." 请使用LuaDebug 进行调试!") - else - -- print("当前为lua版本,请使用LuaDebug 进行调试!") - end - end - _resume(coro_debugger, server) - end - end + }) + xpcall(function() + sethook(debug_hook, "lrc") + end, function(error) + print("error:", error) + end) + if(not jit) then + if(_VERSION)then + print("当前lua版本为: ".._VERSION.." 请使用LuaDebug 进行调试!") + else + print("当前为lua版本,请使用LuaDebug 进行调试!") + end + + end + _resume(coro_debugger, server) + end + end end function StartDebug(host, port) - if (not host) then - -- print("error host nil") - end - if (not port) then - -- print("error prot nil") - end - if (type(host) ~= "string") then - -- print("error host not string") - end - if (type(port) ~= "number") then - -- print("error host not number") - end - controller_host = host - controller_port = port - xpcall(start, function(error) - -- body - -- print(error) - end) - return debugger_receiveDebugBreakInfo, debugger_xpcall + + + if(not host) then + print("error host nil") + end + if(not port) then + print("error prot nil") + end + if(type(host) ~= "string") then + print("error host not string") + end + if(type(port) ~= "number") then + print("error host not number") + end + controller_host = host + controller_port = port + xpcall(start, function(error) + -- body + print(error) + end) + return debugger_receiveDebugBreakInfo, debugger_xpcall end + + --base64 local string = string ZZBase64.__code = { - 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', - 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', - 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', - 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/', -}; + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', + 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', + 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', + 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/', + }; ZZBase64.__decode = {} -for k, v in pairs(ZZBase64.__code) do - ZZBase64.__decode[string.byte(v, 1)] = k - 1 +for k,v in pairs(ZZBase64.__code) do + ZZBase64.__decode[string.byte(v,1)] = k - 1 end function ZZBase64.encode(text) - local len = string.len(text) - local left = len % 3 - len = len - left - local res = {} - local index = 1 + local len = string.len(text) + local left = len % 3 + len = len - left + local res = {} + local index = 1 for i = 1, len, 3 do - local a = string.byte(text, i) + local a = string.byte(text, i ) local b = string.byte(text, i + 1) local c = string.byte(text, i + 2) -- num = a<<16 + b<<8 + c - local num = a * 65536 + b * 256 + c + local num = a * 65536 + b * 256 + c for j = 1, 4 do --tmp = num >> ((4 -j) * 6) - local tmp = math.floor(num / (2 ^ ((4 - j) * 6))) + local tmp = math.floor(num / (2 ^ ((4-j) * 6))) --curPos = tmp&0x3f local curPos = tmp % 64 + 1 res[index] = ZZBase64.__code[curPos] @@ -2448,52 +2479,52 @@ function ZZBase64.encode(text) if left == 1 then ZZBase64.__left1(res, index, text, len) elseif left == 2 then - ZZBase64.__left2(res, index, text, len) + ZZBase64.__left2(res, index, text, len) end return table.concat(res) end function ZZBase64.__left2(res, index, text, len) local num1 = string.byte(text, len + 1) - num1 = num1 * 1024 --lshift 10 + num1 = num1 * 1024 --lshift 10 local num2 = string.byte(text, len + 2) - num2 = num2 * 4 --lshift 2 + num2 = num2 * 4 --lshift 2 local num = num1 + num2 - + local tmp1 = math.floor(num / 4096) --rShift 12 local curPos = tmp1 % 64 + 1 res[index] = ZZBase64.__code[curPos] - + local tmp2 = math.floor(num / 64) curPos = tmp2 % 64 + 1 res[index + 1] = ZZBase64.__code[curPos] curPos = num % 64 + 1 res[index + 2] = ZZBase64.__code[curPos] - - res[index + 3] = "=" + + res[index + 3] = "=" end -function ZZBase64.__left1(res, index, text, len) +function ZZBase64.__left1(res, index,text, len) local num = string.byte(text, len + 1) - num = num * 16 - + num = num * 16 + local tmp = math.floor(num / 64) local curPos = tmp % 64 + 1 - res[index] = ZZBase64.__code[curPos] - + res[index ] = ZZBase64.__code[curPos] + curPos = num % 64 + 1 res[index + 1] = ZZBase64.__code[curPos] - - res[index + 2] = "=" - res[index + 3] = "=" + + res[index + 2] = "=" + res[index + 3] = "=" end function ZZBase64.decode(text) local len = string.len(text) - local left = 0 + local left = 0 if string.sub(text, len - 1) == "==" then - left = 2 + left = 2 len = len - 4 elseif string.sub(text, len) == "=" then left = 1 @@ -2503,20 +2534,20 @@ function ZZBase64.decode(text) local res = {} local index = 1 local decode = ZZBase64.__decode - for i = 1, len, 4 do - local a = decode[string.byte(text, i)] - local b = decode[string.byte(text, i + 1)] - local c = decode[string.byte(text, i + 2)] - local d = decode[string.byte(text, i + 3)] + for i =1, len, 4 do + local a = decode[string.byte(text,i )] + local b = decode[string.byte(text,i + 1)] + local c = decode[string.byte(text,i + 2)] + local d = decode[string.byte(text,i + 3)] --num = a<<18 + b<<12 + c<<6 + d local num = a * 262144 + b * 4096 + c * 64 + d - + local e = string.char(num % 256) num = math.floor(num / 256) local f = string.char(num % 256) num = math.floor(num / 256) - res[index] = string.char(num % 256) + res[index ] = string.char(num % 256) res[index + 1] = f res[index + 2] = e index = index + 3 @@ -2532,11 +2563,11 @@ end function ZZBase64.__decodeLeft1(res, index, text, len) local decode = ZZBase64.__decode - local a = decode[string.byte(text, len + 1)] - local b = decode[string.byte(text, len + 2)] - local c = decode[string.byte(text, len + 3)] + local a = decode[string.byte(text, len + 1)] + local b = decode[string.byte(text, len + 2)] + local c = decode[string.byte(text, len + 3)] local num = a * 4096 + b * 64 + c - + local num1 = math.floor(num / 1024) % 256 local num2 = math.floor(num / 4) % 256 res[index] = string.char(num1) @@ -2545,11 +2576,14 @@ end function ZZBase64.__decodeLeft2(res, index, text, len) local decode = ZZBase64.__decode - local a = decode[string.byte(text, len + 1)] + local a = decode[string.byte(text, len + 1)] local b = decode[string.byte(text, len + 2)] local num = a * 64 + b num = math.floor(num / 16) res[index] = string.char(num) end + + + return StartDebug diff --git a/lua_probject/base_project/Main.lua b/lua_probject/base_project/Main.lua index 2158327f..61892950 100644 --- a/lua_probject/base_project/Main.lua +++ b/lua_probject/base_project/Main.lua @@ -152,35 +152,35 @@ function ShareScreenShot(n, callback) end) end -function shareQRCodePicture(url, secene) - ---- print(debug.traceback()) - -- print(url) - -- print(secene) +function shareQRCodePicture(url,secene) + --print(debug.traceback()) + print(url) + print(secene) local json_data = {} json_data["title"] = "湘北联赛" local mediaObject = {} local filename = "qrcode" .. DataManager.SelfUser.account_id - -- print(Application.persistentDataPath) + print(Application.persistentDataPath) mediaObject["path"] = Application.persistentDataPath mediaObject["filename"] = filename mediaObject["type"] = 1 json_data["mediaObject"] = mediaObject json_data["description"] = "一款现实中朋友约局休闲娱乐的场所!速度约朋友一起来玩吧!" json_data["scene"] = secene - -- print("json_data==================") + print("json_data==================") local json_str = json.encode(json_data) - pt(json_str) + pt(json_str) local tex2 = QRCodePicture.GenerateQRcode(url, 250, 250) - local tex1 = ResourcesManager.LoadObject("base/lobby/bg/bg.png", typeof(UnityEngine.Texture2D)) - filename = filename .. ".jpg" - -- print("text2==========") - -- print(tex2) - -- print("text1==========") - -- print(tex1) - -- print("filename==========") - -- print(filename) - QRCodePicture.CombanitePicture(tex1, tex2, 393, 1334 - 802 - 250, filename) - + local tex1 = ResourcesManager.LoadObject("base/lobby/bg/bg.png",typeof(UnityEngine.Texture2D)) + filename = filename ..".jpg" + print("text2==========") + print(tex2) + print("text1==========") + print(tex1) + print("filename==========") + print(filename) + QRCodePicture.CombanitePicture(tex1,tex2,393,1334-802-250,filename) + GameApplication.Instance:ShareLink(1, json_str, nil) end @@ -201,9 +201,7 @@ local bg_url = nil function LoadGameBg(url, main_view) local win_mode = main_view:GetChild("win_mode") win_mode:RemoveChildren(0, -1, true) - local tex_bg = ResourcesManager.LoadObjectByGroup(url .. ".png", typeof(UnityEngine.Texture), url) - -- print("===========================mainbg") - -- print(url..".png",typeof(UnityEngine.Texture), url) + local tex_bg = ResourcesManager.LoadObjectByGroup(url..".png",typeof(UnityEngine.Texture), url) local bg = GImage() bg.texture = FairyGUI.NTexture(tex_bg) bg.width = win_mode.width @@ -364,7 +362,7 @@ function LuaPrint(lua_table, limit, indent, step) end function printlog(...) - if debug_print then - -- print(...) - end + if debug_print then + print(...) + end end diff --git a/lua_probject/base_project/debug/LuaDebug.lua b/lua_probject/base_project/debug/LuaDebug.lua index 9d591912..f7481d24 100644 --- a/lua_probject/base_project/debug/LuaDebug.lua +++ b/lua_probject/base_project/debug/LuaDebug.lua @@ -1,7 +1,7 @@ -local debugger_reLoadFile = nil -xpcall(function() +local debugger_reLoadFile =nil +xpcall(function() debugger_reLoadFile = require("luaideReLoadFile") -end, function() +end,function() debugger_reLoadFile = function() print("未实现代码重载") end end) local debugger_stackInfo = nil @@ -21,27 +21,27 @@ local setfenv = setfenv if (not setfenv) then setfenv = function(fn, env) - local i = 1 - while true do - local name = debug.getupvalue(fn, i) - if name == "_ENV" then - debug.upvaluejoin( - fn, - i, - (function() - return env - end), - 1 - ) - break - elseif not name then - break - end - - i = i + 1 + local i = 1 + while true do + local name = debug.getupvalue(fn, i) + if name == "_ENV" then + debug.upvaluejoin( + fn, + i, + (function() + return env + end), + 1 + ) + break + elseif not name then + break end - return fn + + i = i + 1 end + return fn + end end local ZZBase64 = {} local LuaDebugTool_ = nil @@ -154,50 +154,50 @@ local function createSocket() sinkt["close-when-done"] = function(sock) - return base.setmetatable( - { - getfd = function() - return sock:getfd() - end, - dirty = function() - return sock:dirty() + return base.setmetatable( + { + getfd = function() + return sock:getfd() + end, + dirty = function() + return sock:dirty() + end + }, + { + __call = function(self, chunk, err) + if not chunk then + sock:close() + return 1 + else + return sock:send(chunk) end - }, - { - __call = function(self, chunk, err) - if not chunk then - sock:close() - return 1 - else - return sock:send(chunk) - end - end - } - ) - end + end + } + ) + end sinkt["keep-open"] = function(sock) - return base.setmetatable( - { - getfd = function() - return sock:getfd() - end, - dirty = function() - return sock:dirty() + return base.setmetatable( + { + getfd = function() + return sock:getfd() + end, + dirty = function() + return sock:dirty() + end + }, + { + __call = function(self, chunk, err) + if chunk then + return sock:send(chunk) + else + return 1 end - }, - { - __call = function(self, chunk, err) - if chunk then - return sock:send(chunk) - else - return 1 - end - end - } - ) - end + end + } + ) + end sinkt["default"] = sinkt["keep-open"] @@ -205,63 +205,63 @@ local function createSocket() sourcet["by-length"] = function(sock, length) - return base.setmetatable( - { - getfd = function() - return sock:getfd() - end, - dirty = function() - return sock:dirty() + return base.setmetatable( + { + getfd = function() + return sock:getfd() + end, + dirty = function() + return sock:dirty() + end + }, + { + __call = function() + if length <= 0 then + return nil end - }, - { - __call = function() - if length <= 0 then - return nil - end - local size = math.min(socket.BLOCKSIZE, length) - local chunk, err = sock:receive(size) - if err then - return nil, err - end - length = length - string.len(chunk) - return chunk + local size = math.min(socket.BLOCKSIZE, length) + local chunk, err = sock:receive(size) + if err then + return nil, err end - } - ) - end + length = length - string.len(chunk) + return chunk + end + } + ) + end sourcet["until-closed"] = function(sock) - local done - return base.setmetatable( - { - getfd = function() - return sock:getfd() - end, - dirty = function() - return sock:dirty() + local done + return base.setmetatable( + { + getfd = function() + return sock:getfd() + end, + dirty = function() + return sock:dirty() + end + }, + { + __call = function() + if done then + return nil end - }, - { - __call = function() - if done then - return nil - end - local chunk, err, partial = sock:receive(socket.BLOCKSIZE) - if not err then - return chunk - elseif err == "closed" then - sock:close() - done = 1 - return partial - else - return nil, err - end + local chunk, err, partial = sock:receive(socket.BLOCKSIZE) + if not err then + return chunk + elseif err == "closed" then + sock:close() + done = 1 + return partial + else + return nil, err end - } - ) - end + end + } + ) + end sourcet["default"] = sourcet["until-closed"] @@ -278,7 +278,7 @@ local function createJson() ----------------------------------------------------------------------------- -- Module declaration ----------------------------------------------------------------------------- - local json = {} -- Public namespace + local json = {} -- Public namespace local json_private = {} -- Private namespace -- Public constants @@ -392,7 +392,6 @@ local function createJson() function json.null() return json.null -- so json.null() will also return null ;-) end - ----------------------------------------------------------------------------- -- Internal, PRIVATE functions. -- Following a Python-like convention, I have prefixed all these 'PRIVATE' @@ -450,8 +449,8 @@ local function createJson() -- @return object, int The object (true, false or nil) and the position at which the next character should be -- scanned. function decode_scanConstant(s, startPos) - local consts = { ["true"] = true, ["false"] = false, ["null"] = nil } - local constNames = { "true", "false", "null" } + local consts = {["true"] = true, ["false"] = false, ["null"] = nil} + local constNames = {"true", "false", "null"} for i, k in pairs(constNames) do if string.sub(s, startPos, startPos + string.len(k) - 1) == k then @@ -600,7 +599,7 @@ local function createJson() assert( string.find(s, startChar, j + 1), "String decoding failed: missing closing " .. - startChar .. " at position " .. j .. "(for string at position " .. startPos .. ")" + startChar .. " at position " .. j .. "(for string at position " .. startPos .. ")" ) return table.concat(t, ""), j + 2 -- END SoniEx2 @@ -676,13 +675,13 @@ local function createJson() if v ~= (t.n or #t) then return false end -- False if n does not hold the number of elements - else -- Else of (k=='n') + else -- Else of (k=='n') if isEncodable(v) then return false end end -- End of (k~='n') - end -- End of k,v not an indexed pair - end -- End of loop across all pairs + end -- End of k,v not an indexed pair + end -- End of loop across all pairs return true, maxIndex end @@ -705,7 +704,7 @@ local breakInfoSocket = nil local json = createJson() local LuaDebugger = { fileMaps = {}, - Run = true, --表示正常运行只检测断点 + Run = true, --表示正常运行只检测断点 StepIn = false, StepInLevel = 0, StepNext = false, @@ -777,17 +776,17 @@ function print(...) end if (LuaDebugger.isProntToConsole == 1 or LuaDebugger.isProntToConsole == 2) then if (debug_server) then - local arg = { ... } --这里的...和{}符号中间需要有空格号,否则会出错 + local arg = {...} --这里的...和{}符号中间需要有空格号,否则会出错 local str = "" if (#arg == 0) then - arg = { "nil" } + arg = {"nil"} end for k, v in pairs(arg) do str = str .. tostring(v) .. "\t" end local sendMsg = { event = LuaDebugger.event.C2S_LuaPrint, - data = { msg = ZZBase64.encode(str), type = 1 } + data = {msg = ZZBase64.encode(str), type = 1} } local sendStr = json.encode(sendMsg) debug_server:send(sendStr .. "__debugger_k0204__") @@ -801,48 +800,46 @@ function luaIdePrintWarn(...) end if (LuaDebugger.isProntToConsole == 1 or LuaDebugger.isProntToConsole == 2) then if (debug_server) then - local arg = { ... } --这里的...和{}符号中间需要有空格号,否则会出错 + local arg = {...} --这里的...和{}符号中间需要有空格号,否则会出错 local str = "" if (#arg == 0) then - arg = { "nil" } + arg = {"nil"} end for k, v in pairs(arg) do str = str .. tostring(v) .. "\t" end local sendMsg = { event = LuaDebugger.event.C2S_LuaPrint, - data = { msg = ZZBase64.encode(str), type = 2 } + data = {msg = ZZBase64.encode(str), type = 2} } local sendStr = json.encode(sendMsg) debug_server:send(sendStr .. "__debugger_k0204__") end end end - function luaIdePrintErr(...) if (LuaDebugger.isProntToConsole == 1 or LuaDebugger.isProntToConsole == 3) then debugger_print(...) end if (LuaDebugger.isProntToConsole == 1 or LuaDebugger.isProntToConsole == 2) then if (debug_server) then - local arg = { ... } --这里的...和{}符号中间需要有空格号,否则会出错 + local arg = {...} --这里的...和{}符号中间需要有空格号,否则会出错 local str = "" if (#arg == 0) then - arg = { "nil" } + arg = {"nil"} end for k, v in pairs(arg) do str = str .. tostring(v) .. "\t" end local sendMsg = { event = LuaDebugger.event.C2S_LuaPrint, - data = { msg = ZZBase64.encode(str), type = 3 } + data = {msg = ZZBase64.encode(str), type = 3} } local sendStr = json.encode(sendMsg) debug_server:send(sendStr .. "__debugger_k0204__") end end end - --@endregion --@region 辅助方法 @@ -879,7 +876,7 @@ local function debugger_getFilePathInfo(file) file = file:gsub("/.\\", "/") file = file:gsub("\\", "/") file = file:gsub("//", "/") - + if file:find("@") == 1 then file = file:sub(2) @@ -980,7 +977,7 @@ local function debugger_dump(value, desciption, nesting) return tostring(v) end local traceback = debugger_strSplit(debug.traceback("", 2), "\n") - -- print("dump from: " .. debugger_strTrim(traceback[3])) + print("dump from: " .. debugger_strTrim(traceback[3])) local function _dump(value, desciption, indent, nest, keylen) desciption = desciption or "" local spc = "" @@ -1029,28 +1026,30 @@ local function debugger_dump(value, desciption, nesting) end _dump(value, desciption, "- ", 1) for i, line in ipairs(result) do - -- print(line) + print(line) end end --@endregion local function debugger_valueToString(v) - local vtype = type(v) + local vtype = type(v) local vstr = nil if (vtype == "userdata") then if (LuaDebugger.isFoxGloryProject) then - return "userdata", vtype + + return "userdata",vtype + else return tostring(v), vtype end elseif (vtype == "table" or vtype == "function" or vtype == "boolean") then local value = vtype - xpcall(function() + xpcall(function() value = tostring(v) - end, function() + end,function() value = vtype end) return value, vtype - elseif (vtype == "number" or vtype == "string") then + elseif (vtype == "number" or vtype == "string" ) then return v, vtype else return tostring(v), vtype @@ -1058,12 +1057,12 @@ local function debugger_valueToString(v) end local function debugger_setVarInfo(name, value) local valueStr, valueType = debugger_valueToString(value) - local nameStr, nameType = debugger_valueToString(name) - if (valueStr == nil) then + local nameStr,nameType = debugger_valueToString(name) + if(valueStr == nil) then valueStr = valueType end local valueInfo = { - name = nameStr, + name =nameStr, valueType = valueType, valueStr = ZZBase64.encode(valueStr) } @@ -1101,64 +1100,64 @@ local function debugger_getvalue(f) i = i + 1 end - return { locals = locals, ups = ups } + return {locals = locals, ups = ups} end --获取堆栈 debugger_stackInfo = function(ignoreCount, event) - local datas = {} - local stack = {} - local varInfos = {} - local funcs = {} - local index = 0 - for i = ignoreCount, 100 do - local source = getinfo(i) - local isadd = true - if (i == ignoreCount) then - local file = source.source - if (file:find(LuaDebugger.DebugLuaFie)) then - return - end - if (file == "=[C]") then - isadd = false - end + local datas = {} + local stack = {} + local varInfos = {} + local funcs = {} + local index = 0 + for i = ignoreCount, 100 do + local source = getinfo(i) + local isadd = true + if (i == ignoreCount) then + local file = source.source + if (file:find(LuaDebugger.DebugLuaFie)) then + return end - if not source then - break - end - if (isadd) then - local fullName, dir, fileName = debugger_getFilePathInfo(source.source) - local info = { - src = fullName, - scoreName = source.name, - currentline = source.currentline, - linedefined = source.linedefined, - what = source.what, - nameWhat = source.namewhat - } - index = i - local vars = debugger_getvalue(i + 1) - table.insert(stack, info) - table.insert(varInfos, vars) - table.insert(funcs, source.func) - end - if source.what == "main" then - break + if (file == "=[C]") then + isadd = false end end - - local stackInfo = { stack = stack, vars = varInfos, funcs = funcs } - local data = { - stack = stackInfo.stack, - vars = stackInfo.vars, - funcs = stackInfo.funcs, - event = event, - funcsLength = #stackInfo.funcs, - upFunc = getinfo(ignoreCount - 3, "f").func - } - LuaDebugger.currentTempFunc = data.funcs[1] - return data - end + if not source then + break + end + if (isadd) then + local fullName, dir, fileName = debugger_getFilePathInfo(source.source) + local info = { + src = fullName, + scoreName = source.name, + currentline = source.currentline, + linedefined = source.linedefined, + what = source.what, + nameWhat = source.namewhat + } + index = i + local vars = debugger_getvalue(i + 1) + table.insert(stack, info) + table.insert(varInfos, vars) + table.insert(funcs, source.func) + end + if source.what == "main" then + break + end + end + + local stackInfo = {stack = stack, vars = varInfos, funcs = funcs} + local data = { + stack = stackInfo.stack, + vars = stackInfo.vars, + funcs = stackInfo.funcs, + event = event, + funcsLength = #stackInfo.funcs, + upFunc = getinfo(ignoreCount - 3, "f").func + } + LuaDebugger.currentTempFunc = data.funcs[1] + return data +end --===========================点断信息================================================== --根据不同的游戏引擎进行定时获取断点信息 @@ -1168,37 +1167,37 @@ local function debugger_receiveDebugBreakInfo() if (jit) then if (LuaDebugger.debugLuaType ~= "jit") then local msg = "当前luajit版本为: " .. jit.version .. " 请使用LuaDebugjit 进行调试!" - -- print(msg) + print(msg) end end if (breakInfoSocket) then local msg, status = breakInfoSocket:receive() - if (LuaDebugger.isLaunch and status == "closed") then - os.exit() + if(LuaDebugger.isLaunch and status == "closed") then + os.exit() end if (msg) then local netData = json.decode(msg) if netData.event == LuaDebugger.event.S2C_SetBreakPoints then debugger_setBreak(netData.data) elseif netData.event == LuaDebugger.event.S2C_LoadLuaScript then - LuaDebugger.loadScriptBody = netData.data + LuaDebugger.loadScriptBody = netData.data debugger_exeLuaString() - debugger_sendMsg(breakInfoSocket, LuaDebugger.event.C2S_LoadLuaScript, LuaDebugger.loadScriptBody) + debugger_sendMsg(breakInfoSocket,LuaDebugger.event.C2S_LoadLuaScript,LuaDebugger.loadScriptBody) elseif netData.event == LuaDebugger.event.S2C_ReLoadFile then LuaDebugger.reLoadFileBody = netData.data LuaDebugger.isReLoadFile = false - LuaDebugger.reLoadFileBody.isReLoad = debugger_reLoadFile(LuaDebugger.reLoadFileBody) - -- print("重载结果:",LuaDebugger.reLoadFileBody.isReLoad) + LuaDebugger.reLoadFileBody.isReLoad = debugger_reLoadFile(LuaDebugger.reLoadFileBody) + print("重载结果:",LuaDebugger.reLoadFileBody.isReLoad) LuaDebugger.reLoadFileBody.script = nil debugger_sendMsg( breakInfoSocket, LuaDebugger.event.C2S_ReLoadFile, { stack = LuaDebugger.reLoadFileBody - + } - ) - end + ) + end end end end @@ -1222,76 +1221,76 @@ local function splitFilePath(path) end debugger_setBreak = function(datas) - local breakInfos = LuaDebugger.breakInfos - for i, data in ipairs(datas) do - data.fileName = string.lower(data.fileName) - data.serverPath = string.lower(data.serverPath) - local breakInfo = breakInfos[data.fileName] - if (not breakInfo) then - breakInfos[data.fileName] = {} - breakInfo = breakInfos[data.fileName] - end - if (not data.breakDatas or #data.breakDatas == 0) then - breakInfo[data.serverPath] = nil - else - local fileBreakInfo = breakInfo[data.serverPath] - if (not fileBreakInfo) then - fileBreakInfo = { - pathNames = splitFilePath(data.serverPath), - --命中次數判斷計數器 - hitCounts = {} - } - breakInfo[data.serverPath] = fileBreakInfo - end - local lineInfos = {} - for li, breakData in ipairs(data.breakDatas) do - lineInfos[breakData.line] = breakData - if (breakData.hitCondition and breakData.hitCondition ~= "") then - breakData.hitCondition = tonumber(breakData.hitCondition) - else - breakData.hitCondition = 0 - end - if (not fileBreakInfo.hitCounts[breakData.line]) then - fileBreakInfo.hitCounts[breakData.line] = 0 - end - end - fileBreakInfo.lines = lineInfos - --這裡添加命中次數判斷 - for line, count in pairs(fileBreakInfo.hitCounts) do - if (not lineInfos[line]) then - fileBreakInfo.hitCounts[line] = nil - end - end - end - local count = 0 - for i, linesInfo in pairs(breakInfo) do - count = count + 1 - end - if (count == 0) then - breakInfos[data.fileName] = nil - end + local breakInfos = LuaDebugger.breakInfos + for i, data in ipairs(datas) do + data.fileName = string.lower(data.fileName) + data.serverPath = string.lower(data.serverPath) + local breakInfo = breakInfos[data.fileName] + if (not breakInfo) then + breakInfos[data.fileName] = {} + breakInfo = breakInfos[data.fileName] end - --debugger_dump(breakInfos, "breakInfos", 6) - --检查是否需要断点 - local isHook = false - for k, v in pairs(breakInfos) do - isHook = true - break - end - - --这样做的原因是为了最大限度的使手机调试更加流畅 注意这里会连续的进行n次 - if (isHook) then - if (not LuaDebugger.isHook) then - debug.sethook(debug_hook, "lrc") - end - LuaDebugger.isHook = true + if (not data.breakDatas or #data.breakDatas == 0) then + breakInfo[data.serverPath] = nil else - if (LuaDebugger.isHook) then - debug.sethook() + local fileBreakInfo = breakInfo[data.serverPath] + if (not fileBreakInfo) then + fileBreakInfo = { + pathNames = splitFilePath(data.serverPath), + --命中次數判斷計數器 + hitCounts = {} + } + breakInfo[data.serverPath] = fileBreakInfo end - LuaDebugger.isHook = false + local lineInfos = {} + for li, breakData in ipairs(data.breakDatas) do + lineInfos[breakData.line] = breakData + if (breakData.hitCondition and breakData.hitCondition ~= "") then + breakData.hitCondition = tonumber(breakData.hitCondition) + else + breakData.hitCondition = 0 + end + if (not fileBreakInfo.hitCounts[breakData.line]) then + fileBreakInfo.hitCounts[breakData.line] = 0 + end + end + fileBreakInfo.lines = lineInfos + --這裡添加命中次數判斷 + for line, count in pairs(fileBreakInfo.hitCounts) do + if (not lineInfos[line]) then + fileBreakInfo.hitCounts[line] = nil + end + end + end + local count = 0 + for i, linesInfo in pairs(breakInfo) do + count = count + 1 + end + if (count == 0) then + breakInfos[data.fileName] = nil end end + --debugger_dump(breakInfos, "breakInfos", 6) + --检查是否需要断点 + local isHook = false + for k, v in pairs(breakInfos) do + isHook = true + break + end + + --这样做的原因是为了最大限度的使手机调试更加流畅 注意这里会连续的进行n次 + if (isHook) then + if (not LuaDebugger.isHook) then + debug.sethook(debug_hook, "lrc") + end + LuaDebugger.isHook = true + else + if (LuaDebugger.isHook) then + debug.sethook() + end + LuaDebugger.isHook = false + end +end local function debugger_checkFileIsBreak(fileName) return LuaDebugger.breakInfos[fileName] end @@ -1323,30 +1322,31 @@ function debugger_conditionStr(condition, vars, callBack) currentTabble[k] = v end end - setmetatable(currentTabble, { __index = _G }) + setmetatable(currentTabble, {__index = _G}) local fun = loadstring("return " .. condition) setfenv(fun, currentTabble) return fun() end local status, - msg = + msg = xpcall( - loadScript, - function(error) - -- print(error) - end - ) + loadScript, + function(error) + print(error) + end + ) if (status and msg) then callBack() end end - --执行lua字符串 debugger_exeLuaString = function() + local function loadScript() + local script = LuaDebugger.loadScriptBody.script if (LuaDebugger.loadScriptBody.isBreak) then - local currentTabble = { _G = _G } + local currentTabble = {_G = _G} local frameId = LuaDebugger.loadScriptBody.frameId frameId = frameId local func = LuaDebugger.currentDebuggerData.funcs[frameId] @@ -1359,8 +1359,8 @@ debugger_exeLuaString = function() for k, v in pairs(locals) do currentTabble[k] = v end - setmetatable(currentTabble, { __index = _G }) - + setmetatable(currentTabble, {__index = _G}) + local fun = loadstring(script) setfenv(fun, currentTabble) fun() @@ -1370,51 +1370,54 @@ debugger_exeLuaString = function() end end local status, - msg = + msg = xpcall( - loadScript, - function(error) - -- debugger_sendMsg(debug_server, LuaDebugger.event.C2S_LoadLuaScript, LuaDebugger.loadScriptBody) - end - ) - LuaDebugger.loadScriptBody.script = nil + loadScript, + function(error) + + -- debugger_sendMsg(debug_server, LuaDebugger.event.C2S_LoadLuaScript, LuaDebugger.loadScriptBody) + end + ) + LuaDebugger.loadScriptBody.script = nil if (LuaDebugger.loadScriptBody.isBreak) then - LuaDebugger.serVarLevel = LuaDebugger.serVarLevel + 1 - LuaDebugger.currentDebuggerData = debugger_stackInfo(LuaDebugger.serVarLevel, LuaDebugger.event - .C2S_HITBreakPoint) - LuaDebugger.loadScriptBody.stack = LuaDebugger.currentDebuggerData.stack - end + LuaDebugger.serVarLevel = LuaDebugger.serVarLevel+1 + LuaDebugger.currentDebuggerData = debugger_stackInfo(LuaDebugger.serVarLevel, LuaDebugger.event.C2S_HITBreakPoint) + LuaDebugger.loadScriptBody.stack = LuaDebugger.currentDebuggerData.stack + end LuaDebugger.loadScriptBody.complete = true + end --@region 调试中修改变量值 --根据key 值在 value 查找 -local function debugger_getTablekey(key, keyType, value) - if (keyType == -1) then +local function debugger_getTablekey(key,keyType,value) + if(keyType == -1) then return key - elseif (keyType == 1) then + elseif(keyType == 1) then return tonumber(key) - elseif (keyType == 2) then + elseif(keyType == 2) then local valueKey = nil - for k, v in pairs(value) do + for k,v in pairs(value) do local nameType = type(k) - if (nameType == "userdata" or nameType == "table") then + if(nameType == "userdata" or nameType == "table") then if (not LuaDebugger.isFoxGloryProject) then valueKey = tostring(k) - if (key == valueKey) then + if(key == valueKey) then return k end break end end end + end end local function debugger_setVarValue(server, data) + local newValue = nil - local level = LuaDebugger.serVarLevel + LuaDebugger.setVarBody.frameId + local level = LuaDebugger.serVarLevel+LuaDebugger.setVarBody.frameId local firstKeyName = data.keys[1] --@region vars check local localValueChangeIndex = -1 @@ -1429,7 +1432,7 @@ local function debugger_setVarValue(server, data) if not name then break end - if (firstKeyName == name) then + if(firstKeyName == name) then localValueChangeIndex = i oldValue = value end @@ -1443,11 +1446,11 @@ local function debugger_setVarValue(server, data) local ups = {} while func do -- check for func as it may be nil for tail calls local name, value = debug.getupvalue(func, i) - + if not name then break end - if (localValueChangeIndex == -1 and firstKeyName == name) then + if(localValueChangeIndex == -1 and firstKeyName == name) then upValueFun = func oldValue = value upValueChangeIndex = i @@ -1459,9 +1462,9 @@ local function debugger_setVarValue(server, data) end i = i + 1 end - --@endregion - local vars = { locals = locals, ups = ups } - +--@endregion + local vars = {locals = locals, ups = ups} + local function loadScript() local currentTabble = {} local locals = vars.locals @@ -1477,56 +1480,58 @@ local function debugger_setVarValue(server, data) currentTabble[k] = v end end - setmetatable(currentTabble, { __index = _G }) + setmetatable(currentTabble, {__index = _G}) local fun = loadstring("return " .. data.value) setfenv(fun, currentTabble) newValue = fun() end local status, - msg = + msg = xpcall( - loadScript, - function(error) - -- print(error, "============================") - end - ) - + loadScript, + function(error) + print(error, "============================") + end + ) + local i = 1 - + -- local 查找并替换 local keyLength = #data.keys - - if (keyLength == 1) then - if (localValueChangeIndex ~= -1) then + + if(keyLength == 1) then + if(localValueChangeIndex ~= -1) then + debug.setlocal(level, localValueChangeIndex, newValue) - elseif (upValueFun ~= nil) then - debug.setupvalue(upValueFun, upValueChangeIndex, newValue) + elseif(upValueFun ~= nil) then + debug.setupvalue( upValueFun, upValueChangeIndex, newValue ) else --全局变量查找 - if (_G[firstKeyName]) then + if(_G[firstKeyName]) then _G[firstKeyName] = newValue end end else - if (not oldValue) then - if (_G[firstKeyName]) then + if(not oldValue) then + if(_G[firstKeyName]) then oldValue = _G[firstKeyName] end end local tempValue = oldValue - for i = 2, keyLength - 1 do - if (tempValue) then - oldValue = oldValue[debugger_getTablekey(data.keys[i], data.numberTypes[i], oldValue)] + for i=2,keyLength-1 do + if(tempValue) then + oldValue = oldValue[debugger_getTablekey(data.keys[i],data.numberTypes[i],oldValue)] end end - if (tempValue) then - oldValue[debugger_getTablekey(data.keys[keyLength], data.numberTypes[keyLength], oldValue)] = newValue + if(tempValue) then + oldValue[debugger_getTablekey(data.keys[keyLength],data.numberTypes[keyLength],oldValue)] = newValue end end - local varInfo = debugger_setVarInfo(data.varName, newValue) + local varInfo = debugger_setVarInfo(data.varName, newValue) data.varInfo = varInfo - LuaDebugger.serVarLevel = LuaDebugger.serVarLevel + 1 + LuaDebugger.serVarLevel = LuaDebugger.serVarLevel+1 LuaDebugger.currentDebuggerData = debugger_stackInfo(LuaDebugger.serVarLevel, LuaDebugger.event.C2S_HITBreakPoint) + end --@endregion @@ -1536,44 +1541,44 @@ end --调试修改变量值统一的 _resume checkSetVar = function() - if (LuaDebugger.isSetVar) then - LuaDebugger.isSetVar = false - debugger_setVarValue(debug_server, LuaDebugger.setVarBody) - LuaDebugger.serVarLevel = LuaDebugger.serVarLevel + 1 - _resume(coro_debugger, LuaDebugger.setVarBody) - xpcall( - checkSetVar, - function(error) - -- print("设置变量", error) - end - ) - elseif (LuaDebugger.isLoadLuaScript) then - LuaDebugger.isLoadLuaScript = false - debugger_exeLuaString() - LuaDebugger.serVarLevel = LuaDebugger.serVarLevel + 1 - _resume(coro_debugger, LuaDebugger.reLoadFileBody) - xpcall( - checkSetVar, - function(error) - -- print("执行代码", error) - end - ) - elseif (LuaDebugger.isReLoadFile) then - LuaDebugger.isReLoadFile = false - LuaDebugger.reLoadFileBody.isReLoad = debugger_reLoadFile(LuaDebugger.reLoadFileBody) - -- print("重载结果:",LuaDebugger.reLoadFileBody.isReLoad) - LuaDebugger.reLoadFileBody.script = nil - LuaDebugger.serVarLevel = LuaDebugger.serVarLevel + 1 - _resume(coro_debugger, LuaDebugger.reLoadFileBody) - xpcall( - checkSetVar, - function(error) - -- print("重新加载文件", error) - end - ) - end + if (LuaDebugger.isSetVar) then + LuaDebugger.isSetVar = false + debugger_setVarValue(debug_server,LuaDebugger.setVarBody) + LuaDebugger.serVarLevel = LuaDebugger.serVarLevel+1 + _resume(coro_debugger, LuaDebugger.setVarBody) + xpcall( + checkSetVar, + function(error) + print("设置变量", error) + end + ) + elseif(LuaDebugger.isLoadLuaScript) then + LuaDebugger.isLoadLuaScript = false + debugger_exeLuaString() + LuaDebugger.serVarLevel = LuaDebugger.serVarLevel+1 + _resume(coro_debugger, LuaDebugger.reLoadFileBody) + xpcall( + checkSetVar, + function(error) + print("执行代码", error) + end + ) + elseif(LuaDebugger.isReLoadFile) then + LuaDebugger.isReLoadFile = false + LuaDebugger.reLoadFileBody.isReLoad = debugger_reLoadFile(LuaDebugger.reLoadFileBody) + print("重载结果:",LuaDebugger.reLoadFileBody.isReLoad) + LuaDebugger.reLoadFileBody.script = nil + LuaDebugger.serVarLevel = LuaDebugger.serVarLevel+1 + _resume(coro_debugger, LuaDebugger.reLoadFileBody) + xpcall( + checkSetVar, + function(error) + print("重新加载文件", error) + end + ) end - +end + local function getSource(source) @@ -1593,7 +1598,7 @@ local function debugger_GeVarInfoBytUserData(server, var) local fileds = LuaDebugTool.getUserDataInfo(var) local varInfos = {} - + --c# vars for i = 1, fileds.Count do @@ -1614,18 +1619,18 @@ end local function debugger_getValueByScript(value, script) local val = nil local status, - msg = + msg = xpcall( - function() - local fun = loadstring("return " .. script) - setfenv(fun, value) - val = fun() - end, - function(error) - -- print(error, "====>") - val = nil - end - ) + function() + local fun = loadstring("return " .. script) + setfenv(fun, value) + val = fun() + end, + function(error) + print(error, "====>") + val = nil + end + ) return val end @@ -1730,7 +1735,7 @@ end local function debugger_searchVarByKeys(value, keys, searckKeys) local index, val = debugger_getVarByKeys(value, searckKeys, 1) - if (not LuaDebugTool or not LuaDebugTool.getCSharpValue or type(LuaDebugTool.getCSharpValue) ~= "function") then + if (not LuaDebugTool or not LuaDebugTool.getCSharpValue or type(LuaDebugTool.getCSharpValue) ~= "function") then return index, val end if (val) then @@ -1858,9 +1863,9 @@ local function debugger_sendTableValues(value, server, variablesReference, debug if (valueType == "userdata") then m = getmetatable(value) - + vinfos = debugger_sendTableField(value, vinfos, server, variablesReference, debugSpeedIndex, valueType) - + if (LuaDebugTool) then local varInfos = debugger_GeVarInfoBytUserData(server, value, variablesReference, debugSpeedIndex) @@ -1889,6 +1894,7 @@ local function debugger_sendTableValues(value, server, variablesReference, debug vinfos = {} end end + end else m = getmetatable(value) @@ -1938,6 +1944,7 @@ local function debugger_getBreakVar(body, server) if (value) then local valueType = type(value) if (valueType == "table" or valueType == "userdata") then + debugger_sendTableValues(value, server, variablesReference, debugSpeedIndex) else if (valueType == "function") then @@ -1972,9 +1979,9 @@ local function debugger_getBreakVar(body, server) xpcall( exe, function(error) - -- -- print("获取变量错误 错误消息-----------------") - -- -- print(error) - -- -- print(debug.traceback("", 2)) + -- print("获取变量错误 错误消息-----------------") + -- print(error) + -- print(debug.traceback("", 2)) debugger_sendMsg( server, LuaDebugger.event.C2S_ReqVar, @@ -2011,24 +2018,25 @@ local function debugger_loop(server) while true do local line, status = server:receive() if (status == "closed") then - if (LuaDebugger.isLaunch) then - os.exit() - else - debug.sethook() - coroutine.yield() - end + if(LuaDebugger.isLaunch) then + os.exit() + else + debug.sethook() + coroutine.yield() + end end if (line) then local netData = json.decode(line) local event = netData.event local body = netData.data if (event == LuaDebugger.event.S2C_DebugClose) then - if (LuaDebugger.isLaunch) then - os.exit() - else - debug.sethook() - coroutine.yield() - end + if(LuaDebugger.isLaunch) then + os.exit() + else + debug.sethook() + coroutine.yield() + end + elseif event == LuaDebugger.event.S2C_SetBreakPoints then --设置断点信息 local function setB() @@ -2037,7 +2045,7 @@ local function debugger_loop(server) xpcall( setB, function(error) - -- print(error) + print(error) end ) elseif event == LuaDebugger.event.S2C_RUN then --开始运行 @@ -2129,8 +2137,8 @@ local function debugger_loop(server) stack = data, eventType = data.eventType } - ) - elseif event == LuaDebugger.event.S2C_ReLoadFile then + ) + elseif event == LuaDebugger.event.S2C_ReLoadFile then LuaDebugger.isReLoadFile = true LuaDebugger.reLoadFileBody = body local data = coroutine.yield() @@ -2148,26 +2156,29 @@ local function debugger_loop(server) end coro_debugger = coroutine.create(debugger_loop) debug_hook = function(event, line) - if (not LuaDebugger.isHook) then + + if(not LuaDebugger.isHook) then return end - - if (LuaDebugger.Run) then - if (event == "line") then + + if(LuaDebugger.Run) then + if(event == "line") then local isCheck = false for k, breakInfo in pairs(LuaDebugger.breakInfos) do + for bk, linesInfo in pairs(breakInfo) do - if (linesInfo.lines and linesInfo.lines[line]) then + + if(linesInfo.lines and linesInfo.lines[line]) then isCheck = true break end end - if (isCheck) then - break - end + if(isCheck) then + break + end end - if (not isCheck) then + if(not isCheck) then return end else @@ -2189,8 +2200,8 @@ debug_hook = function(event, line) else if (LuaDebugger.currentDebuggerData.funcs[2] == tempFun) then local data = debugger_stackInfo(3, LuaDebugger.event.C2S_StepInResponse) - --挂起等待调试器作出反应 - + --挂起等待调试器作出反应 + _resume(coro_debugger, data) checkSetVar() end @@ -2198,7 +2209,7 @@ debug_hook = function(event, line) return end -- debugger_dump(LuaDebugger,"LuaDebugger") - -- -- print(LuaDebugger.StepNextLevel,"LuaDebugger.StepNextLevel") + -- print(LuaDebugger.StepNextLevel,"LuaDebugger.StepNextLevel") local file = nil if (event == "call") then -- end @@ -2206,7 +2217,7 @@ debug_hook = function(event, line) if (not LuaDebugger.Run) then LuaDebugger.StepNextLevel = LuaDebugger.StepNextLevel + 1 end - -- -- print("stepIn",LuaDebugger.StepNextLevel) + -- print("stepIn",LuaDebugger.StepNextLevel) local stepInfo = getinfo(2, "S") local source = stepInfo.source @@ -2243,11 +2254,12 @@ debug_hook = function(event, line) LuaDebugger.currentFileName = file end file = LuaDebugger.currentFileName - + --判断断点 local breakInfo = LuaDebugger.breakInfos[file] local breakData = nil if (breakInfo) then + local ischeck = false for k, lineInfo in pairs(breakInfo) do local lines = lineInfo.lines @@ -2256,7 +2268,7 @@ debug_hook = function(event, line) break end end - + if (ischeck) then --并且在断点中 local info = stepInfo @@ -2264,7 +2276,7 @@ debug_hook = function(event, line) info = getinfo(2) end local hitPathNames = splitFilePath(LuaDebugger.currentLineFile) - + local hitCounts = {} local debugHitCounts = nil for k, lineInfo in pairs(breakInfo) do @@ -2276,7 +2288,7 @@ debug_hook = function(event, line) --判断路径 hitCounts[k] = 0 local hitPathNamesCount = #hitPathNames - + local pathNamesCount = #pathNames local checkCount = 0; while (true) do @@ -2287,13 +2299,13 @@ debug_hook = function(event, line) end pathNamesCount = pathNamesCount - 1 hitPathNamesCount = hitPathNamesCount - 1 - checkCount = checkCount + 1 - + checkCount = checkCount+1 + if (pathNamesCount <= 0 or hitPathNamesCount <= 0) then break end end - if (checkCount > 0) then + if(checkCount>0) then break; end else @@ -2342,8 +2354,8 @@ debug_hook = function(event, line) local data = debugger_stackInfo(3, LuaDebugger.event.C2S_NextResponse) -- 挂起等待调试器作出反应 if (data) then - LuaDebugger.currentTempFunc = data.funcs[1] - + LuaDebugger.currentTempFunc = data.funcs[1] + _resume(coro_debugger, data) checkSetVar() return @@ -2372,8 +2384,8 @@ end local function debugger_xpcall() --调用 coro_debugger 并传入 参数 local data = debugger_stackInfo(4, LuaDebugger.event.C2S_HITBreakPoint) - if (data.stack and data.stack[1]) then - data.stack[1].isXpCall = true + if(data.stack and data.stack[1]) then + data.stack[1].isXpCall = true end --挂起等待调试器作出反应 _resume(coro_debugger, data) @@ -2384,8 +2396,8 @@ local function start() local fullName, dirName, fileName = debugger_getFilePathInfo(getinfo(1).source) LuaDebugger.DebugLuaFie = fileName local socket = createSocket() - -- print(controller_host) - -- print(controller_port) + print(controller_host) + print(controller_port) local server = socket.connect(controller_host, controller_port) debug_server = server @@ -2415,33 +2427,33 @@ local function start() debug.sethook(debug_hook, "lrc") end, function(error) - -- print("error:", error) + print("error:", error) end ) if (jit) then if (LuaDebugger.debugLuaType ~= "jit") then - -- print("error======================================================") + print("error======================================================") local msg = "当前luajit版本为: " .. jit.version .. " 请使用LuaDebugjit 进行调试!" - -- print(msg) + print(msg) end end - _resume(coro_debugger, server) + _resume(coro_debugger, server) end end end function StartDebug(host, port) if (not host) then - -- print("error host nil") + print("error host nil") end if (not port) then - -- print("error prot nil") + print("error prot nil") end if (type(host) ~= "string") then - -- print("error host not string") + print("error host not string") end if (type(port) ~= "number") then - -- print("error host not number") + print("error host not number") end controller_host = host controller_port = port @@ -2449,7 +2461,7 @@ function StartDebug(host, port) start, function(error) -- body - -- print(error) + print(error) end ) return debugger_receiveDebugBreakInfo, debugger_xpcall @@ -2466,25 +2478,25 @@ ZZBase64.__code = { 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/', }; ZZBase64.__decode = {} -for k, v in pairs(ZZBase64.__code) do - ZZBase64.__decode[string.byte(v, 1)] = k - 1 +for k,v in pairs(ZZBase64.__code) do + ZZBase64.__decode[string.byte(v,1)] = k - 1 end function ZZBase64.encode(text) - local len = string.len(text) - local left = len % 3 - len = len - left - local res = {} - local index = 1 + local len = string.len(text) + local left = len % 3 + len = len - left + local res = {} + local index = 1 for i = 1, len, 3 do - local a = string.byte(text, i) + local a = string.byte(text, i ) local b = string.byte(text, i + 1) local c = string.byte(text, i + 2) -- num = a<<16 + b<<8 + c local num = a * 65536 + b * 256 + c for j = 1, 4 do --tmp = num >> ((4 -j) * 6) - local tmp = math.floor(num / (2 ^ ((4 - j) * 6))) + local tmp = math.floor(num / (2 ^ ((4-j) * 6))) --curPos = tmp&0x3f local curPos = tmp % 64 + 1 res[index] = ZZBase64.__code[curPos] @@ -2504,7 +2516,7 @@ function ZZBase64.__left2(res, index, text, len) local num1 = string.byte(text, len + 1) num1 = num1 * 1024 --lshift 10 local num2 = string.byte(text, len + 2) - num2 = num2 * 4 --lshift 2 + num2 = num2 * 4 --lshift 2 local num = num1 + num2 local tmp1 = math.floor(num / 4096) --rShift 12 @@ -2521,13 +2533,13 @@ function ZZBase64.__left2(res, index, text, len) res[index + 3] = "=" end -function ZZBase64.__left1(res, index, text, len) +function ZZBase64.__left1(res, index,text, len) local num = string.byte(text, len + 1) num = num * 16 local tmp = math.floor(num / 64) local curPos = tmp % 64 + 1 - res[index] = ZZBase64.__code[curPos] + res[index ] = ZZBase64.__code[curPos] curPos = num % 64 + 1 res[index + 1] = ZZBase64.__code[curPos] @@ -2550,11 +2562,11 @@ function ZZBase64.decode(text) local res = {} local index = 1 local decode = ZZBase64.__decode - for i = 1, len, 4 do - local a = decode[string.byte(text, i)] - local b = decode[string.byte(text, i + 1)] - local c = decode[string.byte(text, i + 2)] - local d = decode[string.byte(text, i + 3)] + for i =1, len, 4 do + local a = decode[string.byte(text,i )] + local b = decode[string.byte(text,i + 1)] + local c = decode[string.byte(text,i + 2)] + local d = decode[string.byte(text,i + 3)] --num = a<<18 + b<<12 + c<<6 + d local num = a * 262144 + b * 4096 + c * 64 + d @@ -2563,7 +2575,7 @@ function ZZBase64.decode(text) num = math.floor(num / 256) local f = string.char(num % 256) num = math.floor(num / 256) - res[index] = string.char(num % 256) + res[index ] = string.char(num % 256) res[index + 1] = f res[index + 2] = e index = index + 3 @@ -2599,4 +2611,7 @@ function ZZBase64.__decodeLeft2(res, index, text, len) res[index] = string.char(num) end + + + return StartDebug diff --git a/lua_probject/base_project/debug/LuaDebugjit.lua b/lua_probject/base_project/debug/LuaDebugjit.lua index c5a8613b..6ba9f888 100644 --- a/lua_probject/base_project/debug/LuaDebugjit.lua +++ b/lua_probject/base_project/debug/LuaDebugjit.lua @@ -1,7 +1,7 @@ -local debugger_reLoadFile = nil -xpcall(function() +local debugger_reLoadFile =nil +xpcall(function() debugger_reLoadFile = require("luaideReLoadFile") -end, function() +end,function() debugger_reLoadFile = function() print("未实现代码重载") end end) local sethook = debug.sethook @@ -13,165 +13,165 @@ local checkSetVar = nil local loadstring_ = nil local debugger_sendMsg = nil if (loadstring) then - loadstring_ = loadstring +loadstring_ = loadstring else - loadstring_ = load +loadstring_ = load end local ZZBase64 = {} local LuaDebugTool_ = nil if (LuaDebugTool) then - LuaDebugTool_ = LuaDebugTool + LuaDebugTool_ = LuaDebugTool elseif (CS and CS.LuaDebugTool) then - LuaDebugTool_ = CS.LuaDebugTool + LuaDebugTool_ = CS.LuaDebugTool end local LuaDebugTool = LuaDebugTool_ local loadstring = loadstring_ local getinfo = debug.getinfo local function createSocket() - local base = _G - local string = require("string") - local math = require("math") - local socket = require("socket.core") + local base = _G + local string = require("string") + local math = require("math") + local socket = require("socket.core") + + local _M = socket + + ----------------------------------------------------------------------------- + -- Exported auxiliar functions + ----------------------------------------------------------------------------- + function _M.connect4(address, port, laddress, lport) + return socket.connect(address, port, laddress, lport, "inet") + end + + function _M.connect6(address, port, laddress, lport) + return socket.connect(address, port, laddress, lport, "inet6") + end - local _M = socket - - ----------------------------------------------------------------------------- - -- Exported auxiliar functions - ----------------------------------------------------------------------------- - function _M.connect4(address, port, laddress, lport) - return socket.connect(address, port, laddress, lport, "inet") - end - - function _M.connect6(address, port, laddress, lport) - return socket.connect(address, port, laddress, lport, "inet6") - end - - if (not _M.connect) then - function _M.connect(address, port, laddress, lport) - local sock, err = socket.tcp() - if not sock then + if (not _M.connect) then + function _M.connect(address, port, laddress, lport) + local sock, err = socket.tcp() + if not sock then return nil, err - end - if laddress then - local res, err = sock:bind(laddress, lport, -1) - if not res then + end + if laddress then + local res, err = sock:bind(laddress, lport, -1) + if not res then return nil, err end - end - local res, err = sock:connect(address, port) - if not res then + end + local res, err = sock:connect(address, port) + if not res then return nil, err end - return sock - end - end - function _M.bind(host, port, backlog) - if host == "*" then + return sock + end + end + function _M.bind(host, port, backlog) + if host == "*" then host = "0.0.0.0" end local addrinfo, err = socket.dns.getaddrinfo(host) if not addrinfo then return nil, err end - local sock, res - err = "no info on address" - for i, alt in base.ipairs(addrinfo) do - if alt.family == "inet" then - sock, err = socket.tcp4() - else - sock, err = socket.tcp6() - end - if not sock then + local sock, res + err = "no info on address" + for i, alt in base.ipairs(addrinfo) do + if alt.family == "inet" then + sock, err = socket.tcp4() + else + sock, err = socket.tcp6() + end + if not sock then return nil, err end - sock:setoption("reuseaddr", true) - res, err = sock:bind(alt.addr, port) - if not res then - sock:close() - else - res, err = sock:listen(backlog) - if not res then - sock:close() - else - return sock - end - end - end - return nil, err - end - - _M.try = _M.newtry() - - function _M.choose(table) - return function(name, opt1, opt2) - if base.type(name) ~= "string" then - name, opt1, opt2 = "default", name, opt1 - end - local f = table[name or "nil"] - if not f then + sock:setoption("reuseaddr", true) + res, err = sock:bind(alt.addr, port) + if not res then + sock:close() + else + res, err = sock:listen(backlog) + if not res then + sock:close() + else + return sock + end + end + end + return nil, err + end + + _M.try = _M.newtry() + + function _M.choose(table) + return function(name, opt1, opt2) + if base.type(name) ~= "string" then + name, opt1, opt2 = "default", name, opt1 + end + local f = table[name or "nil"] + if not f then base.error("unknown key (" .. base.tostring(name) .. ")", 3) else return f(opt1, opt2) end - end - end - - ----------------------------------------------------------------------------- - -- Socket sources and sinks, conforming to LTN12 - ----------------------------------------------------------------------------- - -- create namespaces inside LuaSocket namespace - local sourcet, sinkt = {}, {} - _M.sourcet = sourcet - _M.sinkt = sinkt - - _M.BLOCKSIZE = 2048 - - sinkt["close-when-done"] = + end + end + + ----------------------------------------------------------------------------- + -- Socket sources and sinks, conforming to LTN12 + ----------------------------------------------------------------------------- + -- create namespaces inside LuaSocket namespace + local sourcet, sinkt = {}, {} + _M.sourcet = sourcet + _M.sinkt = sinkt + + _M.BLOCKSIZE = 2048 + + sinkt["close-when-done"] = function(sock) - return base.setmetatable( - { - getfd = function() - return sock:getfd() - end, - dirty = function() - return sock:dirty() + return base.setmetatable( + { + getfd = function() + return sock:getfd() + end, + dirty = function() + return sock:dirty() + end + }, + { + __call = function(self, chunk, err) + if not chunk then + sock:close() + return 1 + else + return sock:send(chunk) end - }, - { - __call = function(self, chunk, err) - if not chunk then - sock:close() - return 1 - else - return sock:send(chunk) - end - end - } - ) - end + end + } + ) + end sinkt["keep-open"] = function(sock) - return base.setmetatable( - { - getfd = function() - return sock:getfd() - end, - dirty = function() - return sock:dirty() + return base.setmetatable( + { + getfd = function() + return sock:getfd() + end, + dirty = function() + return sock:dirty() + end + }, + { + __call = function(self, chunk, err) + if chunk then + return sock:send(chunk) + else + return 1 end - }, - { - __call = function(self, chunk, err) - if chunk then - return sock:send(chunk) - else - return 1 - end - end - } - ) - end + end + } + ) + end sinkt["default"] = sinkt["keep-open"] @@ -179,133 +179,133 @@ local function createSocket() sourcet["by-length"] = function(sock, length) - return base.setmetatable( - { - getfd = function() - return sock:getfd() - end, - dirty = function() - return sock:dirty() + return base.setmetatable( + { + getfd = function() + return sock:getfd() + end, + dirty = function() + return sock:dirty() + end + }, + { + __call = function() + if length <= 0 then + return nil end - }, - { - __call = function() - if length <= 0 then - return nil - end - local size = math.min(socket.BLOCKSIZE, length) - local chunk, err = sock:receive(size) - if err then - return nil, err - end - length = length - string.len(chunk) - return chunk + local size = math.min(socket.BLOCKSIZE, length) + local chunk, err = sock:receive(size) + if err then + return nil, err end - } - ) - end + length = length - string.len(chunk) + return chunk + end + } + ) + end sourcet["until-closed"] = function(sock) - local done - return base.setmetatable( - { - getfd = function() - return sock:getfd() - end, - dirty = function() - return sock:dirty() + local done + return base.setmetatable( + { + getfd = function() + return sock:getfd() + end, + dirty = function() + return sock:dirty() + end + }, + { + __call = function() + if done then + return nil end - }, - { - __call = function() - if done then - return nil - end - local chunk, err, partial = sock:receive(socket.BLOCKSIZE) - if not err then - return chunk - elseif err == "closed" then - sock:close() - done = 1 - return partial - else - return nil, err - end + local chunk, err, partial = sock:receive(socket.BLOCKSIZE) + if not err then + return chunk + elseif err == "closed" then + sock:close() + done = 1 + return partial + else + return nil, err end - } - ) - end - - sourcet["default"] = sourcet["until-closed"] - - _M.source = _M.choose(sourcet) - - return _M + end + } + ) + end + + sourcet["default"] = sourcet["until-closed"] + + _M.source = _M.choose(sourcet) + + return _M end local function createJson() - local math = require("math") - local string = require("string") - local table = require("table") - local object = nil - ----------------------------------------------------------------------------- - -- Module declaration - ----------------------------------------------------------------------------- - local json = {} -- Public namespace + local math = require("math") + local string = require("string") + local table = require("table") + local object = nil + ----------------------------------------------------------------------------- + -- Module declaration + ----------------------------------------------------------------------------- + local json = {} -- Public namespace local json_private = {} -- Private namespace + + -- Public constants + json.EMPTY_ARRAY = {} + json.EMPTY_OBJECT = {} + -- Public functions - -- Public constants - json.EMPTY_ARRAY = {} - json.EMPTY_OBJECT = {} - -- Public functions - - -- Private functions - local decode_scanArray - local decode_scanComment - local decode_scanConstant - local decode_scanNumber - local decode_scanObject - local decode_scanString - local decode_scanWhitespace - local encodeString - local isArray - local isEncodable - - ----------------------------------------------------------------------------- - -- PUBLIC FUNCTIONS - ----------------------------------------------------------------------------- - --- Encodes an arbitrary Lua object / variable. - -- @param v The Lua object / variable to be JSON encoded. - -- @return String containing the JSON encoding in internal Lua string format (i.e. not unicode) - function json.encode(v) - -- Handle nil values - if v == nil then - return "null" - end - - local vtype = type(v) - - -- Handle strings - if vtype == "string" then + -- Private functions + local decode_scanArray + local decode_scanComment + local decode_scanConstant + local decode_scanNumber + local decode_scanObject + local decode_scanString + local decode_scanWhitespace + local encodeString + local isArray + local isEncodable + + ----------------------------------------------------------------------------- + -- PUBLIC FUNCTIONS + ----------------------------------------------------------------------------- + --- Encodes an arbitrary Lua object / variable. + -- @param v The Lua object / variable to be JSON encoded. + -- @return String containing the JSON encoding in internal Lua string format (i.e. not unicode) + function json.encode(v) + -- Handle nil values + if v == nil then + return "null" + end + + local vtype = type(v) + + -- Handle strings + if vtype == "string" then return '"' .. json_private.encodeString(v) .. '"' -- Need to handle encoding in string end - - -- Handle booleans - if vtype == "number" or vtype == "boolean" then + + -- Handle booleans + if vtype == "number" or vtype == "boolean" then return tostring(v) end - - -- Handle tables - if vtype == "table" then - local rval = {} - -- Consider arrays separately - local bArray, maxCount = isArray(v) - if bArray then - for i = 1, maxCount do - table.insert(rval, json.encode(v[i])) - end - else -- An object, not an array + + -- Handle tables + if vtype == "table" then + local rval = {} + -- Consider arrays separately + local bArray, maxCount = isArray(v) + if bArray then + for i = 1, maxCount do + table.insert(rval, json.encode(v[i])) + end + else -- An object, not an array for i, j in pairs(v) do if isEncodable(i) and isEncodable(j) then table.insert(rval, '"' .. json_private.encodeString(i) .. '":' .. json.encode(j)) @@ -317,23 +317,23 @@ local function createJson() else return "{" .. table.concat(rval, ",") .. "}" end - end - - -- Handle null values - if vtype == "function" and v == json.null then + end + + -- Handle null values + if vtype == "function" and v == json.null then return "null" end assert(false, "encode attempt to encode unsupported type " .. vtype .. ":" .. tostring(v)) end - - --- Decodes a JSON string and returns the decoded value as a Lua data structure / value. - -- @param s The string to scan. - -- @param [startPos] Optional starting position where the JSON string is located. Defaults to 1. - -- @param Lua object, number The object that was scanned, as a Lua table / string / number / boolean or nil, - -- and the position of the first character after - -- the scanned JSON object. - function json.decode(s, startPos) + + --- Decodes a JSON string and returns the decoded value as a Lua data structure / value. + -- @param s The string to scan. + -- @param [startPos] Optional starting position where the JSON string is located. Defaults to 1. + -- @param Lua object, number The object that was scanned, as a Lua table / string / number / boolean or nil, + -- and the position of the first character after + -- the scanned JSON object. + function json.decode(s, startPos) startPos = startPos and startPos or 1 startPos = decode_scanWhitespace(s, startPos) assert(startPos <= string.len(s), "Unterminated JSON encoded object found at position in [" .. s .. "]") @@ -366,19 +366,18 @@ local function createJson() function json.null() return json.null -- so json.null() will also return null ;-) end - - ----------------------------------------------------------------------------- - -- Internal, PRIVATE functions. - -- Following a Python-like convention, I have prefixed all these 'PRIVATE' - -- functions with an underscore. - ----------------------------------------------------------------------------- - --- Scans an array from JSON into a Lua object - -- startPos begins at the start of the array. - -- Returns the array and the next starting position - -- @param s The string being scanned. - -- @param startPos The starting position for the scan. - -- @return table, int The scanned array as a table, and the position of the next character to scan. - function decode_scanArray(s, startPos) + ----------------------------------------------------------------------------- + -- Internal, PRIVATE functions. + -- Following a Python-like convention, I have prefixed all these 'PRIVATE' + -- functions with an underscore. + ----------------------------------------------------------------------------- + --- Scans an array from JSON into a Lua object + -- startPos begins at the start of the array. + -- Returns the array and the next starting position + -- @param s The string being scanned. + -- @param startPos The starting position for the scan. + -- @return table, int The scanned array as a table, and the position of the next character to scan. + function decode_scanArray(s, startPos) local array = {} -- The return value local stringLen = string.len(s) assert( @@ -424,8 +423,8 @@ local function createJson() -- @return object, int The object (true, false or nil) and the position at which the next character should be -- scanned. function decode_scanConstant(s, startPos) - local consts = { ["true"] = true, ["false"] = false, ["null"] = nil } - local constNames = { "true", "false", "null" } + local consts = {["true"] = true, ["false"] = false, ["null"] = nil} + local constNames = {"true", "false", "null"} for i, k in pairs(constNames) do if string.sub(s, startPos, startPos + string.len(k) - 1) == k then @@ -574,7 +573,7 @@ local function createJson() assert( string.find(s, startChar, j + 1), "String decoding failed: missing closing " .. - startChar .. " at position " .. j .. "(for string at position " .. startPos .. ")" + startChar .. " at position " .. j .. "(for string at position " .. startPos .. ")" ) return table.concat(t, ""), j + 2 -- END SoniEx2 @@ -650,13 +649,13 @@ local function createJson() if v ~= (t.n or #t) then return false end -- False if n does not hold the number of elements - else -- Else of (k=='n') + else -- Else of (k=='n') if isEncodable(v) then return false end end -- End of (k~='n') - end -- End of k,v not an indexed pair - end -- End of loop across all pairs + end -- End of k,v not an indexed pair + end -- End of loop across all pairs return true, maxIndex end @@ -678,64 +677,64 @@ local debug_server = nil local breakInfoSocket = nil local json = createJson() local LuaDebugger = { - fileMaps = {}, - Run = true, --表示正常运行只检测断点 - StepIn = false, - StepNext = false, - StepOut = false, - breakInfos = {}, - runTimeType = nil, - isHook = true, - pathCachePaths = {}, - isProntToConsole = 1, - isDebugPrint = true, - hookType = "lrc", - stepNextFun = nil, - DebugLuaFie = "", - runLineCount = 0, - --分割字符串缓存 - splitFilePaths = {}, - version = "0.9.3", + fileMaps = {}, + Run = true, --表示正常运行只检测断点 + StepIn = false, + StepNext = false, + StepOut = false, + breakInfos = {}, + runTimeType = nil, + isHook = true, + pathCachePaths = {}, + isProntToConsole = 1, + isDebugPrint = true, + hookType = "lrc", + stepNextFun = nil, + DebugLuaFie = "", + runLineCount = 0, + --分割字符串缓存 + splitFilePaths = {}, + version="0.9.3", serVarLevel = 4 } local debug_hook = nil local _resume = coroutine.resume coroutine.resume = function(co, ...) - if (LuaDebugger.isHook) then + if (LuaDebugger.isHook) then if coroutine.status(co) ~= "dead" then debug.sethook(co, debug_hook, "lrc") - end + end end return _resume(co, ...) end LuaDebugger.event = { - S2C_SetBreakPoints = 1, - C2S_SetBreakPoints = 2, - S2C_RUN = 3, - C2S_HITBreakPoint = 4, - S2C_ReqVar = 5, - C2S_ReqVar = 6, - --单步跳过请求 - S2C_NextRequest = 7, - --单步跳过反馈 - C2S_NextResponse = 8, - -- 单步跳过 结束 没有下一步 - C2S_NextResponseOver = 9, - --单步跳入 - S2C_StepInRequest = 10, - C2S_StepInResponse = 11, - --单步跳出 - S2C_StepOutRequest = 12, - --单步跳出返回 - C2S_StepOutResponse = 13, - --打印 - C2S_LuaPrint = 14, - S2C_LoadLuaScript = 16, - C2S_SetSocketName = 17, - C2S_LoadLuaScript = 18, - C2S_DebugXpCall = 20, - S2C_DebugClose = 21, + S2C_SetBreakPoints = 1, + C2S_SetBreakPoints = 2, + S2C_RUN = 3, + C2S_HITBreakPoint = 4, + S2C_ReqVar = 5, + C2S_ReqVar = 6, + --单步跳过请求 + S2C_NextRequest = 7, + --单步跳过反馈 + C2S_NextResponse = 8, + -- 单步跳过 结束 没有下一步 + C2S_NextResponseOver = 9, + --单步跳入 + S2C_StepInRequest = 10, + C2S_StepInResponse = 11, + --单步跳出 + S2C_StepOutRequest = 12, + --单步跳出返回 + C2S_StepOutResponse = 13, + --打印 + C2S_LuaPrint = 14, + S2C_LoadLuaScript = 16, + C2S_SetSocketName = 17, + C2S_LoadLuaScript = 18, + C2S_DebugXpCall = 20, + S2C_DebugClose = 21, S2C_SerVar = 24, C2S_SerVar = 25, S2C_ReLoadFile = 26, @@ -743,27 +742,27 @@ LuaDebugger.event = { } --@region print function print(...) - if (LuaDebugger.isProntToConsole == 1 or LuaDebugger.isProntToConsole == 3) then + if (LuaDebugger.isProntToConsole == 1 or LuaDebugger.isProntToConsole == 3) then debugger_print(...) end if (LuaDebugger.isProntToConsole == 1 or LuaDebugger.isProntToConsole == 2) then if (debug_server) then - local arg = { ... } --这里的...和{}符号中间需要有空格号,否则会出错 + local arg = {...} --这里的...和{}符号中间需要有空格号,否则会出错 local str = "" if (#arg == 0) then - arg = { "nil" } - end - for k, v in pairs(arg) do - str = str .. tostring(v) .. "\t" - end - local sendMsg = { - event = LuaDebugger.event.C2S_LuaPrint, - data = { msg = ZZBase64.encode(str), type = 1 } - } - local sendStr = json.encode(sendMsg) - debug_server:send(sendStr .. "__debugger_k0204__") - end - end + arg = {"nil"} + end + for k, v in pairs(arg) do + str = str .. tostring(v) .. "\t" + end + local sendMsg = { + event = LuaDebugger.event.C2S_LuaPrint, + data = {msg = ZZBase64.encode(str), type = 1} + } + local sendStr = json.encode(sendMsg) + debug_server:send(sendStr .. "__debugger_k0204__") + end + end end function luaIdePrintWarn(...) @@ -772,48 +771,46 @@ function luaIdePrintWarn(...) end if (LuaDebugger.isProntToConsole == 1 or LuaDebugger.isProntToConsole == 2) then if (debug_server) then - local arg = { ... } --这里的...和{}符号中间需要有空格号,否则会出错 + local arg = {...} --这里的...和{}符号中间需要有空格号,否则会出错 local str = "" if (#arg == 0) then - arg = { "nil" } - end - for k, v in pairs(arg) do - str = str .. tostring(v) .. "\t" - end - local sendMsg = { - event = LuaDebugger.event.C2S_LuaPrint, - data = { msg = ZZBase64.encode(str), type = 2 } - } - local sendStr = json.encode(sendMsg) - debug_server:send(sendStr .. "__debugger_k0204__") - end - end + arg = {"nil"} + end + for k, v in pairs(arg) do + str = str .. tostring(v) .. "\t" + end + local sendMsg = { + event = LuaDebugger.event.C2S_LuaPrint, + data = {msg = ZZBase64.encode(str), type = 2} + } + local sendStr = json.encode(sendMsg) + debug_server:send(sendStr .. "__debugger_k0204__") + end + end end - function luaIdePrintErr(...) if (LuaDebugger.isProntToConsole == 1 or LuaDebugger.isProntToConsole == 3) then debugger_print(...) end if (LuaDebugger.isProntToConsole == 1 or LuaDebugger.isProntToConsole == 2) then if (debug_server) then - local arg = { ... } --这里的...和{}符号中间需要有空格号,否则会出错 + local arg = {...} --这里的...和{}符号中间需要有空格号,否则会出错 local str = "" if (#arg == 0) then - arg = { "nil" } - end - for k, v in pairs(arg) do - str = str .. tostring(v) .. "\t" - end - local sendMsg = { - event = LuaDebugger.event.C2S_LuaPrint, - data = { msg = ZZBase64.encode(str), type = 3 } - } - local sendStr = json.encode(sendMsg) - debug_server:send(sendStr .. "__debugger_k0204__") - end - end + arg = {"nil"} + end + for k, v in pairs(arg) do + str = str .. tostring(v) .. "\t" + end + local sendMsg = { + event = LuaDebugger.event.C2S_LuaPrint, + data = {msg = ZZBase64.encode(str), type = 3} + } + local sendStr = json.encode(sendMsg) + debug_server:send(sendStr .. "__debugger_k0204__") + end + end end - --@endregion --@region 辅助方法 @@ -844,23 +841,23 @@ local function debugger_convertParentDir(dir) end end -local function debugger_getFilePathInfo(file) - local fileName = nil +local function debugger_getFilePathInfo(file) + local fileName = nil local dir = nil file = file:gsub("/.\\", "/") - file = file:gsub("\\", "/") - file = file:gsub("//", "/") + file = file:gsub("\\", "/") + file = file:gsub("//", "/") + - - if file:find("@") == 1 then + if file:find("@") == 1 then file = file:sub(2) - end - local findex = file:find("%./") - if (findex == 1) then + end + local findex = file:find("%./") + if (findex == 1) then file = file:sub(3) end - file = debugger_convertParentDir(file) + file = debugger_convertParentDir(file) local fileLength = string.len(file) local suffixNames = { ".lua", @@ -889,8 +886,8 @@ local function debugger_getFilePathInfo(file) end local fileNameStartIndex = debugger_lastIndex(file, "/") if (fileNameStartIndex) then - fileName = string.sub(file, fileNameStartIndex + 1) - + fileName = string.sub(file, fileNameStartIndex + 1) + dir = string.sub(file, 1, fileNameStartIndex) file = dir .. fileName else @@ -901,12 +898,12 @@ local function debugger_getFilePathInfo(file) else dir = string.sub(file, 1, fileNameStartIndex) dir = dir:gsub("%.", "/") - fileName = string.sub(file, fileNameStartIndex + 1) - file = dir .. fileName + fileName = string.sub(file, fileNameStartIndex + 1) + file = dir .. fileName end - end + end - return file, dir, fileName + return file, dir, fileName end --@endregion @@ -918,25 +915,25 @@ end local function debugger_strSplit(input, delimiter) - input = tostring(input) - delimiter = tostring(delimiter) - if (delimiter == "") then + input = tostring(input) + delimiter = tostring(delimiter) + if (delimiter == "") then return false end - local pos, arr = 0, {} - -- for each divider found - for st, sp in function() + local pos, arr = 0, {} + -- for each divider found + for st, sp in function() return string.find(input, delimiter, pos, true) - end do - table.insert(arr, string.sub(input, pos, st - 1)) - pos = sp + 1 - end - table.insert(arr, string.sub(input, pos)) - return arr + end do + table.insert(arr, string.sub(input, pos, st - 1)) + pos = sp + 1 + end + table.insert(arr, string.sub(input, pos)) + return arr end local function debugger_strTrim(input) - input = string.gsub(input, "^[ \t\n\r]+", "") - return string.gsub(input, "[ \t\n\r]+$", "") + input = string.gsub(input, "^[ \t\n\r]+", "") + return string.gsub(input, "[ \t\n\r]+$", "") end local function debugger_dump(value, desciption, nesting) if type(nesting) ~= "number" then @@ -951,7 +948,7 @@ local function debugger_dump(value, desciption, nesting) return tostring(v) end local traceback = debugger_strSplit(debug.traceback("", 2), "\n") - -- print("dump from: " .. debugger_strTrim(traceback[3])) + print("dump from: " .. debugger_strTrim(traceback[3])) local function _dump(value, desciption, indent, nest, keylen) desciption = desciption or "" local spc = "" @@ -1000,7 +997,7 @@ local function debugger_dump(value, desciption, nesting) end _dump(value, desciption, "- ", 1) for i, line in ipairs(result) do - -- print(line) + print(line) end end --@endregion @@ -1008,24 +1005,27 @@ local function debugger_valueToString(v) local vtype = type(v) local vstr = nil if (vtype == "userdata") then - if (LuaDebugger.isFoxGloryProject) then - return "userdata", vtype + if (LuaDebugger.isFoxGloryProject ) then + + return "userdata",vtype + else return tostring(v), vtype end elseif (vtype == "table" or vtype == "function" or vtype == "boolean") then local value = vtype - xpcall(function() - if (LuaDebugger.isFoxGloryProject) then + xpcall(function() + if(LuaDebugger.isFoxGloryProject) then value = vtype else value = tostring(v) end - end, function() + + end,function() value = vtype end) return value, vtype - elseif (vtype == "number" or vtype == "string") then + elseif (vtype == "number" or vtype == "string" ) then return v, vtype else return tostring(v), vtype @@ -1033,12 +1033,12 @@ local function debugger_valueToString(v) end local function debugger_setVarInfo(name, value) local valueStr, valueType = debugger_valueToString(value) - local nameStr, nameType = debugger_valueToString(name) - if (valueStr == nil) then + local nameStr,nameType = debugger_valueToString(name) + if(valueStr == nil) then valueStr = valueType end local valueInfo = { - name = nameStr, + name =nameStr, valueType = valueType, valueStr = ZZBase64.encode(valueStr) } @@ -1047,282 +1047,283 @@ local function debugger_setVarInfo(name, value) end local function debugger_getvalue(f) - local i = 1 - local locals = {} - -- get locals - while true do - local name, value = debug.getlocal(f, i) - if not name then + local i = 1 + local locals = {} + -- get locals + while true do + local name, value = debug.getlocal(f, i) + if not name then break end if (name ~= "(*temporary)") then - locals[name] = value - end - i = i + 1 - end - local func = getinfo(f, "f").func - i = 1 - local ups = {} - while func do -- check for func as it may be nil for tail calls - local name, value = debug.getupvalue(func, i) - if not name then + locals[name] = value + end + i = i + 1 + end + local func = getinfo(f, "f").func + i = 1 + local ups = {} + while func do -- check for func as it may be nil for tail calls + local name, value = debug.getupvalue(func, i) + if not name then break end if (name == "_ENV") then - ups["_ENV_"] = value - else - ups[name] = value - end - i = i + 1 - end + ups["_ENV_"] = value + else + ups[name] = value + end + i = i + 1 + end - return { locals = locals, ups = ups } + return {locals = locals, ups = ups} end --获取堆栈 debugger_stackInfo = function(ignoreCount, event) - local datas = {} - local stack = {} - local varInfos = {} - local funcs = {} - local index = 0 - for i = ignoreCount, 100 do - local source = getinfo(i) - local isadd = true - if (i == ignoreCount) then - local file = source.source - if (file:find(LuaDebugger.DebugLuaFie)) then - return - end - if (file == "=[C]") then - isadd = false - end - end - if not source then - break - end - if (isadd) then - local fullName, dir, fileName = debugger_getFilePathInfo(source.source) - local info = { - src = fullName, - scoreName = source.name, - currentline = source.currentline, - linedefined = source.linedefined, - what = source.what, - nameWhat = source.namewhat - } - index = i - local vars = debugger_getvalue(i + 1) - table.insert(stack, info) - table.insert(varInfos, vars) - table.insert(funcs, source.func) - end - if source.what == "main" then - break - end + local datas = {} + local stack = {} + local varInfos = {} + local funcs = {} + local index = 0 + for i = ignoreCount, 100 do + local source = getinfo(i) + local isadd = true + if (i == ignoreCount) then + local file = source.source + if (file:find(LuaDebugger.DebugLuaFie)) then + return + end + if (file == "=[C]") then + isadd = false + end + end + if not source then + break + end + if (isadd) then + local fullName, dir, fileName = debugger_getFilePathInfo(source.source) + local info = { + src = fullName, + scoreName = source.name, + currentline = source.currentline, + linedefined = source.linedefined, + what = source.what, + nameWhat = source.namewhat + } + index = i + local vars = debugger_getvalue(i + 1) + table.insert(stack, info) + table.insert(varInfos, vars) + table.insert(funcs, source.func) + end + if source.what == "main" then + break end + end - local stackInfo = { stack = stack, vars = varInfos, funcs = funcs } - local data = { - stack = stackInfo.stack, - vars = stackInfo.vars, - funcs = stackInfo.funcs, - event = event, - funcsLength = #stackInfo.funcs, - upFunc = getinfo(ignoreCount - 3, "f").func - } + local stackInfo = {stack = stack, vars = varInfos, funcs = funcs} + local data = { + stack = stackInfo.stack, + vars = stackInfo.vars, + funcs = stackInfo.funcs, + event = event, + funcsLength = #stackInfo.funcs, + upFunc = getinfo(ignoreCount - 3, "f").func + } - return data - end + return data +end --==============================工具方法 end====================================================== --===========================点断信息================================================== --根据不同的游戏引擎进行定时获取断点信息 --CCDirector:sharedDirector():getScheduler() local debugger_setBreak = nil local function debugger_receiveDebugBreakInfo() - if (not jit) then - if (_VERSION) then - -- print("当前lua版本为: ".._VERSION.." 请使用 -----LuaDebug.lua----- 进行调试!") - else - -- print("当前为lua版本,请使用-----LuaDebug.lua-----进行调试!") - end - end - if (breakInfoSocket) then + if(not jit) then + if(_VERSION)then + print("当前lua版本为: ".._VERSION.." 请使用 -----LuaDebug.lua----- 进行调试!") + else + print("当前为lua版本,请使用-----LuaDebug.lua-----进行调试!") + end + end + if (breakInfoSocket) then local msg, status = breakInfoSocket:receive() - if (LuaDebugger.isLaunch == true and status == "closed") then + if(LuaDebugger.isLaunch == true and status == "closed") then os.exit() end - if (msg) then - local netData = json.decode(msg) - if netData.event == LuaDebugger.event.S2C_SetBreakPoints then - debugger_setBreak(netData.data) - elseif netData.event == LuaDebugger.event.S2C_LoadLuaScript then - LuaDebugger.loadScriptBody = netData.data + if (msg) then + local netData = json.decode(msg) + if netData.event == LuaDebugger.event.S2C_SetBreakPoints then + debugger_setBreak(netData.data) + elseif netData.event == LuaDebugger.event.S2C_LoadLuaScript then + LuaDebugger.loadScriptBody = netData.data debugger_exeLuaString() - debugger_sendMsg(breakInfoSocket, LuaDebugger.event.C2S_LoadLuaScript, LuaDebugger.loadScriptBody) + debugger_sendMsg(breakInfoSocket,LuaDebugger.event.C2S_LoadLuaScript,LuaDebugger.loadScriptBody) elseif netData.event == LuaDebugger.event.S2C_ReLoadFile then LuaDebugger.reLoadFileBody = netData.data LuaDebugger.isReLoadFile = false - LuaDebugger.reLoadFileBody.isReLoad = debugger_reLoadFile(LuaDebugger.reLoadFileBody) + LuaDebugger.reLoadFileBody.isReLoad = debugger_reLoadFile(LuaDebugger.reLoadFileBody) LuaDebugger.reLoadFileBody.script = nil - + debugger_sendMsg( breakInfoSocket, LuaDebugger.event.C2S_ReLoadFile, { stack = LuaDebugger.reLoadFileBody - + } - ) - end - end - end + ) + end + end + end end local function splitFilePath(path) - if (LuaDebugger.splitFilePaths[path]) then - return LuaDebugger.splitFilePaths[path] - end - local pos, arr = 0, {} - -- for each divider found - for st, sp in function() + if (LuaDebugger.splitFilePaths[path]) then + return LuaDebugger.splitFilePaths[path] + end + local pos, arr = 0, {} + -- for each divider found + for st, sp in function() return string.find(path, "/", pos, true) - end do - local pathStr = string.sub(path, pos, st - 1) - table.insert(arr, pathStr) - pos = sp + 1 - end - local pathStr = string.sub(path, pos) - table.insert(arr, pathStr) - LuaDebugger.splitFilePaths[path] = arr - return arr + end do + local pathStr = string.sub(path, pos, st - 1) + table.insert(arr, pathStr) + pos = sp + 1 + end + local pathStr = string.sub(path, pos) + table.insert(arr, pathStr) + LuaDebugger.splitFilePaths[path] = arr + return arr +end +debugger_setBreak = + function(datas) + local breakInfos = LuaDebugger.breakInfos + for i, data in ipairs(datas) do + data.fileName = string.lower(data.fileName) + data.serverPath = string.lower(data.serverPath) + local breakInfo = breakInfos[data.fileName] + if (not breakInfo) then + breakInfos[data.fileName] = {} + breakInfo = breakInfos[data.fileName] + end + if (not data.breakDatas or #data.breakDatas == 0) then + breakInfo[data.serverPath] = nil + else + local fileBreakInfo = breakInfo[data.serverPath] + if (not fileBreakInfo) then + fileBreakInfo = { + pathNames = splitFilePath(data.serverPath), + --命中次數判斷計數器 + hitCounts = {} + } + breakInfo[data.serverPath] = fileBreakInfo + end + local lineInfos = {} + for li, breakData in ipairs(data.breakDatas) do + lineInfos[breakData.line] = breakData + if (breakData.hitCondition and breakData.hitCondition ~= "") then + breakData.hitCondition = tonumber(breakData.hitCondition) + else + breakData.hitCondition = 0 + end + if (not fileBreakInfo.hitCounts[breakData.line]) then + fileBreakInfo.hitCounts[breakData.line] = 0 + end + end + fileBreakInfo.lines = lineInfos + --這裡添加命中次數判斷 + for line, count in pairs(fileBreakInfo.hitCounts) do + if (not lineInfos[line]) then + fileBreakInfo.hitCounts[line] = nil + end + end + end + local count = 0 + for i, linesInfo in pairs(breakInfo) do + count = count + 1 + end + if (count == 0) then + breakInfos[data.fileName] = nil + end + end + --debugger_dump(breakInfos, "breakInfos", 6) + --检查是否需要断点 + local isHook = false + for k, v in pairs(breakInfos) do + isHook = true + break + end + + --这样做的原因是为了最大限度的使手机调试更加流畅 注意这里会连续的进行n次 + if (isHook) then + if (not LuaDebugger.isHook) then + debug.sethook(debug_hook, "lrc") + end + LuaDebugger.isHook = true + else + if (LuaDebugger.isHook) then + debug.sethook() + end + LuaDebugger.isHook = false + end end -debugger_setBreak = - function(datas) - local breakInfos = LuaDebugger.breakInfos - for i, data in ipairs(datas) do - data.fileName = string.lower(data.fileName) - data.serverPath = string.lower(data.serverPath) - local breakInfo = breakInfos[data.fileName] - if (not breakInfo) then - breakInfos[data.fileName] = {} - breakInfo = breakInfos[data.fileName] - end - if (not data.breakDatas or #data.breakDatas == 0) then - breakInfo[data.serverPath] = nil - else - local fileBreakInfo = breakInfo[data.serverPath] - if (not fileBreakInfo) then - fileBreakInfo = { - pathNames = splitFilePath(data.serverPath), - --命中次數判斷計數器 - hitCounts = {} - } - breakInfo[data.serverPath] = fileBreakInfo - end - local lineInfos = {} - for li, breakData in ipairs(data.breakDatas) do - lineInfos[breakData.line] = breakData - if (breakData.hitCondition and breakData.hitCondition ~= "") then - breakData.hitCondition = tonumber(breakData.hitCondition) - else - breakData.hitCondition = 0 - end - if (not fileBreakInfo.hitCounts[breakData.line]) then - fileBreakInfo.hitCounts[breakData.line] = 0 - end - end - fileBreakInfo.lines = lineInfos - --這裡添加命中次數判斷 - for line, count in pairs(fileBreakInfo.hitCounts) do - if (not lineInfos[line]) then - fileBreakInfo.hitCounts[line] = nil - end - end - end - local count = 0 - for i, linesInfo in pairs(breakInfo) do - count = count + 1 - end - if (count == 0) then - breakInfos[data.fileName] = nil - end - end - --debugger_dump(breakInfos, "breakInfos", 6) - --检查是否需要断点 - local isHook = false - for k, v in pairs(breakInfos) do - isHook = true - break - end - - --这样做的原因是为了最大限度的使手机调试更加流畅 注意这里会连续的进行n次 - if (isHook) then - if (not LuaDebugger.isHook) then - debug.sethook(debug_hook, "lrc") - end - LuaDebugger.isHook = true - else - if (LuaDebugger.isHook) then - debug.sethook() - end - LuaDebugger.isHook = false - end - end local function debugger_checkFileIsBreak(fileName) - return LuaDebugger.breakInfos[fileName] + return LuaDebugger.breakInfos[fileName] end --=====================================断点信息 end ---------------------------------------------- local controller_host = "192.168.1.102" local controller_port = 7003 debugger_sendMsg = function(serverSocket, eventName, data) - local sendMsg = { - event = eventName, - data = data - } - local sendStr = json.encode(sendMsg) - serverSocket:send(sendStr .. "__debugger_k0204__") + local sendMsg = { + event = eventName, + data = data + } + local sendStr = json.encode(sendMsg) + serverSocket:send(sendStr .. "__debugger_k0204__") end -function debugger_conditionStr(condition, vars, callBack) - local function loadScript() - local currentTabble = {} - - local locals = vars[1].locals - local ups = vars[1].ups - if (ups) then - for k, v in pairs(ups) do - currentTabble[k] = v - end - end - - if (locals) then - for k, v in pairs(locals) do - currentTabble[k] = v - end - end - setmetatable(currentTabble, { __index = _G }) - local fun = loadstring("return " .. condition) - setfenv(fun, currentTabble) - return fun() - end - local status, - msg = +function debugger_conditionStr(condition, vars, callBack) + local function loadScript() + local currentTabble = {} + + local locals = vars[1].locals + local ups = vars[1].ups + if (ups) then + for k, v in pairs(ups) do + currentTabble[k] = v + end + end + + if (locals) then + for k, v in pairs(locals) do + currentTabble[k] = v + end + end + setmetatable(currentTabble, {__index = _G}) + local fun = loadstring("return " .. condition) + setfenv(fun, currentTabble) + return fun() + end + local status, + msg = xpcall( - loadScript, - function(error) - -- print(error) - end - ) + loadScript, + function(error) + print(error) + end + ) if (status and msg) then callBack() end end - --执行lua字符串 debugger_exeLuaString = function() + local function loadScript() + local script = LuaDebugger.loadScriptBody.script if (LuaDebugger.loadScriptBody.isBreak) then - local currentTabble = { _G = _G } + local currentTabble = {_G = _G} local frameId = LuaDebugger.loadScriptBody.frameId frameId = frameId local func = LuaDebugger.currentDebuggerData.funcs[frameId] @@ -1335,8 +1336,8 @@ debugger_exeLuaString = function() for k, v in pairs(locals) do currentTabble[k] = v end - setmetatable(currentTabble, { __index = _G }) - + setmetatable(currentTabble, {__index = _G}) + local fun = loadstring(script) setfenv(fun, currentTabble) fun() @@ -1346,51 +1347,54 @@ debugger_exeLuaString = function() end end local status, - msg = + msg = xpcall( - loadScript, - function(error) - -- debugger_sendMsg(debug_server, LuaDebugger.event.C2S_LoadLuaScript, LuaDebugger.loadScriptBody) - end - ) - LuaDebugger.loadScriptBody.script = nil + loadScript, + function(error) + + -- debugger_sendMsg(debug_server, LuaDebugger.event.C2S_LoadLuaScript, LuaDebugger.loadScriptBody) + end + ) + LuaDebugger.loadScriptBody.script = nil if (LuaDebugger.loadScriptBody.isBreak) then - LuaDebugger.serVarLevel = LuaDebugger.serVarLevel + 1 - LuaDebugger.currentDebuggerData = debugger_stackInfo(LuaDebugger.serVarLevel, LuaDebugger.event - .C2S_HITBreakPoint) - LuaDebugger.loadScriptBody.stack = LuaDebugger.currentDebuggerData.stack - end + LuaDebugger.serVarLevel = LuaDebugger.serVarLevel+1 + LuaDebugger.currentDebuggerData = debugger_stackInfo(LuaDebugger.serVarLevel, LuaDebugger.event.C2S_HITBreakPoint) + LuaDebugger.loadScriptBody.stack = LuaDebugger.currentDebuggerData.stack + end LuaDebugger.loadScriptBody.complete = true + end --@region 调试中修改变量值 --根据key 值在 value 查找 -local function debugger_getTablekey(key, keyType, value) - if (keyType == -1) then +local function debugger_getTablekey(key,keyType,value) + if(keyType == -1) then return key - elseif (keyType == 1) then + elseif(keyType == 1) then return tonumber(key) - elseif (keyType == 2) then + elseif(keyType == 2) then local valueKey = nil - for k, v in pairs(value) do + for k,v in pairs(value) do local nameType = type(k) - if (nameType == "userdata" or nameType == "table") then + if(nameType == "userdata" or nameType == "table") then if (not LuaDebugger.isFoxGloryProject) then valueKey = tostring(k) - if (key == valueKey) then + if(key == valueKey) then return k end break end end end + end end local function debugger_setVarValue(server, data) + local newValue = nil - local level = LuaDebugger.serVarLevel + LuaDebugger.setVarBody.frameId + local level = LuaDebugger.serVarLevel+LuaDebugger.setVarBody.frameId local firstKeyName = data.keys[1] --@region vars check local localValueChangeIndex = -1 @@ -1405,7 +1409,7 @@ local function debugger_setVarValue(server, data) if not name then break end - if (firstKeyName == name) then + if(firstKeyName == name) then localValueChangeIndex = i oldValue = value end @@ -1419,11 +1423,11 @@ local function debugger_setVarValue(server, data) local ups = {} while func do -- check for func as it may be nil for tail calls local name, value = debug.getupvalue(func, i) - + if not name then break end - if (localValueChangeIndex == -1 and firstKeyName == name) then + if(localValueChangeIndex == -1 and firstKeyName == name) then upValueFun = func oldValue = value upValueChangeIndex = i @@ -1435,9 +1439,9 @@ local function debugger_setVarValue(server, data) end i = i + 1 end - --@endregion - local vars = { locals = locals, ups = ups } - +--@endregion + local vars = {locals = locals, ups = ups} + local function loadScript() local currentTabble = {} local locals = vars.locals @@ -1453,56 +1457,58 @@ local function debugger_setVarValue(server, data) currentTabble[k] = v end end - setmetatable(currentTabble, { __index = _G }) + setmetatable(currentTabble, {__index = _G}) local fun = loadstring("return " .. data.value) setfenv(fun, currentTabble) newValue = fun() end local status, - msg = + msg = xpcall( - loadScript, - function(error) - -- print(error, "============================") - end - ) - + loadScript, + function(error) + print(error, "============================") + end + ) + local i = 1 - + -- local 查找并替换 local keyLength = #data.keys - - if (keyLength == 1) then - if (localValueChangeIndex ~= -1) then + + if(keyLength == 1) then + if(localValueChangeIndex ~= -1) then + debug.setlocal(level, localValueChangeIndex, newValue) - elseif (upValueFun ~= nil) then - debug.setupvalue(upValueFun, upValueChangeIndex, newValue) + elseif(upValueFun ~= nil) then + debug.setupvalue( upValueFun, upValueChangeIndex, newValue ) else --全局变量查找 - if (_G[firstKeyName]) then + if(_G[firstKeyName]) then _G[firstKeyName] = newValue end end else - if (not oldValue) then - if (_G[firstKeyName]) then + if(not oldValue) then + if(_G[firstKeyName]) then oldValue = _G[firstKeyName] end end local tempValue = oldValue - for i = 2, keyLength - 1 do - if (tempValue) then - oldValue = oldValue[debugger_getTablekey(data.keys[i], data.numberTypes[i], oldValue)] + for i=2,keyLength-1 do + if(tempValue) then + oldValue = oldValue[debugger_getTablekey(data.keys[i],data.numberTypes[i],oldValue)] end end - if (tempValue) then - oldValue[debugger_getTablekey(data.keys[keyLength], data.numberTypes[keyLength], oldValue)] = newValue + if(tempValue) then + oldValue[debugger_getTablekey(data.keys[keyLength],data.numberTypes[keyLength],oldValue)] = newValue end end - local varInfo = debugger_setVarInfo(data.varName, newValue) + local varInfo = debugger_setVarInfo(data.varName, newValue) data.varInfo = varInfo - LuaDebugger.serVarLevel = LuaDebugger.serVarLevel + 1 + LuaDebugger.serVarLevel = LuaDebugger.serVarLevel+1 LuaDebugger.currentDebuggerData = debugger_stackInfo(LuaDebugger.serVarLevel, LuaDebugger.event.C2S_HITBreakPoint) + end --@endregion @@ -1512,107 +1518,107 @@ end --调试修改变量值统一的 _resume checkSetVar = function() - if (LuaDebugger.isSetVar) then - LuaDebugger.isSetVar = false - debugger_setVarValue(debug_server, LuaDebugger.setVarBody) - LuaDebugger.serVarLevel = LuaDebugger.serVarLevel + 1 - _resume(coro_debugger, LuaDebugger.setVarBody) - xpcall( - checkSetVar, - function(error) - -- print("设置变量", error) - end - ) - elseif (LuaDebugger.isLoadLuaScript) then - LuaDebugger.isLoadLuaScript = false - debugger_exeLuaString() - LuaDebugger.serVarLevel = LuaDebugger.serVarLevel + 1 - _resume(coro_debugger, LuaDebugger.reLoadFileBody) - xpcall( - checkSetVar, - function(error) - -- print("执行代码", error) - end - ) - elseif (LuaDebugger.isReLoadFile) then - LuaDebugger.isReLoadFile = false - LuaDebugger.reLoadFileBody.isReLoad = debugger_reLoadFile(LuaDebugger.reLoadFileBody) - -- print("重载结果:",LuaDebugger.reLoadFileBody.isReLoad) - LuaDebugger.reLoadFileBody.script = nil - LuaDebugger.serVarLevel = LuaDebugger.serVarLevel + 1 - _resume(coro_debugger, LuaDebugger.reLoadFileBody) - xpcall( - checkSetVar, - function(error) - -- print("重新加载文件", error) - end - ) - end + if (LuaDebugger.isSetVar) then + LuaDebugger.isSetVar = false + debugger_setVarValue(debug_server,LuaDebugger.setVarBody) + LuaDebugger.serVarLevel = LuaDebugger.serVarLevel+1 + _resume(coro_debugger, LuaDebugger.setVarBody) + xpcall( + checkSetVar, + function(error) + print("设置变量", error) + end + ) + elseif(LuaDebugger.isLoadLuaScript) then + LuaDebugger.isLoadLuaScript = false + debugger_exeLuaString() + LuaDebugger.serVarLevel = LuaDebugger.serVarLevel+1 + _resume(coro_debugger, LuaDebugger.reLoadFileBody) + xpcall( + checkSetVar, + function(error) + print("执行代码", error) + end + ) + elseif(LuaDebugger.isReLoadFile) then + LuaDebugger.isReLoadFile = false + LuaDebugger.reLoadFileBody.isReLoad = debugger_reLoadFile(LuaDebugger.reLoadFileBody) + print("重载结果:",LuaDebugger.reLoadFileBody.isReLoad) + LuaDebugger.reLoadFileBody.script = nil + LuaDebugger.serVarLevel = LuaDebugger.serVarLevel+1 + _resume(coro_debugger, LuaDebugger.reLoadFileBody) + xpcall( + checkSetVar, + function(error) + print("重新加载文件", error) + end + ) end - +end + local function getSource(source) - source = string.lower(source) + source = string.lower(source) if (LuaDebugger.pathCachePaths[source]) then - LuaDebugger.currentLineFile = LuaDebugger.pathCachePaths[source] - return LuaDebugger.pathCachePaths[source] - end + LuaDebugger.currentLineFile = LuaDebugger.pathCachePaths[source] + return LuaDebugger.pathCachePaths[source] + end - local fullName, dir, fileName = debugger_getFilePathInfo(source) - LuaDebugger.currentLineFile = fullName - LuaDebugger.pathCachePaths[source] = fileName + local fullName, dir, fileName = debugger_getFilePathInfo(source) + LuaDebugger.currentLineFile = fullName + LuaDebugger.pathCachePaths[source] = fileName - return fileName + return fileName end local function debugger_GeVarInfoBytUserData(server, var) - local fileds = LuaDebugTool.getUserDataInfo(var) + local fileds = LuaDebugTool.getUserDataInfo(var) + + local varInfos = {} - local varInfos = {} - - - --c# vars - for i = 1, fileds.Count do - local filed = fileds[i - 1] - local valueInfo = { - name = filed.name, - valueType = filed.valueType, - valueStr = ZZBase64.encode(filed.valueStr), - isValue = filed.isValue, - csharp = true - } - - table.insert(varInfos, valueInfo) - end - return varInfos -end + + --c# vars + for i = 1, fileds.Count do + local filed = fileds[i - 1] + local valueInfo = { + name = filed.name, + valueType = filed.valueType, + valueStr = ZZBase64.encode(filed.valueStr), + isValue = filed.isValue, + csharp = true + } + + table.insert(varInfos, valueInfo) + end + return varInfos +end local function debugger_getValueByScript(value, script) - local val = nil - local status, - msg = - xpcall( - function() - local fun = loadstring("return " .. script) - setfenv(fun, value) - val = fun() - end, - function(error) - -- print(error, "====>") - val = nil - end - ) + local val = nil + local status, + msg = + xpcall( + function() + local fun = loadstring("return " .. script) + setfenv(fun, value) + val = fun() + end, + function(error) + print(error, "====>") + val = nil + end + ) - return val + return val end -local function debugger_getVarByKeys(value, keys, index) - local str = "" - local keyLength = #keys - for i = index, keyLength do - local key = keys[i] - if (key == "[metatable]") then - else - if (i == index) then +local function debugger_getVarByKeys(value, keys, index) + local str = "" + local keyLength = #keys + for i = index, keyLength do + local key = keys[i] + if (key == "[metatable]") then + else + if (i == index) then if (string.find(key, "%.")) then if (str == "") then i = index + 1 @@ -1624,10 +1630,10 @@ local function debugger_getVarByKeys(value, keys, index) return debugger_getVarByKeys(value, keys, i) else - str = key - end - else - if (string.find(key, "%[")) then + str = key + end + else + if (string.find(key, "%[")) then str = str .. key elseif (type(key) == "string") then if (string.find(key, "table:") or string.find(key, "userdata:") or string.find(key, "function:")) then @@ -1706,7 +1712,7 @@ end local function debugger_searchVarByKeys(value, keys, searckKeys) local index, val = debugger_getVarByKeys(value, searckKeys, 1) - if (not LuaDebugTool or not LuaDebugTool.getCSharpValue or type(LuaDebugTool.getCSharpValue) ~= "function") then + if (not LuaDebugTool or not LuaDebugTool.getCSharpValue or type(LuaDebugTool.getCSharpValue) ~= "function") then return index, val end if (val) then @@ -1739,6 +1745,7 @@ end return ]] local function debugger_getmetatable(value, metatable, vinfos, server, variablesReference, debugSpeedIndex, metatables) + for i, mtable in ipairs(metatables) do if (metatable == mtable) then return vinfos @@ -1787,13 +1794,14 @@ local function debugger_getmetatable(value, metatable, vinfos, server, variables end end end - + local m = getmetatable(metatable) if (m) then return debugger_getmetatable(value, m, vinfos, server, variablesReference, debugSpeedIndex, metatables) else return vinfos end + end local function debugger_sendTableField(luatable, vinfos, server, variablesReference, debugSpeedIndex, valueType) if (valueType == "userdata") then @@ -1832,12 +1840,12 @@ local function debugger_sendTableValues(value, server, variablesReference, debug local valueType = type(value) local userDataInfos = {} local m = nil - + if (valueType == "userdata") then m = getmetatable(value) - + vinfos = debugger_sendTableField(value, vinfos, server, variablesReference, debugSpeedIndex, valueType) - + if (LuaDebugTool) then local varInfos = debugger_GeVarInfoBytUserData(server, value, variablesReference, debugSpeedIndex) @@ -1866,6 +1874,7 @@ local function debugger_sendTableValues(value, server, variablesReference, debug vinfos = {} end end + end else m = getmetatable(value) @@ -1889,55 +1898,56 @@ end --获取lua 变量的方法 local function debugger_getBreakVar(body, server) - local variablesReference = body.variablesReference - local debugSpeedIndex = body.debugSpeedIndex - local vinfos = {} - local function exe() - local frameId = body.frameId + local variablesReference = body.variablesReference + local debugSpeedIndex = body.debugSpeedIndex + local vinfos = {} + local function exe() + local frameId = body.frameId local type_ = body.type local keys = body.keys - --找到对应的var - local vars = nil - if (type_ == 1) then - vars = LuaDebugger.currentDebuggerData.vars[frameId + 1] - vars = vars.locals - elseif (type_ == 2) then - vars = LuaDebugger.currentDebuggerData.vars[frameId + 1] - vars = vars.ups - elseif (type_ == 3) then - vars = _G - end - if (#keys == 0) then - debugger_sendTableValues(vars, server, variablesReference, debugSpeedIndex) - return - end - local index, value = debugger_searchVarByKeys(vars, keys, keys) - if (value) then - local valueType = type(value) + --找到对应的var + local vars = nil + if (type_ == 1) then + vars = LuaDebugger.currentDebuggerData.vars[frameId + 1] + vars = vars.locals + elseif (type_ == 2) then + vars = LuaDebugger.currentDebuggerData.vars[frameId + 1] + vars = vars.ups + elseif (type_ == 3) then + vars = _G + end + if (#keys == 0) then + debugger_sendTableValues(vars, server, variablesReference, debugSpeedIndex) + return + end + local index, value = debugger_searchVarByKeys(vars, keys, keys) + if (value) then + local valueType = type(value) if (valueType == "table" or valueType == "userdata") then - debugger_sendTableValues(value, server, variablesReference, debugSpeedIndex) - else + + debugger_sendTableValues(value, server, variablesReference, debugSpeedIndex) + else if (valueType == "function") then - if (LuaDebugger.isFoxGloryProject) then - value = "function" + if(LuaDebugger.isFoxGloryProject) then + value = "function" else value = tostring(value) end - end - debugger_sendMsg( + end + debugger_sendMsg( server, LuaDebugger.event.C2S_ReqVar, { - variablesReference = variablesReference, - debugSpeedIndex = debugSpeedIndex, - vars = ZZBase64.encode(value), - isComplete = 1, - varType = valueType - } + variablesReference = variablesReference, + debugSpeedIndex = debugSpeedIndex, + vars = ZZBase64.encode(value), + isComplete = 1, + varType = valueType + } ) - end - else - debugger_sendMsg( + end + else + debugger_sendMsg( server, LuaDebugger.event.C2S_ReqVar, { @@ -1948,14 +1958,14 @@ local function debugger_getBreakVar(body, server) varType = "nil" } ) - end - end - xpcall( + end + end + xpcall( exe, function(error) - -- -- print("获取变量错误 错误消息-----------------") - -- -- print(error) - -- -- print(debug.traceback("", 2)) + -- print("获取变量错误 错误消息-----------------") + -- print(error) + -- print(debug.traceback("", 2)) debugger_sendMsg( server, LuaDebugger.event.C2S_ReqVar, @@ -1977,62 +1987,64 @@ local function debugger_getBreakVar(body, server) ) end local function ResetDebugInfo() - LuaDebugger.Run = false - LuaDebugger.StepIn = false - LuaDebugger.StepNext = false - LuaDebugger.StepOut = false + LuaDebugger.Run = false + LuaDebugger.StepIn = false + LuaDebugger.StepNext = false + LuaDebugger.StepOut = false + end local function debugger_loop(server) - server = debug_server - --命令 - local command - local eval_env = {} - local arg - while true do - local line, status = server:receive() - if (status == "closed") then - if (LuaDebugger.isLaunch) then + server = debug_server + --命令 + local command + local eval_env = {} + local arg + while true do + local line, status = server:receive() + if (status == "closed") then + if(LuaDebugger.isLaunch) then os.exit() else debug.sethook() coroutine.yield() end - end - if (line) then - local netData = json.decode(line) - local event = netData.event + end + if (line) then + local netData = json.decode(line) + local event = netData.event local body = netData.data if (event == LuaDebugger.event.S2C_DebugClose) then - if (LuaDebugger.isLaunch) then - os.exit() - else - debug.sethook() - coroutine.yield() - end - elseif event == LuaDebugger.event.S2C_SetBreakPoints then - --设置断点信息 - local function setB() - debugger_setBreak(body) - end - xpcall( + if(LuaDebugger.isLaunch) then + os.exit() + else + debug.sethook() + coroutine.yield() + end + + elseif event == LuaDebugger.event.S2C_SetBreakPoints then + --设置断点信息 + local function setB() + debugger_setBreak(body) + end + xpcall( setB, function(error) - -- print(error) + print(error) end ) - elseif event == LuaDebugger.event.S2C_RUN then --开始运行 - LuaDebugger.runTimeType = body.runTimeType - LuaDebugger.isProntToConsole = body.isProntToConsole + elseif event == LuaDebugger.event.S2C_RUN then --开始运行 + LuaDebugger.runTimeType = body.runTimeType + LuaDebugger.isProntToConsole = body.isProntToConsole LuaDebugger.isFoxGloryProject = body.isFoxGloryProject LuaDebugger.isLaunch = body.isLaunch - ResetDebugInfo() - LuaDebugger.currentDebuggerData = nil - LuaDebugger.Run = true + ResetDebugInfo() + LuaDebugger.currentDebuggerData = nil + LuaDebugger.Run = true LuaDebugger.tempRunFlag = true - LuaDebugger.currentLine = nil - local data = coroutine.yield() - LuaDebugger.serVarLevel = 4 - LuaDebugger.currentDebuggerData = data + LuaDebugger.currentLine= nil + local data = coroutine.yield() + LuaDebugger.serVarLevel = 4 + LuaDebugger.currentDebuggerData = data debugger_sendMsg( server, data.event, @@ -2040,58 +2052,58 @@ local function debugger_loop(server) stack = data.stack } ) - elseif event == LuaDebugger.event.S2C_ReqVar then -- 获取变量信息 - --请求数据信息 - debugger_getBreakVar(body, server) - elseif event == LuaDebugger.event.S2C_NextRequest then -- 设置单步跳过 - ResetDebugInfo() - LuaDebugger.StepNext = true - --设置当前文件名和当前行数 - local data = coroutine.yield() - LuaDebugger.serVarLevel = 4 - --重置调试信息 - LuaDebugger.currentDebuggerData = data - debugger_sendMsg( + elseif event == LuaDebugger.event.S2C_ReqVar then -- 获取变量信息 + --请求数据信息 + debugger_getBreakVar(body, server) + elseif event == LuaDebugger.event.S2C_NextRequest then -- 设置单步跳过 + ResetDebugInfo() + LuaDebugger.StepNext = true + --设置当前文件名和当前行数 + local data = coroutine.yield() + LuaDebugger.serVarLevel = 4 + --重置调试信息 + LuaDebugger.currentDebuggerData = data + debugger_sendMsg( server, data.event, { stack = data.stack } ) - elseif (event == LuaDebugger.event.S2C_StepInRequest) then --单步跳入 - --单步跳入 - ResetDebugInfo() - LuaDebugger.StepIn = true - - local data = coroutine.yield() - LuaDebugger.serVarLevel = 4 - --重置调试信息 - LuaDebugger.currentDebuggerData = data - debugger_sendMsg( + elseif (event == LuaDebugger.event.S2C_StepInRequest) then --单步跳入 + --单步跳入 + ResetDebugInfo() + LuaDebugger.StepIn = true + + local data = coroutine.yield() + LuaDebugger.serVarLevel = 4 + --重置调试信息 + LuaDebugger.currentDebuggerData = data + debugger_sendMsg( server, data.event, { - stack = data.stack, - eventType = data.eventType - } - ) - elseif (event == LuaDebugger.event.S2C_StepOutRequest) then - --单步跳出 - ResetDebugInfo() - LuaDebugger.StepOut = true - local data = coroutine.yield() - LuaDebugger.serVarLevel = 4 - --重置调试信息 - LuaDebugger.currentDebuggerData = data - debugger_sendMsg( + stack = data.stack, + eventType = data.eventType + } + ) + elseif (event == LuaDebugger.event.S2C_StepOutRequest) then + --单步跳出 + ResetDebugInfo() + LuaDebugger.StepOut = true + local data = coroutine.yield() + LuaDebugger.serVarLevel = 4 + --重置调试信息 + LuaDebugger.currentDebuggerData = data + debugger_sendMsg( server, data.event, { - stack = data.stack, - eventType = data.eventType - } - ) - elseif event == LuaDebugger.event.S2C_LoadLuaScript then + stack = data.stack, + eventType = data.eventType + } + ) + elseif event == LuaDebugger.event.S2C_LoadLuaScript then LuaDebugger.loadScriptBody = body LuaDebugger.isLoadLuaScript = true local data = coroutine.yield() @@ -2111,8 +2123,8 @@ local function debugger_loop(server) stack = data, eventType = data.eventType } - ) - elseif event == LuaDebugger.event.S2C_ReLoadFile then + ) + elseif event == LuaDebugger.event.S2C_ReLoadFile then LuaDebugger.isReLoadFile = true LuaDebugger.reLoadFileBody = body local data = coroutine.yield() @@ -2123,321 +2135,340 @@ local function debugger_loop(server) stack = data, eventType = data.eventType } - ) - end - end - end + ) + end + end + end end coro_debugger = coroutine.create(debugger_loop) debug_hook = function(event, line) - if (not LuaDebugger.isHook) then - return - end - if (LuaDebugger.Run) then - if (event == "line") then - local isCheck = false - for k, breakInfo in pairs(LuaDebugger.breakInfos) do - for bk, linesInfo in pairs(breakInfo) do - if (linesInfo.lines and linesInfo.lines[line]) then - isCheck = true - break - end - end - if (isCheck) then - break - end - end + if(not LuaDebugger.isHook) then + return + end - if (not isCheck) then - return - end - end - end + if(LuaDebugger.Run) then + if(event == "line") then + local isCheck = false + for k, breakInfo in pairs(LuaDebugger.breakInfos) do + for bk, linesInfo in pairs(breakInfo) do + + if(linesInfo.lines and linesInfo.lines[line]) then + isCheck = true + break + end + end + if(isCheck) then + break + end + end + + if(not isCheck) then + return + end + + end + end + + + local file = nil + if(event == "line") then + + local funs = nil + local funlength =0 + if(LuaDebugger.currentDebuggerData) then + funs = LuaDebugger.currentDebuggerData.funcs + funlength = #funs + end + local stepInfo = getinfo(2) + local tempFunc = stepInfo.func + local source = stepInfo.source + file = getSource(source); + if(source == "=[C]" or source:find(LuaDebugger.DebugLuaFie)) then return end + if(funlength > 0 and funs[1] == tempFunc and LuaDebugger.currentLine ~= line) then + LuaDebugger.runLineCount = LuaDebugger.runLineCount+1 + end + local breakInfo = LuaDebugger.breakInfos[file] + local breakData = nil + local ischeck = false + if(breakInfo) then + + for k, lineInfo in pairs(breakInfo) do + local lines = lineInfo.lines + if(lines and lines[line]) then + ischeck = true + break + end + end + end + local isHit = false + if(ischeck) then - local file = nil - if (event == "line") then - local funs = nil - local funlength = 0 - if (LuaDebugger.currentDebuggerData) then - funs = LuaDebugger.currentDebuggerData.funcs - funlength = #funs - end - local stepInfo = getinfo(2) - local tempFunc = stepInfo.func - local source = stepInfo.source - file = getSource(source); - if (source == "=[C]" or source:find(LuaDebugger.DebugLuaFie)) then return end - if (funlength > 0 and funs[1] == tempFunc and LuaDebugger.currentLine ~= line) then - LuaDebugger.runLineCount = LuaDebugger.runLineCount + 1 - end - local breakInfo = LuaDebugger.breakInfos[file] - local breakData = nil - local ischeck = false - if (breakInfo) then - for k, lineInfo in pairs(breakInfo) do - local lines = lineInfo.lines - if (lines and lines[line]) then - ischeck = true - break - end - end - end - local isHit = false - if (ischeck) then --并且在断点中 - local info = stepInfo - local source = string.lower(info.source) - local fullName, dir, fileName = debugger_getFilePathInfo(source) - local hitPathNames = splitFilePath(fullName) + local info = stepInfo + local source = string.lower( info.source ) + local fullName,dir,fileName = debugger_getFilePathInfo(source) + local hitPathNames = splitFilePath(fullName) + + local hitCounts = {} + local debugHitCounts = nil + for k, lineInfo in pairs(breakInfo) do - local hitCounts = {} - local debugHitCounts = nil - for k, lineInfo in pairs(breakInfo) do local lines = lineInfo.lines - local pathNames = lineInfo.pathNames - debugHitCounts = lineInfo.hitCounts - if (lines and lines[line]) then - breakData = lines[line] - --判断路径 - hitCounts[k] = 0 - local hitPathNamesCount = #hitPathNames - local pathNamesCount = #pathNames - local checkCount = 0; - while (true) do - if (pathNames[pathNamesCount] ~= hitPathNames[hitPathNamesCount]) then - break - else - hitCounts[k] = hitCounts[k] + 1 - end - pathNamesCount = pathNamesCount - 1 - hitPathNamesCount = hitPathNamesCount - 1 - checkCount = checkCount + 1 - if (pathNamesCount <= 0 or hitPathNamesCount <= 0) then - break - end - end - if (checkCount > 0) then - break; - end - else - breakData = nil - end - end - if (breakData) then - local hitFieName = "" - local maxCount = 0 - for k, v in pairs(hitCounts) do - if (v > maxCount) then - maxCount = v - hitFieName = k; - end - end - local hitPathNamesLength = #hitPathNames - if (hitPathNamesLength == 1 or (hitPathNamesLength > 1 and maxCount > 1)) then - if (hitFieName ~= "") then + local pathNames = lineInfo.pathNames + debugHitCounts = lineInfo.hitCounts + if(lines and lines[line]) then + breakData = lines[line] + --判断路径 + hitCounts[k] = 0 + local hitPathNamesCount = #hitPathNames + local pathNamesCount = #pathNames + local checkCount = 0; + while(true) do + if (pathNames[pathNamesCount] ~= hitPathNames[hitPathNamesCount]) then + break + else + hitCounts[k] = hitCounts[k] + 1 + end + pathNamesCount = pathNamesCount - 1 + hitPathNamesCount = hitPathNamesCount - 1 + checkCount = checkCount+1 + if(pathNamesCount <= 0 or hitPathNamesCount <= 0) then + break + end + end + if(checkCount>0) then + break; + end + else + breakData = nil + end + end + if(breakData) then + local hitFieName = "" + local maxCount = 0 + for k, v in pairs(hitCounts) do + if(v > maxCount) then + maxCount = v + hitFieName = k; + end + end + local hitPathNamesLength = #hitPathNames + if (hitPathNamesLength == 1 or (hitPathNamesLength > 1 and maxCount > 1)) then + if(hitFieName ~= "") then + local hitCount = breakData.hitCondition - local clientHitCount = debugHitCounts[breakData.line] - clientHitCount = clientHitCount + 1 - debugHitCounts[breakData.line] = clientHitCount - if (funs and funs[1] == tempFunc and LuaDebugger.runLineCount == 0) then - LuaDebugger.runLineCount = 0 - elseif (LuaDebugger.tempRunFlag and LuaDebugger.currentLine == line) then - LuaDebugger.runLineCount = 0 - LuaDebugger.tempRunFlag = nil - elseif (clientHitCount >= hitCount) then - isHit = true - end - end - end - end - end - if (LuaDebugger.StepOut) then - if (funlength == 1) then - ResetDebugInfo(); - LuaDebugger.Run = true - return - else - if (funs[2] == tempFunc) then - local data = debugger_stackInfo(3, LuaDebugger.event.C2S_StepInResponse) - -- -- print("StepIn 挂起") - --挂起等待调试器作出反应 + local clientHitCount = debugHitCounts[breakData.line] + clientHitCount = clientHitCount + 1 + debugHitCounts[breakData.line] = clientHitCount + if(funs and funs[1] == tempFunc and LuaDebugger.runLineCount == 0) then + LuaDebugger.runLineCount = 0 + elseif(LuaDebugger.tempRunFlag and LuaDebugger.currentLine == line) then + LuaDebugger.runLineCount = 0 + LuaDebugger.tempRunFlag = nil + elseif(clientHitCount >= hitCount) then + isHit = true + end + + end + end + end + end + if(LuaDebugger.StepOut) then + if(funlength == 1) then + ResetDebugInfo(); + LuaDebugger.Run = true + return + else + if(funs[2] == tempFunc) then + local data = debugger_stackInfo(3, LuaDebugger.event.C2S_StepInResponse) + -- print("StepIn 挂起") + --挂起等待调试器作出反应 _resume(coro_debugger, data) checkSetVar() - return - end - end - end - - if (LuaDebugger.StepIn) then - if (funs[1] == tempFunc and LuaDebugger.runLineCount == 0) then - return - end - local data = debugger_stackInfo(3, LuaDebugger.event.C2S_StepInResponse) - -- -- print("StepIn 挂起") - --挂起等待调试器作出反应 + return + end + end + end + + if(LuaDebugger.StepIn) then + if(funs[1] == tempFunc and LuaDebugger.runLineCount == 0) then + return + end + local data = debugger_stackInfo(3, LuaDebugger.event.C2S_StepInResponse) + -- print("StepIn 挂起") + --挂起等待调试器作出反应 _resume(coro_debugger, data) checkSetVar() - return - end - - if (LuaDebugger.StepNext) then - local isNext = false - if (funs) then - for i, f in ipairs(funs) do - if (tempFunc == f) then - if (LuaDebugger.currentLine == line) then - return - end - isNext = true - break; - end - end + return + end + + if(LuaDebugger.StepNext ) then + local isNext = false + if(funs) then + for i,f in ipairs(funs) do + if(tempFunc == f) then + if(LuaDebugger.currentLine == line) then + return + end + isNext =true + break; + end + end else - isNext = true - end - if (isNext) then - local data = debugger_stackInfo(3, LuaDebugger.event.C2S_NextResponse) - LuaDebugger.runLineCount = 0 - LuaDebugger.currentLine = line - --挂起等待调试器作出反应 + + isNext =true + end + if(isNext) then + local data = debugger_stackInfo(3, LuaDebugger.event.C2S_NextResponse) + LuaDebugger.runLineCount = 0 + LuaDebugger.currentLine = line + --挂起等待调试器作出反应 _resume(coro_debugger, data) checkSetVar() - return - end - end + return + end + end + + local sevent = nil + - local sevent = nil + --断点判断 + if(isHit) then + - - --断点判断 - if (isHit) then - LuaDebugger.runLineCount = 0 - LuaDebugger.currentLine = line - sevent = LuaDebugger.event.C2S_HITBreakPoint - --调用 coro_debugger 并传入 参数 - local data = debugger_stackInfo(3, sevent) - --挂起等待调试器作出反应 - if (breakData and breakData.condition) then - debugger_conditionStr(breakData.condition, data.vars, function() + LuaDebugger.runLineCount = 0 + LuaDebugger.currentLine = line + sevent = LuaDebugger.event.C2S_HITBreakPoint + --调用 coro_debugger 并传入 参数 + local data = debugger_stackInfo(3, sevent) + --挂起等待调试器作出反应 + if(breakData and breakData.condition) then + debugger_conditionStr(breakData.condition,data.vars,function() _resume(coro_debugger, data) checkSetVar() - end) - else - --挂起等待调试器作出反应 + end) + else + --挂起等待调试器作出反应 _resume(coro_debugger, data) checkSetVar() - end - end - end + end + end + end end local function debugger_xpcall() - --调用 coro_debugger 并传入 参数 + --调用 coro_debugger 并传入 参数 local data = debugger_stackInfo(4, LuaDebugger.event.C2S_HITBreakPoint) - if (data.stack and data.stack[1]) then - data.stack[1].isXpCall = true + if(data.stack and data.stack[1]) then + data.stack[1].isXpCall = true end - --挂起等待调试器作出反应 + --挂起等待调试器作出反应 _resume(coro_debugger, data) checkSetVar() end --调试开始 local function start() - local socket = createSocket() - -- print(controller_host) - -- print(controller_port) + + local socket = createSocket() + print(controller_host) + print(controller_port) + + local fullName,dirName,fileName = debugger_getFilePathInfo(getinfo(1).source) + LuaDebugger.DebugLuaFie = fileName + local server = socket.connect(controller_host, controller_port) + debug_server = server; + if server then + --创建breakInfo socket + socket = createSocket() + breakInfoSocket = socket.connect(controller_host, controller_port) + if(breakInfoSocket) then + breakInfoSocket:settimeout(0) + debugger_sendMsg(breakInfoSocket, LuaDebugger.event.C2S_SetSocketName, { + name = "breakPointSocket" + }) + + + debugger_sendMsg(server, LuaDebugger.event.C2S_SetSocketName, { + name = "mainSocket", + version = LuaDebugger.version - local fullName, dirName, fileName = debugger_getFilePathInfo(getinfo(1).source) - LuaDebugger.DebugLuaFie = fileName - local server = socket.connect(controller_host, controller_port) - debug_server = server; - if server then - --创建breakInfo socket - socket = createSocket() - breakInfoSocket = socket.connect(controller_host, controller_port) - if (breakInfoSocket) then - breakInfoSocket:settimeout(0) - debugger_sendMsg(breakInfoSocket, LuaDebugger.event.C2S_SetSocketName, { - name = "breakPointSocket" - }) - - - debugger_sendMsg(server, LuaDebugger.event.C2S_SetSocketName, { - name = "mainSocket", - version = LuaDebugger.version - - }) - xpcall(function() - sethook(debug_hook, "lrc") - end, function(error) - -- print("error:", error) - end) - if (not jit) then - if (_VERSION) then - -- print("当前lua版本为: ".._VERSION.." 请使用LuaDebug 进行调试!") - else - -- print("当前为lua版本,请使用LuaDebug 进行调试!") - end - end - _resume(coro_debugger, server) - end - end + }) + xpcall(function() + sethook(debug_hook, "lrc") + end, function(error) + print("error:", error) + end) + if(not jit) then + if(_VERSION)then + print("当前lua版本为: ".._VERSION.." 请使用LuaDebug 进行调试!") + else + print("当前为lua版本,请使用LuaDebug 进行调试!") + end + + end + _resume(coro_debugger, server) + end + end end function StartDebug(host, port) - if (not host) then - -- print("error host nil") - end - if (not port) then - -- print("error prot nil") - end - if (type(host) ~= "string") then - -- print("error host not string") - end - if (type(port) ~= "number") then - -- print("error host not number") - end - controller_host = host - controller_port = port - xpcall(start, function(error) - -- body - -- print(error) - end) - return debugger_receiveDebugBreakInfo, debugger_xpcall + + + if(not host) then + print("error host nil") + end + if(not port) then + print("error prot nil") + end + if(type(host) ~= "string") then + print("error host not string") + end + if(type(port) ~= "number") then + print("error host not number") + end + controller_host = host + controller_port = port + xpcall(start, function(error) + -- body + print(error) + end) + return debugger_receiveDebugBreakInfo, debugger_xpcall end + + --base64 local string = string ZZBase64.__code = { - 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', - 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', - 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', - 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/', -}; + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', + 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', + 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', + 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/', + }; ZZBase64.__decode = {} -for k, v in pairs(ZZBase64.__code) do - ZZBase64.__decode[string.byte(v, 1)] = k - 1 +for k,v in pairs(ZZBase64.__code) do + ZZBase64.__decode[string.byte(v,1)] = k - 1 end function ZZBase64.encode(text) - local len = string.len(text) - local left = len % 3 - len = len - left - local res = {} - local index = 1 + local len = string.len(text) + local left = len % 3 + len = len - left + local res = {} + local index = 1 for i = 1, len, 3 do - local a = string.byte(text, i) + local a = string.byte(text, i ) local b = string.byte(text, i + 1) local c = string.byte(text, i + 2) -- num = a<<16 + b<<8 + c - local num = a * 65536 + b * 256 + c + local num = a * 65536 + b * 256 + c for j = 1, 4 do --tmp = num >> ((4 -j) * 6) - local tmp = math.floor(num / (2 ^ ((4 - j) * 6))) + local tmp = math.floor(num / (2 ^ ((4-j) * 6))) --curPos = tmp&0x3f local curPos = tmp % 64 + 1 res[index] = ZZBase64.__code[curPos] @@ -2448,52 +2479,52 @@ function ZZBase64.encode(text) if left == 1 then ZZBase64.__left1(res, index, text, len) elseif left == 2 then - ZZBase64.__left2(res, index, text, len) + ZZBase64.__left2(res, index, text, len) end return table.concat(res) end function ZZBase64.__left2(res, index, text, len) local num1 = string.byte(text, len + 1) - num1 = num1 * 1024 --lshift 10 + num1 = num1 * 1024 --lshift 10 local num2 = string.byte(text, len + 2) - num2 = num2 * 4 --lshift 2 + num2 = num2 * 4 --lshift 2 local num = num1 + num2 - + local tmp1 = math.floor(num / 4096) --rShift 12 local curPos = tmp1 % 64 + 1 res[index] = ZZBase64.__code[curPos] - + local tmp2 = math.floor(num / 64) curPos = tmp2 % 64 + 1 res[index + 1] = ZZBase64.__code[curPos] curPos = num % 64 + 1 res[index + 2] = ZZBase64.__code[curPos] - - res[index + 3] = "=" + + res[index + 3] = "=" end -function ZZBase64.__left1(res, index, text, len) +function ZZBase64.__left1(res, index,text, len) local num = string.byte(text, len + 1) - num = num * 16 - + num = num * 16 + local tmp = math.floor(num / 64) local curPos = tmp % 64 + 1 - res[index] = ZZBase64.__code[curPos] - + res[index ] = ZZBase64.__code[curPos] + curPos = num % 64 + 1 res[index + 1] = ZZBase64.__code[curPos] - - res[index + 2] = "=" - res[index + 3] = "=" + + res[index + 2] = "=" + res[index + 3] = "=" end function ZZBase64.decode(text) local len = string.len(text) - local left = 0 + local left = 0 if string.sub(text, len - 1) == "==" then - left = 2 + left = 2 len = len - 4 elseif string.sub(text, len) == "=" then left = 1 @@ -2503,20 +2534,20 @@ function ZZBase64.decode(text) local res = {} local index = 1 local decode = ZZBase64.__decode - for i = 1, len, 4 do - local a = decode[string.byte(text, i)] - local b = decode[string.byte(text, i + 1)] - local c = decode[string.byte(text, i + 2)] - local d = decode[string.byte(text, i + 3)] + for i =1, len, 4 do + local a = decode[string.byte(text,i )] + local b = decode[string.byte(text,i + 1)] + local c = decode[string.byte(text,i + 2)] + local d = decode[string.byte(text,i + 3)] --num = a<<18 + b<<12 + c<<6 + d local num = a * 262144 + b * 4096 + c * 64 + d - + local e = string.char(num % 256) num = math.floor(num / 256) local f = string.char(num % 256) num = math.floor(num / 256) - res[index] = string.char(num % 256) + res[index ] = string.char(num % 256) res[index + 1] = f res[index + 2] = e index = index + 3 @@ -2532,11 +2563,11 @@ end function ZZBase64.__decodeLeft1(res, index, text, len) local decode = ZZBase64.__decode - local a = decode[string.byte(text, len + 1)] - local b = decode[string.byte(text, len + 2)] - local c = decode[string.byte(text, len + 3)] + local a = decode[string.byte(text, len + 1)] + local b = decode[string.byte(text, len + 2)] + local c = decode[string.byte(text, len + 3)] local num = a * 4096 + b * 64 + c - + local num1 = math.floor(num / 1024) % 256 local num2 = math.floor(num / 4) % 256 res[index] = string.char(num1) @@ -2545,11 +2576,14 @@ end function ZZBase64.__decodeLeft2(res, index, text, len) local decode = ZZBase64.__decode - local a = decode[string.byte(text, len + 1)] + local a = decode[string.byte(text, len + 1)] local b = decode[string.byte(text, len + 2)] local num = a * 64 + b num = math.floor(num / 16) res[index] = string.char(num) end + + + return StartDebug diff --git a/lua_probject/extend_project/extend/majiang/lichuan/EXClearingView.lua b/lua_probject/extend_project/extend/majiang/lichuan/EXClearingView.lua index a5b2cda2..574e679b 100644 --- a/lua_probject/extend_project/extend/majiang/lichuan/EXClearingView.lua +++ b/lua_probject/extend_project/extend/majiang/lichuan/EXClearingView.lua @@ -6,585 +6,236 @@ local EXClearingView = {} local M = EXClearingView function EXClearingView.new(blur_view) - setmetatable(M, { __index = ResultView }) - local self = setmetatable({}, { __index = M }) - self._full = true - ResultView.init(self, "ui://Main_Majiang/clearing") + setmetatable(M, { __index = ResultView }) + local self = setmetatable({}, { __index = M }) + self._full = true + ResultView.init(self, "ui://Main_Majiang/clearing_jiangxi") - self._currenIndex = 0 - self._blur_view = blur_view - self._close_zone = false - self:InitMaPai() + self._currenIndex = 0 + self._blur_view = blur_view + self._close_zone = false + -- self:InitMaPai() - return self + return self end -function M:InitMaPai() - self.maPaiCtr = self._view:GetController("mapai") - self.maPaiCtr.selectedIndex = 0 +-- function M:InitMaPai() +-- self.maPaiCtr = self._view:GetController("mapai") +-- self.maPaiCtr.selectedIndex = 0 - self.maPaiList = {} +-- self.maPaiList = {} - for i = 1, 8 do - local tempMP = self._view:GetChild("niao" .. i) - table.insert(self.maPaiList, tempMP) - end -end - -function M:IsMapaiShow(niao, isShow) - if niao then - niao.visible = isShow - end -end - -function M:SetMaPaiValue(niao, value) - if niao then - niao.icon = 'ui://Main_Majiang/' .. get_majiang_prefix(DataManager.CurrenRoom.game_id) .. "201_" .. value - end -end - -function M:SetMaPaiColor(niao, num) - niao:GetController("color").selectedIndex = num -end - -function M:HideAllMapai() - for i = 1, #self.maPaiList do - self:IsMapaiShow(self.maPaiList[i], false) - self:SetMaPaiColor(self.maPaiList[i], 0) - end -end - -function M:ShowSelectMaPai(niaoList) - if niaoList and #niaoList > 0 then - self.maPaiCtr.selectedIndex = 1 - self:HideAllMapai() - for i = 1, #niaoList do - self:IsMapaiShow(self.maPaiList[i], true) - self:SetMaPaiValue(self.maPaiList[i], niaoList[i].card) - if niaoList[i].score > 0 then - self:SetMaPaiColor(self.maPaiList[i], 2) - end - end - else - self.maPaiCtr.selectedIndex = 0 - end -end - -function M:CalculatePaixingInfo(result) - self.WinList = {} - if result.info_list and #result.info_list > 0 then - for i = 1, #result.info_list do - if result.info_list[i].win_list and #result.info_list[i].win_list > 0 then - table.insert(self.WinList, result.info_list[i].win_list) - end - end - end - - printlog("牌型列表====>>>") - pt(self.WinList) -end - -function M:SetPaixingxiangqing(num) - for i = 1, #self.PaiXingXiangQingCtrList do - if self.PaiXingXiangQingCtrList[i] then - self.PaiXingXiangQingCtrList[i].selectedIndex = num - end - end -end +-- for i = 1, 8 do +-- local tempMP = self._view:GetChild("niao" .. i) +-- table.insert(self.maPaiList, tempMP) +-- end +-- end function M:InitData(over, room, result, total_result, callback) - self._callback = callback - local _overCtr = self._view:GetController("over") - local btn_confirm = self._view:GetChild("btn_confirm") - local btn_result = self._view:GetChild("btn_showResult") - local btn_close = self._view:GetChild("big_result"):GetChild("btn_close") - local _btnCtr = self._view:GetController("button") - local _sdkCtr = self._view:GetController("sdk") - local ctr_type = self._view:GetController("type") + self._callback = callback + local showClearMainBtn = self._view:GetChild("btn_showClearMain") + local nextRoundBtn = self._view:GetChild("btn_nextRound") + local nextRoundBtn2 = self._view:GetChild("Btn_NextRound2") + local endRound = self._view:GetChild("Btn_EndRound") + local _overCtr = self._view:GetController("over") + local mainCtr = self._view:GetController("main") + local playerNum = self._view:GetController("playerNum") - self._view:GetChild("tex_roominfo").text = string.format("房号%s 局%s/%s %s", room.room_id, room.curren_round, - room.room_config.round, os.date("%Y-%m-%d %H:%M:%S", os.time())) - self._view:GetChild("tex_gameinfo").text = string.gsub(room.room_config:GetDes2(), "\r", "") + local peopleNum = room.room_config.people_num - if result then - self:ShowSelectMaPai(result.niao) - self:CalculatePaixingInfo(result) - end + playerNum.selectedIndex = peopleNum - 2 - self.PaiXingXiangQingCtrList = {} + showClearMainBtn.onClick:Set(function() + mainCtr.selectedIndex = 1 + end) - local paixingxiangqing = self._view:GetChild("btn_detal") - local fanhuipaixing = self._view:GetChild("btn_fanhuipaixing") - fanhuipaixing.visible = false - paixingxiangqing.visible = true - paixingxiangqing.onClick:Add(function() - paixingxiangqing.visible = false - fanhuipaixing.visible = true - self:SetPaixingxiangqing(1) - end) - fanhuipaixing.onClick:Add(function() - paixingxiangqing.visible = true - fanhuipaixing.visible = false - self:SetPaixingxiangqing(0) - end) + nextRoundBtn.onClick:Set(function() + local _gamectr = ControllerManager.GetController(GameController) + _gamectr:PlayerReady() + self:DestroyWithCallback() + end) + nextRoundBtn2.onClick:Set(function() + local _gamectr = ControllerManager.GetController(GameController) + _gamectr:PlayerReady() + self:DestroyWithCallback() + end) - if over ~= 2 then - if result.liuju then - ctr_type.selectedIndex = 3 - else - local info_list = result.info_list - for i = 1, #info_list do - local is_win = info_list[i].is_win - if is_win then - if info_list[i].seat == room.self_player.seat then - ctr_type.selectedIndex = 1 - else - ctr_type.selectedIndex = 2 - end - end - end - end + endRound.onClick:Set(function() + ViewManager.ChangeView(ViewManager.View_Family) + end) - if over == 0 then - _btnCtr.selectedIndex = 0 - _sdkCtr.selectedIndex = 1 - btn_confirm.onClick:Add(function() - local _gamectr = ControllerManager.GetController(GameController) - _gamectr:PlayerReady() - self:DestroyWithCallback() - end) - self:AddClearItem(room, result.info_list, nil, over, result.niao, result.active_player) - elseif over == 1 then - _btnCtr.selectedIndex = 1 - _sdkCtr.selectedIndex = 1 - btn_result.onClick:Add(function() - self.maPaiCtr.selectedIndex = 0 - _overCtr.selectedIndex = 1 - _btnCtr.selectedIndex = 0 - _sdkCtr.selectedIndex = 0 - if self._qsinfo_view then - self._qsinfo_view:Dispose() - end - end) - btn_close.onClick:Add(function() - ViewManager.ChangeView(ViewManager.View_Lobby) - end) - - self:AddClearItem(room, result.info_list, total_result.info_list, over, result.niao, result.active_player) - end - else - _overCtr.selectedIndex = 1 - self.maPaiCtr.selectedIndex = 0 - btn_close.onClick:Add(function() - ViewManager.ChangeView(ViewManager.View_Lobby) - end) - - self:AddClearItem(room, nil, total_result.info_list, over) - end + if over == 0 then + _overCtr.selectedIndex = 0 + self:fillResult0(room, peopleNum, result) + else + _overCtr.selectedIndex = 1 + self:fillResult1(room, peopleNum, total_result) + end end -function M:AddClearItem(room, data, total_data, over, niao, active_player) - local n = over + 1 - local list_view1 = self._view:GetChild("player_list_1") - local list_view2 = self._view:GetChild("player_list_2") +function M:fillResult0(room, peopleNum, result) + local config = ExtendManager.GetExtendConfig(room.game_id) + local mode = config:GetGameInfo() + local gamePlay = mode:LoadConfigToDetail(json.encode(room.room_config.config)) + self._view:GetChild("Label_GamePlay").title = string.format("第%s/%s局,%s", room.curren_round, + room.room_config.round, gamePlay) + for i = 1, peopleNum do + local playerInfoComp = self._view:GetChild(string.format("Comp_Player%d", i)) - if 0 == over or 1 == over then - table.sort(data, function(a, b) return a.seat < b.seat end) - list_view1:RemoveChildrenToPool() + local allCardsList = playerInfoComp:GetChild("list_allCards") + local huCardBtn = playerInfoComp:GetChild("Btn_Card_Hu") + local jiangMaList = playerInfoComp:GetChild("list_JiangMa") + local ziMoCtr = playerInfoComp:GetController("isZiMo") + local dianPaoCtr = playerInfoComp:GetController("isPao") + local isMeCtr = playerInfoComp:GetController("IsMe") - for i = 1, #data do - local item = list_view1:AddItemFromPool() - self:FillItemData(room, data[i], item, active_player, niao) - end - if #data == 3 then - list_view1.lineGap = 54 - elseif #data == 2 then - list_view1.lineGap = 108 - end - if 1 == over then - self:FillItemData2(room, total_data, list_view2) - end - elseif 2 == over then - self:FillItemData2(room, total_data, list_view2) - end + local infoList = result.info_list[i] + local playInfo = room:GetPlayerBySeat(infoList.seat) + local fzCardInfo = playInfo.fz_list + local fzInfoNum = #fzCardInfo + local handInfoNum = #infoList.hand_card + + self:fillHead(playInfo.self_user.head_url, playerInfoComp) + + playerInfoComp:GetChild("text_name").text = playInfo.self_user.nick_name + playerInfoComp:GetChild("Text_BoJing").text = infoList.jing_score >= 0 and + string.format("+%d", infoList.jing_score) or infoList.jing_score + playerInfoComp:GetChild("Text_Gang").text = infoList.gang_score >= 0 and + string.format("+%d", infoList.gang_score) or infoList.gang_score + playerInfoComp:GetChild("Text_Hu").text = infoList.hu_score >= 0 and string.format("+%d", infoList.hu_score) or + infoList.hu_score + playerInfoComp:GetChild("Text_Tatal").text = infoList.round_score >= 0 and + string.format("+%d", infoList.round_score) or infoList.round_score + + for j = 1, fzInfoNum do + if fzCardInfo[j].type == FZType.Peng then + local item = allCardsList:AddItemFromPool("ui://Main_Majiang/Comp_FZ_3") + for l = 1, 3 do + local card = item:GetChild(string.format("Btn_Card%d", l)) + card.icon = string.format("ui://Main_Majiang/%s202_%d", self:GetPrefix(), fzCardInfo[j].card) + end + elseif fzCardInfo[j].type == FZType.Chi then + local item = allCardsList:AddItemFromPool("ui://Main_Majiang/Comp_FZ_3") + for l = 1, 3 do + local card = item:GetChild(string.format("Btn_Card%d", l)) + card.icon = string.format("ui://Main_Majiang/%s202_%d", self:GetPrefix(), fzCardInfo[j].opcard + [l]) + end + elseif fzCardInfo[j].type == FZType.Gang or fzCardInfo[j].type == FZType.Gang_An or fzCardInfo[j].type == FZType.Gang_Peng then + local item = allCardsList:AddItemFromPool("ui://Main_Majiang/Comp_FZ_4") + for l = 1, 4 do + local card = item:GetChild(string.format("Btn_Card%d", l)) + if fzCardInfo[j].type == FZType.Gang_An and j == 4 then + card.icon = "ui://Main_Majiang/202_00" + else + card.icon = string.format("ui://Main_Majiang/%s202_%d", self:GetPrefix(), fzCardInfo[j].card) + end + end + end + end + + local handCardItem = allCardsList:AddItemFromPool("ui://Main_Majiang/Comp_HandCard") + local handCardList = handCardItem:GetChild("list") + handCardList:SetVirtual() + handCardList.itemRenderer = function(index, obj) + obj.icon = string.format("ui://Main_Majiang/%s202_%d", self:GetPrefix(), infoList.hand_card[index + 1]) + end + handCardList.numItems = handInfoNum + allCardsList.width = 172 * fzInfoNum + 60 + (handInfoNum - 1) * 56 + 36 * (fzInfoNum) + + if infoList.seat == room.self_player.seat then + isMeCtr.selectedIndex = 1 + end + + if infoList.is_win then + local winInfo = "" + for j = 1, #infoList.win_list do + winInfo = string.format("%s,%s", winInfo, Hu_Type_Name[infoList.win_list[j].type]) + end + winInfo = string.sub(winInfo, 2, -1) + playerInfoComp:GetChild("text_huShow").text = winInfo + + if room.isZiMoHu then + ziMoCtr.selectedIndex = 1 + end + + huCardBtn.icon = string.format("ui://Main_Majiang/202_%d", infoList.win_card) + huCardBtn.visible = true + + jiangMaList.visible = false + else + playerInfoComp:GetChild("text_huShow").text = "" + if not room.isZiMoHu and playInfo.self_user.account_id == result.active_player then + dianPaoCtr.selectedIndex = 1 + end + + huCardBtn.visible = false + jiangMaList.visible = false + end + end end -function M:FillItemData(room, data, item, active_player, niao) - local _gamectr = ControllerManager.GetController(GameController) - local p = room:GetPlayerBySeat(data["seat"]) - item:GetChild("playerName").text = p.self_user.nick_name - item:GetChild("lab_hp").text = "" --抓马 - local user = room:GetPlayerBySeat(data["seat"]).self_user - local head = item:GetChild('head'):GetChild('n4') - ImageLoad.Load(user.head_url, head) +function M:fillResult1(room, peopleNum, total_result) + local gameNameAndRoomIDText = self._view:GetChild("Text_GameNameAndRoomID") + local familyIDText = self._view:GetChild("Text_FamilyID") + for i, v in pairs(room.self_player.self_user.games) do + if v.game_id == room.game_id then + gameNameAndRoomIDText.text = string.format("%s 房号:%s", v.name, room.room_id) + end + end + if #gameNameAndRoomIDText.text <= 0 then + gameNameAndRoomIDText.text = string.format("房号:%s", room.room_id) + end + if room.group_id ~= 0 then + familyIDText.text = string.format("俱乐部:%s", room.group_id) + else + familyIDText.visible = false + end + self._view:GetChild("Text_RoundNum").text = string.format("局数:%s/%s", room.curren_round, room.room_config.round) + self._view:GetChild("Text_Time").text = os.date("%Y-%m-%d %H:%M:%S", os.time()) - -- 手牌 - local hand_cards = data["hand_card"] - table.sort(hand_cards, ViewUtil.HandCardSort) - local hand_list_view = item:GetChild("hand_card_list") - hand_list_view:RemoveChildrenToPool() - for i = 1, #hand_cards do - local card = hand_list_view:AddItemFromPool() - card.icon = "ui://Main_Majiang/202_" .. hand_cards[i] - end - hand_list_view.width = 52 * #hand_cards + for i = 1, peopleNum do + local resultInfoComp = self._view:GetChild(string.format("Comp_ResultInfo%d", i)) + local totalInfoList = total_result.info_list[i] + local playInfo = room:GetPlayerBySeat(totalInfoList.seat) - local fz_card = p.fz_list - local fz_card_list = item:GetChild("fz_card_list") - fz_card_list.width = 157 * #fz_card * 0.8 - fz_card_list:RemoveChildrenToPool() + self:fillHead(playInfo.self_user.head_url, resultInfoComp) - for i = 1, #fz_card do - if fz_card[i].type == FZType.Peng then - local item = fz_card_list:AddItemFromPool("ui://Main_Majiang/clearing_fz_3") - for j = 1, 3 do - local card = item:GetChild("card_" .. j) - card.icon = "ui://Main_Majiang/202_" .. fz_card[i].card - end - elseif fz_card[i].type == FZType.Chi then - local item = fz_card_list:AddItemFromPool("ui://Main_Majiang/clearing_fz_3") - for j = 1, 3 do - local card = item:GetChild("card_" .. j) - card.icon = "ui://Main_Majiang/" .. self:GetPrefix() .. "202_" .. fz_card[i].opcard[j] - end - elseif fz_card[i].type == FZType.Gang or fz_card[i].type == FZType.Gang_An or fz_card[i].type == FZType.Gang_Peng then - local item = fz_card_list:AddItemFromPool("ui://Main_Majiang/clearing_fz_4") - for j = 1, 4 do - local card = item:GetChild("card_" .. j) - if fz_card[i].type == FZType.Gang_An and j == 4 then - card.icon = "ui://Main_Majiang/202_00" - else - card.icon = "ui://Main_Majiang/202_" .. fz_card[i].card - end - end - end - end + resultInfoComp:GetChild('Text_Name').text = playInfo.self_user.nick_name + resultInfoComp:GetChild('Text_ID').text = string.format("ID:%s", playInfo.self_user.account_id) + resultInfoComp:GetChild('Text_TotalScore').text = totalInfoList.total_score >= 0 and + string.format("+%s", totalInfoList.total_score) or totalInfoList.total_score + resultInfoComp:GetChild('Text_ZiMo').text = string.format("自摸 %d次", totalInfoList.settle_log.zimo or 0) + resultInfoComp:GetChild('Text_JiePao').text = string.format("接炮 %d次", totalInfoList.settle_log.jiepao or 0) + resultInfoComp:GetChild('Text_FangPao').text = string.format("放炮 %d次", totalInfoList.settle_log.fangpao or 0) + resultInfoComp:GetChild('Text_AnGang').text = string.format("暗杠 %d次", totalInfoList.settle_log.an_kong or 0) + resultInfoComp:GetChild('Text_MingGang').text = string.format("明杠 %d次", + totalInfoList.settle_log.ming_kong or 0) + resultInfoComp:GetChild('Text_FangGang').text = string.format("放杠 %d次", + totalInfoList.settle_log.fanggang or 0) - local huadd = data["hu_score"] - local gangadd = data["gang_score"] - local jingadd = data["jing_score"] - local total = data["round_score"] - local geng_zhuan = data["geng_zhuan"] - local sp = " " - local str = "胡:" .. huadd .. "分" - if gangadd then - str = str .. sp .. "杠:" .. gangadd .. "分" - end - if jingadd then - str = str .. sp .. "博精:" .. jingadd .. "分" - end - - - - - - item:GetChild("score1").text = str - -- local total_score = data["total_score"] - if total >= 0 then - item:GetChild("score2").text = "+" .. total - item:GetChild("score2").grayed = false - else - item:GetChild("score2").text = total - item:GetChild("score2").grayed = true - end - - - --计算牌型 - local totalPeson = DataManager.CurrenRoom.room_config.people_num - 1 - local win_list = data["win_list"] - local is_win = data["is_win"] or false - local str1 = "" - sp = "、" - if is_win then - if win_list then - if DataManager.CurrenRoom.isZiMoHu then - str1 = "自摸" - else - str1 = "接炮" - end - for i = 1, #win_list do - local huName = Hu_Type_Name[win_list[i].type] - if huName then - str1 = str1 .. sp .. huName .. "x" .. win_list[i].score - end - end - str1 = str1 .. " +" .. huadd .. "分" - end - else - printlog("输家============") - if DataManager.CurrenRoom.isZiMoHu then - printlog("自摸处理============") - --str1="" - if #self.WinList == 1 then - for i = 1, #self.WinList do - for j = 1, #self.WinList[i] do - local huName = Hu_Type_Name[self.WinList[i][j].type] - if huName then - if j == 1 then - str1 = str1 .. huName .. "x" .. self.WinList[i][j].score - else - str1 = str1 .. sp .. huName .. "x" .. self.WinList[i][j].score - end - end - end - end - str1 = str1 .. " " .. huadd .. "分" - else - printlog("服务端自摸计算异常===>>>") - end - else - printlog("非自摸处理====>>>") - --点炮 一炮多响 - local yipaoduoxiang = false - if #self.WinList > 1 then - yipaoduoxiang = true - end - - if yipaoduoxiang then - printlog("一炮多响====>>>") - str = "点炮" - local allTypeList = {} - local isHas = false - for i = 1, #self.WinList do - for j = 1, #self.WinList[i] do - isHas = IsHasDictionary(self.WinList[i][j].type, allTypeList) - if isHas == false then - table.insert(allTypeList, self.WinList[i][j].type) - end - end - end - - if #allTypeList > 0 then - for i = 1, #allTypeList do - local huName = Hu_Type_Name[allTypeList[i]] - if huName then - str1 = str1 .. huName .. "、" - end - end - str1 = str1 .. " " .. huadd .. "分" - end - else - if p.self_user.account_id == active_player and is_win == false and not data["liuju"] then - str1 = "点炮" - if #self.WinList == 1 then - for i = 1, # self.WinList do - for j = 1, #self.WinList[i] do - local huName = Hu_Type_Name[self.WinList[i][j].type] - if huName then - str1 = str1 .. sp .. huName .. "x" .. self.WinList[i][j].score - end - end - end - str1 = str1 .. " " .. huadd .. "分" - else - printlog("服务端自摸计算异常===>>>") - end - end - end - end - end - - -- - printlog("牌型计算==>>>", str1) - - if data["ming_gang_num"] > 0 then - str1 = str1 .. " 明杠x" .. data["ming_gang_num"] - end - - if data["an_gang_num"] > 0 then - str1 = str1 .. " 暗杠x" .. data["an_gang_num"] - end - - if data["dian_gang_num"] > 0 then - str1 = str1 .. " 点杠x" .. data["dian_gang_num"] - end - - if gangadd ~= 0 then - if gangadd > 0 then - str1 = str1 .. " +" .. gangadd .. "分" - else - str1 = str1 .. " " .. gangadd .. "分" - end - end - - if data["ma_geng_gong"] and data["ma_geng_gong"] ~= 0 then - if data["ma_geng_gong"] > 0 then - str1 = str1 .. " 马跟杠:+" .. data["ma_geng_gong"] .. "分" - else - str1 = str1 .. " 马跟杠:" .. data["ma_geng_gong"] .. "分" - end - end - - if geng_zhuan and geng_zhuan ~= 0 then - if geng_zhuan > 0 then - str1 = str1 .. " 跟庄:+" .. geng_zhuan .. "分" - else - str1 = str1 .. " 跟庄:" .. geng_zhuan .. "分" - end - end - - - - - - item:GetChild("score3").text = str1 - item:GetChild("score4").text = str1 - local paixingCtr = item:GetController("detail") - table.insert(self.PaiXingXiangQingCtrList, paixingCtr) - ------------------------- - - local hp_nonnegative = room:checkHpNonnegative() - item:GetController("nonnegative").selectedIndex = hp_nonnegative and 1 or 0 - if hp_nonnegative then - local hp_info = data.hp_info - local ctr_hp_limit = item:GetController("hp_limit") - local hp = d2ad(hp_info.round_actual_hp) - if hp >= 0 then hp = "+" .. tostring(hp) end - item:GetChild("tex_hp").text = hp - ctr_hp_limit.selectedIndex = hp_info.upper_limit and 1 or 0 - end - - - item:GetController("win").selectedIndex = is_win and 0 or 1 - if p.self_user.account_id == active_player and is_win == false and total < 0 then - item:GetController("win").selectedIndex = 2 - end - - if is_win then - item:GetController("bg").selectedIndex = 1 - else - item:GetController("bg").selectedIndex = 0 - end - local win_card = item:GetChild("win_card") - win_card.icon = "ui://Main_Majiang/202_" .. data["win_card"] - - if niao and #niao > 0 then - local currentNiaoList = self:CalculateNiao(niao, data["seat"]) - if currentNiaoList and #currentNiaoList > 0 then - local lst_niao = item:GetChild("list_niao") - lst_niao:RemoveChildrenToPool() - for i = 1, #currentNiaoList do - if currentNiaoList[i].score > 0 then - local card_niao = lst_niao:AddItemFromPool() - card_niao.icon = "ui://Main_Majiang/202_" .. currentNiaoList[i].card - end - end - end - end - - - - if p.seat == room.banker_seat then - item:GetController("bank").selectedIndex = 1 - end + resultInfoComp:GetController("win").selectedIndex = totalInfoList.total_score >= 0 and 1 or 0 + end end -function M:CalculateNiao(niaoList, seat) - local tempNiao = {} - for i = 1, #niaoList do - if niaoList[i].seat == seat then - table.insert(tempNiao, niaoList[i]) - end - end - return tempNiao -end - -function M:FillItemData2(room, data, list) - -- 赋值result_info,聊天室分享需要 - local player_list = {} - for i = 1, #data do - player_list[i] = {} - local user = room:GetPlayerBySeat(data[i].seat).self_user - player_list[i].id = user.account_id - player_list[i].hp_info = data[i].hp_info - player_list[i].score = data[i].total_score - player_list[i].house = room.owner_id == player_list[i].id and 1 or 0 - player_list[i].nick = user.nick_name - player_list[i].head_url = user.head_url - - local settle_log = data[i].settle_log - player_list[i].param = {} - player_list[i].param[1] = {} - player_list[i].param[1].key = "自摸次数:" - player_list[i].param[1].value = tostring(data[i].settle_log.zimo) - player_list[i].param[2] = {} - player_list[i].param[2].key = "接炮次数:" - player_list[i].param[2].value = tostring(data[i].settle_log.jie_pao) - player_list[i].param[3] = {} - player_list[i].param[3].key = "点炮次数:" - player_list[i].param[3].value = tostring(data[i].settle_log.dian_pao) - player_list[i].param[4] = {} - player_list[i].param[4].key = "暗杠次数:" - player_list[i].param[4].value = tostring(data[i].settle_log.an_kong) - player_list[i].param[5] = {} - player_list[i].param[5].key = "明杠次数:" - player_list[i].param[5].value = tostring(data[i].settle_log.ming_kong) - end - - local round = room.room_config.round - self:GenerateRoomResultInfo(round, room.room_config:GetGameName(), room.room_id, room.create_time, player_list) - local big_result = self._view:GetChild("big_result") - big_result:GetChild("txt_room_info").text = string.format("%s 房号%s 局%s/%s", os.date("%Y/%m/%d", os.time()), - room.room_id, room.curren_round, room.room_config.round) - local lst_p = big_result:GetChild("player_list") - if #player_list == 3 then - lst_p.columnGap = 108 - elseif #player_list == 2 then - lst_p.columnGap = 208 - end - - self:InitBigResult(room, 30) - local show_detail = room.hpOnOff == 1 - for i = 1, lst_p.numChildren do - local com_p = lst_p:GetChildAt(i - 1) - com_p:GetController("jsicon").selectedIndex = i - 1 - local list_param = com_p:GetChild("list_param") - for j = 1, list_param.numChildren do - local tem = list_param:GetChildAt(j - 1) - tem:GetChild("txt_value").textFormat.size = 30 - end - if show_detail then - local score = 0 - if com_p:GetController("pn").selectedIndex == 0 then - score = com_p:GetChild("txt_navigate").text - else - score = com_p:GetChild("txt_positive").text - end - score = score / room.score_times - com_p:GetChild("tex_detail_score").text = string.format("%s × %s倍", score, room.score_times) - end - end - - if room.group_id ~= 0 then - big_result:GetController("group").selectedIndex = 1 - end - DataManager.CurrenRoom = nil -end - -function M:LoadHead(p, room) - local btn_head = self._view:GetChild("btn_head") - for i = 1, #room.player_list do - local player = room.player_list[i] - if p.seat == player.seat and player.self_user.head_url ~= "" then - ImageLoad.Load(player.self_user.head_url, btn_head.icon) - end - end +function M:fillHead(url, view) + ImageLoad.Load(url, view:GetChild("Btn_Head")._iconObject) end local prefix function M:GetPrefix() - -- if not prefix then - prefix = get_majiang_prefix(10) - -- end - return prefix + -- if not prefix then + prefix = get_majiang_prefix(10) + -- end + return prefix end function M:DestroyWithCallback() - if self._callback then - self._callback() - end - self:Destroy() + if self._callback then + self._callback() + end + self:Destroy() end return M diff --git a/lua_probject/extend_project/extend/majiang/lichuan/EXClearingView_JiangXi.lua b/lua_probject/extend_project/extend/majiang/lichuan/EXClearingView_JiangXi.lua deleted file mode 100644 index ba6a4d1d..00000000 --- a/lua_probject/extend_project/extend/majiang/lichuan/EXClearingView_JiangXi.lua +++ /dev/null @@ -1,605 +0,0 @@ -require("Game.View.ResultView") -local Hu_Type_Name = import(".CS_Win_Type") - -local EXClearingView = {} - -local M = EXClearingView - -function EXClearingView.new(blur_view) - setmetatable(M, { __index = ResultView }) - local self = setmetatable({}, { __index = M }) - self._full = true - ResultView.init(self, "ui://Main_Majiang/clearing_jiangxi") - - self._currenIndex = 0 - self._blur_view = blur_view - self._close_zone = false - self:InitMaPai() - - return self -end - -function M:InitMaPai() - self.maPaiCtr = self._view:GetController("mapai") - self.maPaiCtr.selectedIndex = 0 - - self.maPaiList = {} - - for i = 1, 8 do - local tempMP = self._view:GetChild("niao" .. i) - table.insert(self.maPaiList, tempMP) - end -end - -function M:IsMapaiShow(niao, isShow) - if niao then - niao.visible = isShow - end -end - -function M:SetMaPaiValue(niao, value) - if niao then - niao.icon = 'ui://Main_Majiang/' .. get_majiang_prefix(DataManager.CurrenRoom.game_id) .. "201_" .. value - end -end - -function M:SetMaPaiColor(niao, num) - niao:GetController("color").selectedIndex = num -end - -function M:HideAllMapai() - for i = 1, #self.maPaiList do - self:IsMapaiShow(self.maPaiList[i], false) - self:SetMaPaiColor(self.maPaiList[i], 0) - end -end - -function M:ShowSelectMaPai(niaoList) - if niaoList and #niaoList > 0 then - self.maPaiCtr.selectedIndex = 1 - self:HideAllMapai() - for i = 1, #niaoList do - self:IsMapaiShow(self.maPaiList[i], true) - self:SetMaPaiValue(self.maPaiList[i], niaoList[i].card) - if niaoList[i].score > 0 then - self:SetMaPaiColor(self.maPaiList[i], 2) - end - end - else - self.maPaiCtr.selectedIndex = 0 - end -end - -function M:CalculatePaixingInfo(result) - self.WinList = {} - if result.info_list and #result.info_list > 0 then - for i = 1, #result.info_list do - if result.info_list[i].win_list and #result.info_list[i].win_list > 0 then - table.insert(self.WinList, result.info_list[i].win_list) - end - end - end - - printlog("牌型列表====>>>") - pt(self.WinList) -end - -function M:SetPaixingxiangqing(num) - for i = 1, #self.PaiXingXiangQingCtrList do - if self.PaiXingXiangQingCtrList[i] then - self.PaiXingXiangQingCtrList[i].selectedIndex = num - end - end -end - -function M:InitData(over, room, result, total_result, callback) - self._callback = callback - local _overCtr = self._view:GetController("over") - local btn_confirm = self._view:GetChild("btn_confirm") - local btn_result = self._view:GetChild("btn_showResult") - local btn_close = self._view:GetChild("big_result"):GetChild("btn_close") - local _btnCtr = self._view:GetController("button") - local _sdkCtr = self._view:GetController("sdk") - local ctr_type = self._view:GetController("type") - - self._view:GetChild("tex_roominfo").text = string.format("房号%s 局%s/%s %s", room.room_id, room.curren_round, - room.room_config.round, os.date("%Y-%m-%d %H:%M:%S", os.time())) - self._view:GetChild("tex_gameinfo").text = string.gsub(room.room_config:GetDes2(), "\r", "") - - if result then - self:ShowSelectMaPai(result.niao) - self:CalculatePaixingInfo(result) - end - - self.PaiXingXiangQingCtrList = {} - - local paixingxiangqing = self._view:GetChild("btn_detal") - local fanhuipaixing = self._view:GetChild("btn_fanhuipaixing") - fanhuipaixing.visible = false - paixingxiangqing.visible = true - paixingxiangqing.onClick:Add(function() - paixingxiangqing.visible = false - fanhuipaixing.visible = true - self:SetPaixingxiangqing(1) - end) - fanhuipaixing.onClick:Add(function() - paixingxiangqing.visible = true - fanhuipaixing.visible = false - self:SetPaixingxiangqing(0) - end) - - - if over ~= 2 then - if result.liuju then - ctr_type.selectedIndex = 3 - else - local info_list = result.info_list - for i = 1, #info_list do - local is_win = info_list[i].is_win - if is_win then - if info_list[i].seat == room.self_player.seat then - ctr_type.selectedIndex = 1 - else - ctr_type.selectedIndex = 2 - end - end - end - end - - if over == 0 then - _btnCtr.selectedIndex = 0 - _sdkCtr.selectedIndex = 1 - btn_confirm.onClick:Add(function() - local _gamectr = ControllerManager.GetController(GameController) - _gamectr:PlayerReady() - self:DestroyWithCallback() - end) - self:AddClearItem(room, result.info_list, nil, over, result.niao, result.active_player) - elseif over == 1 then - _btnCtr.selectedIndex = 1 - _sdkCtr.selectedIndex = 1 - btn_result.onClick:Add(function() - self.maPaiCtr.selectedIndex = 0 - _overCtr.selectedIndex = 1 - _btnCtr.selectedIndex = 0 - _sdkCtr.selectedIndex = 0 - if self._qsinfo_view then - self._qsinfo_view:Dispose() - end - end) - btn_close.onClick:Add(function() - ViewManager.ChangeView(ViewManager.View_Lobby) - end) - - self:AddClearItem(room, result.info_list, total_result.info_list, over, result.niao, result.active_player) - end - else - _overCtr.selectedIndex = 1 - self.maPaiCtr.selectedIndex = 0 - btn_close.onClick:Add(function() - ViewManager.ChangeView(ViewManager.View_Lobby) - end) - - self:AddClearItem(room, nil, total_result.info_list, over) - end - -----------------------lingmeng---------------------------- - local showClearMainBtn = self._view:GetChild("btn_showClearMain") - local nextRoundBtn = self._view:GetChild("btn_nextRound") - local MainCtr = self._view:GetController("main") - - showClearMainBtn.onClick:Set(function() - MainCtr.selectedIndex = 1 - end) - - nextRoundBtn.onClick:Set(function() - local _gamectr = ControllerManager.GetController(GameController) - _gamectr:PlayerReady() - self:DestroyWithCallback() - end) - ----------------------------------------------------------- -end - -function M:AddClearItem(room, data, total_data, over, niao, active_player) - local n = over + 1 - local list_view1 = self._view:GetChild("player_list_1") - local list_view2 = self._view:GetChild("player_list_2") - - if 0 == over or 1 == over then - table.sort(data, function(a, b) return a.seat < b.seat end) - list_view1:RemoveChildrenToPool() - - for i = 1, #data do - local item = list_view1:AddItemFromPool() - self:FillItemData(room, data[i], item, active_player, niao) - end - if #data == 3 then - list_view1.lineGap = 54 - elseif #data == 2 then - list_view1.lineGap = 108 - end - if 1 == over then - self:FillItemData2(room, total_data, list_view2) - end - elseif 2 == over then - self:FillItemData2(room, total_data, list_view2) - end -end - -function M:FillItemData(room, data, item, active_player, niao) - local _gamectr = ControllerManager.GetController(GameController) - local p = room:GetPlayerBySeat(data["seat"]) - item:GetChild("playerName").text = p.self_user.nick_name - item:GetChild("lab_hp").text = "" --抓马 - local user = room:GetPlayerBySeat(data["seat"]).self_user - local head = item:GetChild('head'):GetChild('n4') - ImageLoad.Load(user.head_url, head) - - -- 手牌 - local hand_cards = data["hand_card"] - table.sort(hand_cards, ViewUtil.HandCardSort) - local hand_list_view = item:GetChild("hand_card_list") - hand_list_view:RemoveChildrenToPool() - for i = 1, #hand_cards do - local card = hand_list_view:AddItemFromPool() - card.icon = "ui://Main_Majiang/202_" .. hand_cards[i] - end - hand_list_view.width = 52 * #hand_cards - - local fz_card = p.fz_list - local fz_card_list = item:GetChild("fz_card_list") - fz_card_list.width = 157 * #fz_card * 0.8 - fz_card_list:RemoveChildrenToPool() - - for i = 1, #fz_card do - if fz_card[i].type == FZType.Peng then - local item = fz_card_list:AddItemFromPool("ui://Main_Majiang/clearing_fz_3") - for j = 1, 3 do - local card = item:GetChild("card_" .. j) - card.icon = "ui://Main_Majiang/202_" .. fz_card[i].card - end - elseif fz_card[i].type == FZType.Chi then - local item = fz_card_list:AddItemFromPool("ui://Main_Majiang/clearing_fz_3") - for j = 1, 3 do - local card = item:GetChild("card_" .. j) - card.icon = "ui://Main_Majiang/" .. self:GetPrefix() .. "202_" .. fz_card[i].opcard[j] - end - elseif fz_card[i].type == FZType.Gang or fz_card[i].type == FZType.Gang_An or fz_card[i].type == FZType.Gang_Peng then - local item = fz_card_list:AddItemFromPool("ui://Main_Majiang/clearing_fz_4") - for j = 1, 4 do - local card = item:GetChild("card_" .. j) - if fz_card[i].type == FZType.Gang_An and j == 4 then - card.icon = "ui://Main_Majiang/202_00" - else - card.icon = "ui://Main_Majiang/202_" .. fz_card[i].card - end - end - end - end - - local huadd = data["hu_score"] - local gangadd = data["gang_score"] - local jingadd = data["jing_score"] - local total = data["round_score"] - local geng_zhuan = data["geng_zhuan"] - local sp = " " - local str = "胡:" .. huadd .. "分" - if gangadd then - str = str .. sp .. "杠:" .. gangadd .. "分" - end - if jingadd then - str = str .. sp .. "博精:" .. jingadd .. "分" - end - - - - - - item:GetChild("score1").text = str - -- local total_score = data["total_score"] - if total >= 0 then - item:GetChild("score2").text = "+" .. total - item:GetChild("score2").grayed = false - else - item:GetChild("score2").text = total - item:GetChild("score2").grayed = true - end - - - --计算牌型 - local totalPeson = DataManager.CurrenRoom.room_config.people_num - 1 - local win_list = data["win_list"] - local is_win = data["is_win"] or false - local str1 = "" - sp = "、" - if is_win then - if win_list then - if DataManager.CurrenRoom.isZiMoHu then - str1 = "自摸" - else - str1 = "接炮" - end - for i = 1, #win_list do - local huName = Hu_Type_Name[win_list[i].type] - if huName then - str1 = str1 .. sp .. huName .. "x" .. win_list[i].score - end - end - str1 = str1 .. " +" .. huadd .. "分" - end - else - printlog("输家============") - if DataManager.CurrenRoom.isZiMoHu then - printlog("自摸处理============") - --str1="" - if #self.WinList == 1 then - for i = 1, #self.WinList do - for j = 1, #self.WinList[i] do - local huName = Hu_Type_Name[self.WinList[i][j].type] - if huName then - if j == 1 then - str1 = str1 .. huName .. "x" .. self.WinList[i][j].score - else - str1 = str1 .. sp .. huName .. "x" .. self.WinList[i][j].score - end - end - end - end - str1 = str1 .. " " .. huadd .. "分" - else - printlog("服务端自摸计算异常===>>>") - end - else - printlog("非自摸处理====>>>") - --点炮 一炮多响 - local yipaoduoxiang = false - if #self.WinList > 1 then - yipaoduoxiang = true - end - - if yipaoduoxiang then - printlog("一炮多响====>>>") - str = "点炮" - local allTypeList = {} - local isHas = false - for i = 1, #self.WinList do - for j = 1, #self.WinList[i] do - isHas = IsHasDictionary(self.WinList[i][j].type, allTypeList) - if isHas == false then - table.insert(allTypeList, self.WinList[i][j].type) - end - end - end - - if #allTypeList > 0 then - for i = 1, #allTypeList do - local huName = Hu_Type_Name[allTypeList[i]] - if huName then - str1 = str1 .. huName .. "、" - end - end - str1 = str1 .. " " .. huadd .. "分" - end - else - if p.self_user.account_id == active_player and is_win == false and not data["liuju"] then - str1 = "点炮" - if #self.WinList == 1 then - for i = 1, # self.WinList do - for j = 1, #self.WinList[i] do - local huName = Hu_Type_Name[self.WinList[i][j].type] - if huName then - str1 = str1 .. sp .. huName .. "x" .. self.WinList[i][j].score - end - end - end - str1 = str1 .. " " .. huadd .. "分" - else - printlog("服务端自摸计算异常===>>>") - end - end - end - end - end - - -- - printlog("牌型计算==>>>", str1) - - if data["ming_gang_num"] > 0 then - str1 = str1 .. " 明杠x" .. data["ming_gang_num"] - end - - if data["an_gang_num"] > 0 then - str1 = str1 .. " 暗杠x" .. data["an_gang_num"] - end - - if data["dian_gang_num"] > 0 then - str1 = str1 .. " 点杠x" .. data["dian_gang_num"] - end - - if gangadd ~= 0 then - if gangadd > 0 then - str1 = str1 .. " +" .. gangadd .. "分" - else - str1 = str1 .. " " .. gangadd .. "分" - end - end - - if data["ma_geng_gong"] and data["ma_geng_gong"] ~= 0 then - if data["ma_geng_gong"] > 0 then - str1 = str1 .. " 马跟杠:+" .. data["ma_geng_gong"] .. "分" - else - str1 = str1 .. " 马跟杠:" .. data["ma_geng_gong"] .. "分" - end - end - - if geng_zhuan and geng_zhuan ~= 0 then - if geng_zhuan > 0 then - str1 = str1 .. " 跟庄:+" .. geng_zhuan .. "分" - else - str1 = str1 .. " 跟庄:" .. geng_zhuan .. "分" - end - end - - - - - - item:GetChild("score3").text = str1 - item:GetChild("score4").text = str1 - local paixingCtr = item:GetController("detail") - table.insert(self.PaiXingXiangQingCtrList, paixingCtr) - ------------------------- - - local hp_nonnegative = room:checkHpNonnegative() - item:GetController("nonnegative").selectedIndex = hp_nonnegative and 1 or 0 - if hp_nonnegative then - local hp_info = data.hp_info - local ctr_hp_limit = item:GetController("hp_limit") - local hp = d2ad(hp_info.round_actual_hp) - if hp >= 0 then hp = "+" .. tostring(hp) end - item:GetChild("tex_hp").text = hp - ctr_hp_limit.selectedIndex = hp_info.upper_limit and 1 or 0 - end - - - item:GetController("win").selectedIndex = is_win and 0 or 1 - if p.self_user.account_id == active_player and is_win == false and total < 0 then - item:GetController("win").selectedIndex = 2 - end - - if is_win then - item:GetController("bg").selectedIndex = 1 - else - item:GetController("bg").selectedIndex = 0 - end - local win_card = item:GetChild("win_card") - win_card.icon = "ui://Main_Majiang/202_" .. data["win_card"] - - if niao and #niao > 0 then - local currentNiaoList = self:CalculateNiao(niao, data["seat"]) - if currentNiaoList and #currentNiaoList > 0 then - local lst_niao = item:GetChild("list_niao") - lst_niao:RemoveChildrenToPool() - for i = 1, #currentNiaoList do - if currentNiaoList[i].score > 0 then - local card_niao = lst_niao:AddItemFromPool() - card_niao.icon = "ui://Main_Majiang/202_" .. currentNiaoList[i].card - end - end - end - end - - - - if p.seat == room.banker_seat then - item:GetController("bank").selectedIndex = 1 - end -end - -function M:CalculateNiao(niaoList, seat) - local tempNiao = {} - for i = 1, #niaoList do - if niaoList[i].seat == seat then - table.insert(tempNiao, niaoList[i]) - end - end - return tempNiao -end - -function M:FillItemData2(room, data, list) - -- 赋值result_info,聊天室分享需要 - local player_list = {} - for i = 1, #data do - player_list[i] = {} - local user = room:GetPlayerBySeat(data[i].seat).self_user - player_list[i].id = user.account_id - player_list[i].hp_info = data[i].hp_info - player_list[i].score = data[i].total_score - player_list[i].house = room.owner_id == player_list[i].id and 1 or 0 - player_list[i].nick = user.nick_name - player_list[i].head_url = user.head_url - - local settle_log = data[i].settle_log - player_list[i].param = {} - player_list[i].param[1] = {} - player_list[i].param[1].key = "自摸次数:" - player_list[i].param[1].value = tostring(data[i].settle_log.zimo) - player_list[i].param[2] = {} - player_list[i].param[2].key = "接炮次数:" - player_list[i].param[2].value = tostring(data[i].settle_log.jie_pao) - player_list[i].param[3] = {} - player_list[i].param[3].key = "点炮次数:" - player_list[i].param[3].value = tostring(data[i].settle_log.dian_pao) - player_list[i].param[4] = {} - player_list[i].param[4].key = "暗杠次数:" - player_list[i].param[4].value = tostring(data[i].settle_log.an_kong) - player_list[i].param[5] = {} - player_list[i].param[5].key = "明杠次数:" - player_list[i].param[5].value = tostring(data[i].settle_log.ming_kong) - end - - local round = room.room_config.round - self:GenerateRoomResultInfo(round, room.room_config:GetGameName(), room.room_id, room.create_time, player_list) - local big_result = self._view:GetChild("big_result") - big_result:GetChild("txt_room_info").text = string.format("%s 房号%s 局%s/%s", os.date("%Y/%m/%d", os.time()), - room.room_id, room.curren_round, room.room_config.round) - local lst_p = big_result:GetChild("player_list") - if #player_list == 3 then - lst_p.columnGap = 108 - elseif #player_list == 2 then - lst_p.columnGap = 208 - end - - self:InitBigResult(room, 30) - local show_detail = room.hpOnOff == 1 - for i = 1, lst_p.numChildren do - local com_p = lst_p:GetChildAt(i - 1) - com_p:GetController("jsicon").selectedIndex = i - 1 - local list_param = com_p:GetChild("list_param") - for j = 1, list_param.numChildren do - local tem = list_param:GetChildAt(j - 1) - tem:GetChild("txt_value").textFormat.size = 30 - end - if show_detail then - local score = 0 - if com_p:GetController("pn").selectedIndex == 0 then - score = com_p:GetChild("txt_navigate").text - else - score = com_p:GetChild("txt_positive").text - end - score = score / room.score_times - com_p:GetChild("tex_detail_score").text = string.format("%s × %s倍", score, room.score_times) - end - end - - if room.group_id ~= 0 then - big_result:GetController("group").selectedIndex = 1 - end - DataManager.CurrenRoom = nil -end - -function M:LoadHead(p, room) - local btn_head = self._view:GetChild("btn_head") - for i = 1, #room.player_list do - local player = room.player_list[i] - if p.seat == player.seat and player.self_user.head_url ~= "" then - ImageLoad.Load(player.self_user.head_url, btn_head.icon) - end - end -end - -local prefix -function M:GetPrefix() - -- if not prefix then - prefix = get_majiang_prefix(10) - -- end - return prefix -end - -function M:DestroyWithCallback() - if self._callback then - self._callback() - end - self:Destroy() -end - -return M diff --git a/lua_probject/extend_project/extend/majiang/lichuan/EXGameController.lua b/lua_probject/extend_project/extend/majiang/lichuan/EXGameController.lua index 0fe2ea2c..fcc7bb8c 100644 --- a/lua_probject/extend_project/extend/majiang/lichuan/EXGameController.lua +++ b/lua_probject/extend_project/extend/majiang/lichuan/EXGameController.lua @@ -306,7 +306,7 @@ end function M:OneventResult1(evt_data) local over = evt_data.type - printlog("OneventResult1") + print("OneventResult1") pt(evt_data) --0:小结算 1:小大结算 2:大结算 self._room._reload_flag = false diff --git a/lua_probject/extend_project/extend/majiang/lichuan/EXGameInfo.lua b/lua_probject/extend_project/extend/majiang/lichuan/EXGameInfo.lua index 0f90792b..5bad5d74 100644 --- a/lua_probject/extend_project/extend/majiang/lichuan/EXGameInfo.lua +++ b/lua_probject/extend_project/extend/majiang/lichuan/EXGameInfo.lua @@ -4,181 +4,181 @@ local M = EXGameInfo function EXGameInfo.new(blur_view) - setmetatable(M, { __index = IGameInfo }) - local self = setmetatable({}, { __index = M }) - self.class = "EXGameInfo" - UIPackage.AddPackage("extend/majiang/lichuan/ui/Info_MJ_LiChuan") - return self + setmetatable(M, { __index = IGameInfo }) + local self = setmetatable({}, { __index = M }) + self.class = "EXGameInfo" + UIPackage.AddPackage("extend/majiang/lichuan/ui/Info_MJ_LiChuan") + return self end function M:FillData() - self._maxPlayer = 4 -- 默认玩家人数 - self._roundChoice = 3 -- 回合选项数 - self._config = UIPackage.CreateObjectFromURL("ui://Info_MJ_LiChuan/Label_Detail_83") + self._maxPlayer = 4 -- 默认玩家人数 + self._roundChoice = 3 -- 回合选项数 + self._config = UIPackage.CreateObjectFromURL("ui://Info_MJ_LiChuan/Label_Detail_83") - -- if oldGameVersion == 2 then - -- self._config:GetController("xipai").selectedIndex = 0 + -- if oldGameVersion == 2 then + -- self._config:GetController("xipai").selectedIndex = 0 - -- self.xipaiValueText = self._config:GetChild('xipaifen') - -- self.xipaiValueText.text = 1 - -- self.xipaiValue = 1 + -- self.xipaiValueText = self._config:GetChild('xipaifen') + -- self.xipaiValueText.text = 1 + -- self.xipaiValue = 1 - -- self.anchouValueText = self._config:GetChild('anchoufen') - -- self.anchouValueText.text = 1 - -- self.anchouValue = 1 + -- self.anchouValueText = self._config:GetChild('anchoufen') + -- self.anchouValueText.text = 1 + -- self.anchouValue = 1 - -- local btn_cr = self._config:GetChild('sdsrbtn') - -- btn_cr.onClick:Set( - -- function() - -- local gniv = GroupNumberInputView_Game.new(nil, function(num) - -- local value = limit - -- if otype == 1 then - -- value = value + ad2d(num) - -- elseif otype == -1 then - -- value = value - ad2d(num) - -- else - -- value = ad2d(num) - -- end + -- local btn_cr = self._config:GetChild('sdsrbtn') + -- btn_cr.onClick:Set( + -- function() + -- local gniv = GroupNumberInputView_Game.new(nil, function(num) + -- local value = limit + -- if otype == 1 then + -- value = value + ad2d(num) + -- elseif otype == -1 then + -- value = value - ad2d(num) + -- else + -- value = ad2d(num) + -- end - -- if value < 0 then - -- ViewUtil.ErrorTip(1, "输入数据异常!") - -- end + -- if value < 0 then + -- ViewUtil.ErrorTip(1, "输入数据异常!") + -- end - -- self.xipaiValueText.text = value / 1000 - -- self.xipaiValue = value / 1000 - -- end, 3, nil) - -- gniv:Show() - -- end - -- ) + -- self.xipaiValueText.text = value / 1000 + -- self.xipaiValue = value / 1000 + -- end, 3, nil) + -- gniv:Show() + -- end + -- ) - -- local btn_cr2 = self._config:GetChild('anchoubtn') - -- btn_cr2.onClick:Set( - -- function() - -- local gniv = GroupNumberInputView_Game.new(nil, function(num) - -- local value = limit - -- if otype == 1 then - -- value = value + ad2d(num) - -- elseif otype == -1 then - -- value = value - ad2d(num) - -- else - -- value = ad2d(num) - -- end + -- local btn_cr2 = self._config:GetChild('anchoubtn') + -- btn_cr2.onClick:Set( + -- function() + -- local gniv = GroupNumberInputView_Game.new(nil, function(num) + -- local value = limit + -- if otype == 1 then + -- value = value + ad2d(num) + -- elseif otype == -1 then + -- value = value - ad2d(num) + -- else + -- value = ad2d(num) + -- end - -- if value < 0 then - -- ViewUtil.ErrorTip(1, "输入数据异常!") - -- end + -- if value < 0 then + -- ViewUtil.ErrorTip(1, "输入数据异常!") + -- end - -- self.anchouValueText.text = value / 1000 - -- self.anchouValue = value / 1000 - -- end, 3, nil) - -- gniv:Show() - -- end - -- ) - -- end + -- self.anchouValueText.text = value / 1000 + -- self.anchouValue = value / 1000 + -- end, 3, nil) + -- gniv:Show() + -- end + -- ) + -- end end local _help_url = "ui://Info_MJ_LiChuan/Com_help" function M:GetHelpUrl() - return _help_url + return _help_url end local _icon_url = "ui://Info_MJ_LiChuan/icon" function M:GetIconUrl() - return _icon_url + return _icon_url end local _icon_url1 = "ui://Info_MJ_LiChuan/icon1" function M:GetIconUrl1() - return _icon_url1 + return _icon_url1 end local _play_list = {} function M:GetPlayList() - return _play_list + return _play_list end function M:SelectedConfigData() - local _config = self._config - local round = _config:GetController("round").selectedIndex + 1 - local people = _config:GetController("peopleNum").selectedIndex + 2 + local _config = self._config + local round = _config:GetController("round").selectedIndex + 1 + local people = _config:GetController("peopleNum").selectedIndex + 2 - local zimo = _config:GetController("ZiMo").selectedIndex - local jingbibo = _config:GetController("jingbibo").selectedIndex + local zimo = _config:GetController("ZiMo").selectedIndex + local jingbibo = _config:GetController("jingbibo").selectedIndex - local xi_pai = false - local xi_paifen = 0 - if _config:GetChild("xipai") then - xi_pai = _config:GetChild("xipai").selected - end + local xi_pai = false + local xi_paifen = 0 + if _config:GetChild("xipai") then + xi_pai = _config:GetChild("xipai").selected + end - ------ - local _data = {} - _data["opt"] = round - _data["maxPlayers"] = people + ------ + local _data = {} + _data["opt"] = round + _data["maxPlayers"] = people - _data["zimo"] = zimo - _data["jingbibo"] = jingbibo - _data["jiangma"] = 0 + _data["zimo"] = zimo + _data["jingbibo"] = jingbibo + _data["jiangma"] = 0 - _data['xi_pai'] = xi_pai + _data['xi_pai'] = xi_pai - local xi_pai_score = 0 - local an_chou_score = 0 - -- if oldGameVersion == 2 then - -- xi_pai_score = self.xipaiValue - -- an_chou_score = self.anchouValue - -- end + local xi_pai_score = 0 + local an_chou_score = 0 + -- if oldGameVersion == 2 then + -- xi_pai_score = self.xipaiValue + -- an_chou_score = self.anchouValue + -- end - _data['xi_pai_score'] = xi_pai_score * 1000 - _data['an_chou_score'] = an_chou_score * 1000 + _data['xi_pai_score'] = xi_pai_score * 1000 + _data['an_chou_score'] = an_chou_score * 1000 - return _data + return _data end function M:LoadConfigData(data) - --printlog("加载房间配置=========>>>") - --pt(data) - local _config = self._config - _config:GetController("round").selectedIndex = data.opt - 1 - _config:GetController("play_list").selectedIndex = data.maxPlayers - 2 + --printlog("加载房间配置=========>>>") + --pt(data) + local _config = self._config + _config:GetController("round").selectedIndex = data.opt - 1 + _config:GetController("play_list").selectedIndex = data.maxPlayers - 2 - _config:GetController("fengding").selectedIndex = data.fengding + _config:GetController("fengding").selectedIndex = data.fengding - _config:GetController("wanfa").selectedIndex = data.wanfa - _config:GetChild("btn_qidui").selected = data.qiduijiafan - _config:GetChild("btn_shoudailong").selected = data.shoudailongjiafan - _config:GetChild("btn_loudilong").selected = data.loudilongjiafan - _config:GetChild("btn_bunengchi").selected = data.bunengchi + _config:GetController("wanfa").selectedIndex = data.wanfa + _config:GetChild("btn_qidui").selected = data.qiduijiafan + _config:GetChild("btn_shoudailong").selected = data.shoudailongjiafan + _config:GetChild("btn_loudilong").selected = data.loudilongjiafan + _config:GetChild("btn_bunengchi").selected = data.bunengchi - _config:GetChild("btn_doudizhu").selected = data.doudizhu - _config:GetChild("btn_doudizhufanbei").selected = data.doudizhufanbei + _config:GetChild("btn_doudizhu").selected = data.doudizhu + _config:GetChild("btn_doudizhufanbei").selected = data.doudizhufanbei - if _config:GetChild("xipai") then - _config:GetChild("xipai").selected = data.xi_pai - end + if _config:GetChild("xipai") then + _config:GetChild("xipai").selected = data.xi_pai + end - if oldGameVersion == 2 then - self.xipaiValueText.text = data.xi_pai_score / 1000 - self.xipaiValue = data.xi_pai_score / 1000 + if oldGameVersion == 2 then + self.xipaiValueText.text = data.xi_pai_score / 1000 + self.xipaiValue = data.xi_pai_score / 1000 - self.anchouValueText.text = data.an_chou_score / 1000 - self.anchouValue = data.an_chou_score / 1000 - end + self.anchouValueText.text = data.an_chou_score / 1000 + self.anchouValue = data.an_chou_score / 1000 + end end function M:LoadConfigToDetail(data) - local configData = json.decode(data) - local returnString = string.format("人数%s人%s%s,%s", configData.maxPlayers, - configData.zimo and ",只能自摸" or ",自摸可点炮", - configData.tuoguan and string.format(",%d秒后自动托管", configData.tuoguan_active_time) or "不能托管", - configData.jingbibo and "有精必博" or "有精可胡") - return returnString + local configData = json.decode(data) + local returnString = string.format("人数%s人,%s,%s,%s", configData.maxPlayers, + configData.zimo and "只能自摸" or "自摸可点炮", + configData.tuoguan and string.format("%d秒后自动托管", configData.tuoguan_active_time) or "不能托管", + configData.jingbibo and "有精必博" or "有精可胡") + return returnString end return M diff --git a/lua_probject/extend_project/extend/majiang/lichuan/EXMainView.lua b/lua_probject/extend_project/extend/majiang/lichuan/EXMainView.lua index 55447365..3ac5d2a8 100644 --- a/lua_probject/extend_project/extend/majiang/lichuan/EXMainView.lua +++ b/lua_probject/extend_project/extend/majiang/lichuan/EXMainView.lua @@ -1,7 +1,7 @@ local MJPlayerSelfCardInfoView = import(".MJPlayerSelfCardInfoView") local MJPlayerCardInfoView = require("main.majiang.MJPlayerCardInfoView") local MJMainView = require("main.majiang.MJMainView") -local EXClearingView = import(".EXClearingView_JiangXi") +local EXClearingView = import(".EXClearingView") local TX_GameEvent = import(".GameEvent") local HuTipView = import("main.majiang.HuTipView") local SettingView = import(".EXSettingView") @@ -473,7 +473,7 @@ function M:EventInit() -- info:UpdateScore() info._view:GetChild("zhanji").visible = true local num = data[i].hp_info.total_hp - if num > 0 then + if num >= 0 then info._view:GetController("text_color").selectedIndex = 0 info._view:GetChild("text_jifen").text = "+" .. d2ad(num) else diff --git a/lua_probject/tolua_project/cjson/util.lua b/lua_probject/tolua_project/cjson/util.lua index dceb34cd..6916dad0 100644 --- a/lua_probject/tolua_project/cjson/util.lua +++ b/lua_probject/tolua_project/cjson/util.lua @@ -186,7 +186,7 @@ local function run_test(testname, func, input, should_work, output) if status ~= nil then name = name .. statusmap[status] end - -- print(("[%s] %s"):format(name, serialise_value(value, false))) + print(("[%s] %s"):format(name, serialise_value(value, false))) end local result = { pcall(func, unpack(input)) } @@ -200,7 +200,7 @@ local function run_test(testname, func, input, should_work, output) test_count_total = test_count_total + 1 local teststatus = { [true] = "PASS", [false] = "FAIL" } - -- print(("==> Test [%d] %s: %s"):format(test_count_total, testname, + print(("==> Test [%d] %s: %s"):format(test_count_total, testname, teststatus[correct])) status_line("Input", nil, input) @@ -208,7 +208,7 @@ local function run_test(testname, func, input, should_work, output) status_line("Expected", should_work, output) end status_line("Received", success, result) - -- print() + print() return correct, result end @@ -216,11 +216,11 @@ end local function run_test_group(tests) local function run_helper(name, func, input) if type(name) == "string" and #name > 0 then - -- print("==> " .. name) + print("==> " .. name) end -- Not a protected call, these functions should never generate errors. func(unpack(input or {})) - -- print() + print() end for _, v in ipairs(tests) do diff --git a/lua_probject/tolua_project/event.lua b/lua_probject/tolua_project/event.lua index a2060905..72086794 100644 --- a/lua_probject/tolua_project/event.lua +++ b/lua_probject/tolua_project/event.lua @@ -18,49 +18,49 @@ local ilist = ilist local _xpcall = {} _xpcall.__call = function(self, ...) - if jit then - if nil == self.obj then - return xpcall(self.func, traceback, ...) - else - return xpcall(self.func, traceback, self.obj, ...) - end - else - local args = { ... } + if jit then + if nil == self.obj then + return xpcall(self.func, traceback, ...) + else + return xpcall(self.func, traceback, self.obj, ...) + end + else + local args = { ... } - if nil == self.obj then - local func = function() self.func(unpack(args, 1, maxn(args))) end - return xpcall(func, traceback) - else - local func = function() self.func(self.obj, unpack(args, 1, maxn(args))) end - return xpcall(func, traceback) - end - end + if nil == self.obj then + local func = function() self.func(unpack(args, 1, maxn(args))) end + return xpcall(func, traceback) + else + local func = function() self.func(self.obj, unpack(args, 1, maxn(args))) end + return xpcall(func, traceback) + end + end end _xpcall.__eq = function(lhs, rhs) - return lhs.func == rhs.func and lhs.obj == rhs.obj + return lhs.func == rhs.func and lhs.obj == rhs.obj end local function xfunctor(func, obj) - return setmetatable({ func = func, obj = obj }, _xpcall) + return setmetatable({ func = func, obj = obj }, _xpcall) end local _pcall = {} _pcall.__call = function(self, ...) - if nil == self.obj then - return pcall(self.func, ...) - else - return pcall(self.func, self.obj, ...) - end + if nil == self.obj then + return pcall(self.func, ...) + else + return pcall(self.func, self.obj, ...) + end end _pcall.__eq = function(lhs, rhs) - return lhs.func == rhs.func and lhs.obj == rhs.obj + return lhs.func == rhs.func and lhs.obj == rhs.obj end local function functor(func, obj) - return setmetatable({ func = func, obj = obj }, _pcall) + return setmetatable({ func = func, obj = obj }, _pcall) end local _event = {} @@ -68,123 +68,122 @@ _event.__index = _event --废弃 function _event:Add(func, obj) - assert(func) + assert(func) - if self.keepSafe then - func = xfunctor(func, obj) - else - func = functor(func, obj) - end + if self.keepSafe then + func = xfunctor(func, obj) + else + func = functor(func, obj) + end - if self.lock then - local node = { value = func, _prev = 0, _next = 0, removed = true } - table.insert(self.opList, function() self.list:pushnode(node) end) - return node - else - return self.list:push(func) - end + if self.lock then + local node = { value = func, _prev = 0, _next = 0, removed = true } + table.insert(self.opList, function() self.list:pushnode(node) end) + return node + else + return self.list:push(func) + end end --废弃 function _event:Remove(func, obj) - for i, v in ilist(self.list) do - if v.func == func and v.obj == obj then - if self.lock then - table.insert(self.opList, function() self.list:remove(i) end) - else - self.list:remove(i) - end - break - end - end + for i, v in ilist(self.list) do + if v.func == func and v.obj == obj then + if self.lock then + table.insert(self.opList, function() self.list:remove(i) end) + else + self.list:remove(i) + end + break + end + end end function _event:CreateListener(func, obj) - if self.keepSafe then - func = xfunctor(func, obj) - else - func = functor(func, obj) - end + if self.keepSafe then + func = xfunctor(func, obj) + else + func = functor(func, obj) + end - return { value = func, _prev = 0, _next = 0, removed = true } + return { value = func, _prev = 0, _next = 0, removed = true } end function _event:AddListener(handle) - assert(handle) + assert(handle) - if self.lock then - table.insert(self.opList, function() self.list:pushnode(handle) end) - else - self.list:pushnode(handle) - end + if self.lock then + table.insert(self.opList, function() self.list:pushnode(handle) end) + else + self.list:pushnode(handle) + end end function _event:RemoveListener(handle) - assert(handle) + assert(handle) - if self.lock then - table.insert(self.opList, function() self.list:remove(handle) end) - else - self.list:remove(handle) - end + if self.lock then + table.insert(self.opList, function() self.list:remove(handle) end) + else + self.list:remove(handle) + end end function _event:Count() - return self.list.length + return self.list.length end function _event:Clear() - self.list:clear() - self.opList = {} - self.lock = false - self.keepSafe = false - self.current = nil + self.list:clear() + self.opList = {} + self.lock = false + self.keepSafe = false + self.current = nil end function _event:Dump() - local count = 0 + local count = 0 - for _, v in ilist(self.list) do - if v.obj then - -- print("update function:", v.func, "object name:", v.obj.name) - else - -- print("update function: ", v.func) - end + for _, v in ilist(self.list) do + if v.obj then + print("update function:", v.func, "object name:", v.obj.name) + else + print("update function: ", v.func) + end - count = count + 1 - end + count = count + 1 + end - -- print("all function is:", count) + print("all function is:", count) end _event.__call = function(self, ...) - local _list = self.list - self.lock = true - local ilist = ilist + local _list = self.list + self.lock = true + local ilist = ilist - for i, f in ilist(_list) do - self.current = i - local flag, msg = f(...) + for i, f in ilist(_list) do + self.current = i + local flag, msg = f(...) + if not flag then + _list:remove(i) + self.lock = false + error(msg) + end + end - if not flag then - _list:remove(i) - self.lock = false - error(msg) - end - end + local opList = self.opList + self.lock = false - local opList = self.opList - self.lock = false - - for i, op in ipairs(opList) do - op() - opList[i] = nil - end + for i, op in ipairs(opList) do + op() + opList[i] = nil + end end function event(name, safe) - safe = safe or false - return setmetatable({ name = name, keepSafe = safe, lock = false, opList = {}, list = list:new() }, _event) + safe = safe or false + return setmetatable({ name = name, keepSafe = safe, lock = false, opList = {}, list = list:new() }, _event) end UpdateBeat = event("Update", true) @@ -200,23 +199,23 @@ local CoUpdateBeat = CoUpdateBeat --逻辑update function Update(deltaTime, unscaledDeltaTime) - Time:SetDeltaTime(deltaTime, unscaledDeltaTime) - UpdateBeat() + Time:SetDeltaTime(deltaTime, unscaledDeltaTime) + UpdateBeat() end function LateUpdate() - LateUpdateBeat() - CoUpdateBeat() - Time:SetFrameCount() + LateUpdateBeat() + CoUpdateBeat() + Time:SetFrameCount() end --物理update function FixedUpdate(fixedDeltaTime) - Time:SetFixedDelta(fixedDeltaTime) - FixedUpdateBeat() + Time:SetFixedDelta(fixedDeltaTime) + FixedUpdateBeat() end function PrintEvents() - UpdateBeat:Dump() - FixedUpdateBeat:Dump() + UpdateBeat:Dump() + FixedUpdateBeat:Dump() end diff --git a/lua_probject/tolua_project/jit/bc.lua b/lua_probject/tolua_project/jit/bc.lua index 104a55aa..193cf01f 100644 --- a/lua_probject/tolua_project/jit/bc.lua +++ b/lua_probject/tolua_project/jit/bc.lua @@ -11,7 +11,7 @@ -- -- Example usage: -- --- luajit -jbc -e 'local x=0; for i=1,1e6 do x=x+i end; -- print(x)' +-- luajit -jbc -e 'local x=0; for i=1,1e6 do x=x+i end; print(x)' -- luajit -jbc=- foo.lua -- luajit -jbc=foo.list foo.lua -- @@ -24,10 +24,10 @@ -- -- local bc = require("jit.bc") -- --- local function foo() -- print("hello") end +-- local function foo() print("hello") end -- -- bc.dump(foo) --> -- BYTECODE -- [...] --- -- print(bc.line(foo, 2)) --> 0002 KSTR 1 1 ; "hello" +-- print(bc.line(foo, 2)) --> 0002 KSTR 1 1 ; "hello" -- -- local out = { -- -- Do something with each line: @@ -55,14 +55,10 @@ local stdout, stderr = io.stdout, io.stderr ------------------------------------------------------------------------------ local function ctlsub(c) - if c == "\n" then - return "\\n" - elseif c == "\r" then - return "\\r" - elseif c == "\t" then - return "\\t" - else - return format("\\%03d", byte(c)) + if c == "\n" then return "\\n" + elseif c == "\r" then return "\\r" + elseif c == "\t" then return "\\t" + else return format("\\%03d", byte(c)) end end @@ -70,41 +66,41 @@ end local function bcline(func, pc, prefix) local ins, m = funcbc(func, pc) if not ins then return end - local ma, mb, mc = band(m, 7), band(m, 15 * 8), band(m, 15 * 128) + local ma, mb, mc = band(m, 7), band(m, 15*8), band(m, 15*128) local a = band(shr(ins, 8), 0xff) - local oidx = 6 * band(ins, 0xff) - local op = sub(bcnames, oidx + 1, oidx + 6) + local oidx = 6*band(ins, 0xff) + local op = sub(bcnames, oidx+1, oidx+6) local s = format("%04d %s %-6s %3s ", pc, prefix or " ", op, ma == 0 and "" or a) local d = shr(ins, 16) - if mc == 13 * 128 then -- BCMjump - return format("%s=> %04d\n", s, pc + d - 0x7fff) + if mc == 13*128 then -- BCMjump + return format("%s=> %04d\n", s, pc+d-0x7fff) end if mb ~= 0 then d = band(d, 0xff) elseif mc == 0 then - return s .. "\n" + return s.."\n" end local kc - if mc == 10 * 128 then -- BCMstr - kc = funck(func, -d - 1) + if mc == 10*128 then -- BCMstr + kc = funck(func, -d-1) kc = format(#kc > 40 and '"%.40s"~' or '"%s"', gsub(kc, "%c", ctlsub)) - elseif mc == 9 * 128 then -- BCMnum + elseif mc == 9*128 then -- BCMnum kc = funck(func, d) - if op == "TSETM " then kc = kc - 2 ^ 52 end - elseif mc == 12 * 128 then -- BCMfunc - local fi = funcinfo(funck(func, -d - 1)) + if op == "TSETM " then kc = kc - 2^52 end + elseif mc == 12*128 then -- BCMfunc + local fi = funcinfo(funck(func, -d-1)) if fi.ffid then kc = vmdef.ffnames[fi.ffid] else kc = fi.loc end - elseif mc == 5 * 128 then -- BCMuv + elseif mc == 5*128 then -- BCMuv kc = funcuvname(func, d) end if ma == 5 then -- BCMuv local ka = funcuvname(func, a) - if kc then kc = ka .. " ; " .. kc else kc = ka end + if kc then kc = ka.." ; "..kc else kc = ka end end if mb ~= 0 then local b = shr(ins, 24) @@ -112,17 +108,17 @@ local function bcline(func, pc, prefix) return format("%s%3d %3d\n", s, b, d) end if kc then return format("%s%3d ; %s\n", s, d, kc) end - if mc == 7 * 128 and d > 32767 then d = d - 65536 end -- BCMlits + if mc == 7*128 and d > 32767 then d = d - 65536 end -- BCMlits return format("%s%3d\n", s, d) end -- Collect branch targets of a function. local function bctargets(func) local target = {} - for pc = 1, 1000000000 do + for pc=1,1000000000 do local ins, m = funcbc(func, pc) if not ins then break end - if band(m, 15 * 128) == 13 * 128 then target[pc + shr(ins, 16) - 0x7fff] = true end + if band(m, 15*128) == 13*128 then target[pc+shr(ins, 16)-0x7fff] = true end end return target end @@ -132,7 +128,7 @@ local function bcdump(func, out, all) if not out then out = stdout end local fi = funcinfo(func) if all and fi.children then - for n = -1, -1000000000, -1 do + for n=-1,-1000000000,-1 do local k = funck(func, n) if not k then break end if type(k) == "proto" then bcdump(k, out, true) end @@ -140,7 +136,7 @@ local function bcdump(func, out, all) end out:write(format("-- BYTECODE -- %s-%d\n", fi.loc, fi.lastlinedefined)) local target = bctargets(func) - for pc = 1, 1000000000 do + for pc=1,1000000000 do local s = bcline(func, pc, target[pc] and "=>") if not s then break end out:write(s) @@ -191,3 +187,4 @@ return { off = bclistoff, start = bcliston -- For -j command line option. } + diff --git a/lua_probject/tolua_project/jit/dump.lua b/lua_probject/tolua_project/jit/dump.lua index 91e14e3f..2bea652b 100644 --- a/lua_probject/tolua_project/jit/dump.lua +++ b/lua_probject/tolua_project/jit/dump.lua @@ -10,7 +10,7 @@ -- -- Example usage: -- --- luajit -jdump -e "local x=0; for i=1,1e6 do x=x+i end; -- print(x)" +-- luajit -jdump -e "local x=0; for i=1,1e6 do x=x+i end; print(x)" -- luajit -jdump=im -e "for i=1,1000 do for j=1,1000 do end end" | less -R -- luajit -jdump=is myapp.lua | less -R -- luajit -jdump=-b myapp.lua @@ -28,15 +28,15 @@ -- -- The following dump features are available (* marks the default): -- --- * t -- print a line for each started, ended or aborted trace (see also -jv). +-- * t Print a line for each started, ended or aborted trace (see also -jv). -- * b Dump the traced bytecode. -- * i Dump the IR (intermediate representation). -- r Augment the IR with register/stack slots. -- s Dump the snapshot map. -- * m Dump the generated machine code. --- x -- print each taken trace exit. --- X -- print each taken trace exit and the contents of all registers. --- a -- print the IR of aborted traces, too. +-- x Print each taken trace exit. +-- X Print each taken trace exit and the contents of all registers. +-- a Print the IR of aborted traces, too. -- -- The output format can be set with the following characters: -- @@ -89,9 +89,9 @@ local function fillsymtab_tr(tr, nexit) t[traceexitstub(tr, 0)] = "exit" return end - for i = 0, nexit - 1 do + for i=0,nexit-1 do local addr = traceexitstub(tr, i) - if addr < 0 then addr = addr + 2 ^ 32 end + if addr < 0 then addr = addr + 2^32 end t[addr] = tostring(i) end local addr = traceexitstub(tr, nexit) @@ -103,26 +103,26 @@ local function fillsymtab(tr, nexit) local t = symtab if nexitsym == 0 then local ircall = vmdef.ircall - for i = 0, #ircall do + for i=0,#ircall do local addr = ircalladdr(i) if addr ~= 0 then - if addr < 0 then addr = addr + 2 ^ 32 end - t[addr] = ircall[i] + if addr < 0 then addr = addr + 2^32 end + t[addr] = ircall[i] end end end - if nexitsym == 1000000 then -- Per-trace exit stubs. + if nexitsym == 1000000 then -- Per-trace exit stubs. fillsymtab_tr(tr, nexit) elseif nexit > nexitsym then -- Shared exit stubs. - for i = nexitsym, nexit - 1 do + for i=nexitsym,nexit-1 do local addr = traceexitstub(i) if addr == nil then -- Fall back to per-trace exit stubs. - fillsymtab_tr(tr, nexit) - setmetatable(symtab, symtabmt) - nexit = 1000000 - break + fillsymtab_tr(tr, nexit) + setmetatable(symtab, symtabmt) + nexit = 1000000 + break end - if addr < 0 then addr = addr + 2 ^ 32 end + if addr < 0 then addr = addr + 2^32 end t[addr] = tostring(i) end nexitsym = nexit @@ -140,18 +140,18 @@ local function dump_mcode(tr) if not info then return end local mcode, addr, loop = tracemc(tr) if not mcode then return end - if not disass then disass = require("jit.dis_" .. jit.arch) end - if addr < 0 then addr = addr + 2 ^ 32 end + if not disass then disass = require("jit.dis_"..jit.arch) end + if addr < 0 then addr = addr + 2^32 end out:write("---- TRACE ", tr, " mcode ", #mcode, "\n") local ctx = disass.create(mcode, addr, dumpwrite) ctx.hexdump = 0 ctx.symtab = fillsymtab(tr, info.nexit) if loop ~= 0 then - symtab[addr + loop] = "LOOP" + symtab[addr+loop] = "LOOP" ctx:disass(0, loop) out:write("->LOOP:\n") - ctx:disass(loop, #mcode - loop) - symtab[addr + loop] = nil + ctx:disass(loop, #mcode-loop) + symtab[addr+loop] = nil else ctx:disass(0, #mcode) end @@ -222,11 +222,8 @@ local function colorize_ansi(s, t) end local irtype_ansi = setmetatable({}, - { - __index = function(tab, t) - local s = colorize_ansi(irtype_text[t], t); tab[t] = s; return s; - end - }) + { __index = function(tab, t) + local s = colorize_ansi(irtype_text[t], t); tab[t] = s; return s; end }) local html_escape = { ["<"] = "<", [">"] = ">", ["&"] = "&", } @@ -236,11 +233,8 @@ local function colorize_html(s, t) end local irtype_html = setmetatable({}, - { - __index = function(tab, t) - local s = colorize_html(irtype_text[t], t); tab[t] = s; return s; - end - }) + { __index = function(tab, t) + local s = colorize_html(irtype_text[t], t); tab[t] = s; return s; end }) local header_html = [[