下面是内存溢出 jb51.cc 通过网络收集整理的代码片段。
内存溢出小编现在分享给大家,也给大家做个参考。
require "iuplua"require "iupluacontrols"--iup.Message("abc","def")--[[fileDlg = iup.filedlg{dialogtype = "save",Title = "file save",filter = "*.bmp",filerinfo = "Bitmap files",directory = "C:\windows"}fileDlg:popup(iup.anywhere,iup.anywhere)--]]--fl = io.open("E:\Program\Lua\Scrawl\cander.lua")--for line in fl:lines() do print(line) endlocal isOnlyShowDiff = falselocal tabTxtfileleft,tabTxtfileRight = {},{}function openfile(filePath) local tab = {} --clear local flh = io.open(filePath) for line in flh:lines() do tab[#tab + 1] = {} tab[#tab].str = line end --for _,v in ipairs(tab) do print(v) end return tabendbtnAll = iup.button{Title = "Show All",ID = 1}btnOnly = iup.button{Title = "Only Show Difference",ID = 2}--print(iup.button1)--[[print(type(iup))for k,v in pairs(iup) do if type(v) == "number" then print(k,v) endend--]]function changeShow(ih,but,pressed,x,y,stat) --print(ih.ID) --print(but,pressed) if(but == iup.button1 and pressed == 0) then --print(ih.ID) --isOnlyShowDiff = not isOnlyShowDiff if tonumber(ih.ID) == 1 then isOnlyShowDiff = false else isOnlyShowDiff = true end print(isOnlyShowDiff) endendbtnAll.button_cb,btnOnly.button_cb = changeShow,changeShowhBox1 = iup.hBox{btnAll,btnOnly; margin = "3x3",gap = "2"}slnleft = iup.text{size = "300x",value = ""}btnleft = iup.button{Title = "browse"}hBox2 = iup.hBox{slnleft,btnleft; margin = "3x3",gap = "2"}mlnleft = iup.multiline{size = "450x400",value = "",Readonly = "yes",formatting = "yes"}--[[Tags = iup.user{bulk = "Yes",cleanout = "Yes"}iup.Append(Tags,iup.user{selection = "1,1:1,10",fgcolor = "255 0 0"})iup.Append(Tags,iup.user{selection = "2,1:2,fgcolor = "0 255 0"})iup.Append(Tags,iup.user{selection = "3,1:3,bgcolor = "100 255 255"})--mlnleft.addformattag = Tagsfunction mlnleft.caret_cb(ih,lin,col,pos) str = lin..",1:"..lin..",100" Tags2 = iup.user{bulk = "yes",cleanout = "Yes"} iup.Append(Tags2,iup.user{selection = str,bgcolor = "255 0 255"}) mlnleft.addformattag = Tags2 print(lin,pos,str)end--]]vBox1 = iup.vBox{hBox2,mlnleft}slnRight = iup.text{size = "300x",value = ""}btnRight = iup.button{Title = "browse"}hBox3 = iup.hBox{slnRight,btnRight; margin = "3x3",gap = "2"}flDlg = iup.filedlg{dialogtype = "OPEN",Title = "Open file",filter = "*.*",directory = "D:\"}--[[xxa = "abc"print("abc" == "abc")print(xxa == "abc")xxb = "abc"print(xxa == xxb)--]]--like max-len common sub-squeue problemfunction markLabel(p,i,j,tab1,tab2) if i == 0 or j == 0 then for k = 1,i do tab1[k].label = 0 end for k = 1,j do tab2[k].label = 0 end return end local a local b if j == 1 then a = 0 else a = p[i][j - 1] end if i == 1 then b = 0 else b = p[i - 1][j] end if p[i][j] == a then tab2[j].label = 0 return markLabel(p,j - 1,tab2) elseif p[i][j] == b then tab1[i].label = 0 return markLabel(p,i - 1,tab2) else tab1[i].label,tab2[j].label = 1,1 return markLabel(p,tab2) endendfunction computeDiff(tab1,tab2) local p = {} local n,m = #tab1,#tab2 for i = 1,n do p[i] = {} end for i = 1,n do for j = 1,m do local a local b if j == 1 then a = 0 else a = p[i][j - 1] end if i == 1 then b = 0 else b = p[i - 1][j] end if tab1[i].str == tab2[j].str then p[i][j] = math.max(a,b) + 1 else p[i][j] = math.max(a,b) end end end markLabel(p,n,m,tab2)--[[ for i = 1,n do print(i,tab1[i].label,tab2[i].label) end--]]endmlnRight = iup.multiline{size = "450x400",formatting = "yes"}vBox2 = iup.vBox{hBox3,mlnRight}hBox4 = iup.hBox{vBox1,vBox2}vBox3 = iup.vBox{hBox1,hBox4}function showResult() local Tagsleft = iup.user{bulk = "Yes",cleanout = "Yes"} local TagsRight = iup.user{bulk = "Yes",cleanout = "Yes"} local strleft = "" local strRight = "" for i = 1,#tabTxtfileleft do if isOnlyShowDiff then strleft = strleft .. "\n" else strleft = strleft .. tabTxtfileleft[i].str .. "\n" end if tabTxtfileleft[i].label == 0 then iup.Append(Tagsleft,iup.user{selection = i .. ",1:" .. i .. ",500",fgcolor = "200 0 0"}) else iup.Append(Tagsleft,fgcolor = "0 200 0"}) end end for i = 1,#tabTxtfileRight do if isOnlyShowDiff then strRight = strRight .. "\n" else strRight = strRight .. tabTxtfileRight[i].str .. "\n" end if tabTxtfileRight[i].label == 0 then iup.Append(TagsRight,fgcolor = "0 0 200"}) else iup.Append(TagsRight,fgcolor = "0 200 0"}) end end print(strleft,strRight) mlnleft.value,mlnRight.value = strleft,strRight mlnleft.addformattag = Tagsleft mlnRight.addformattag = TagsRightendfunction selectfile(ih,stat) if but == iup.button1 and pressed == 0 then flDlg:popup(iup.ANYWHERE,iup.ANYWHERE) --print(flDlg.value) if ih == btnleft and flDlg.value ~= nil then slnleft.value = flDlg.value tabTxtfileleft = openfile(flDlg.value) --print(#tabTxtfileleft) --for _,v in ipairs(tabTxtfileleft) do print(v.str) end --print(flDlg.value) elseif ih == btnRight and flDlg.value ~= nil then slnRight.value = flDlg.value tabTxtfileRight = openfile(flDlg.value) end if slnleft.value ~= nil and slnleft.value ~= "" and slnRight.value ~= nil and slnRight.value ~= "" then --print(slnleft.value,slnRight.value) --print("asdgasg",slnRight.value) computeDiff(tabTxtfileleft,tabTxtfileRight) showResult() iup.Flush() end endendbtnleft.button_cb,btnRight.button_cb = selectfile,selectfiledlg = iup.dialog{vBox3; Title = "Contrast Soft"}dlg:show()iup.MainLoop()
以上是内存溢出(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
总结以上是内存溢出为你收集整理的仿对比软件的对比功能全部内容,希望文章能够帮你解决仿对比软件的对比功能所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)