Advertisement
podoko_Lua

Explorateur Lua [v1.1]

Aug 26th, 2014
614
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.95 KB | None | 0 0
  1. --[[ Explorateur Lua v1.1
  2.    
  3.     Module à destination de personnes sachant coder, ce module vous permet d'observer la mémoire utilisée par vos modules pendant qu'ils sont actifs.
  4.    
  5.    
  6.     Variables globales utilisées par le module :
  7.         exploLua
  8.         table.copy
  9.     Fonctions de l'api utilisées :
  10.         eventTextAreaCallback
  11.     Ids de textArea utilisés :
  12.         2112 / 2113 / 2114 / 2115 / 2116 / 2117 / 2118
  13.  
  14. ]]--
  15.  
  16.  
  17. --[[ Module exploLua (début)
  18.     Merci de ne rien modifier
  19. ]]
  20. local exploLua = {}
  21.  
  22. function exploLua.init()
  23.     exploLua.info = {}
  24.     for name in pairs(tfm.get.room.playerList) do exploLua.newP(name) end
  25. end
  26.  
  27. function exploLua.newP(name)
  28.     exploLua.info[name] = {}
  29.     exploLua.info[name].path = {"_G"}
  30.     ui.addTextArea(2112, "<a href='event:open'>open</a>", name, 5, 377, 50, 18, 0x27373f, 0x27373f, 1, true)
  31. end
  32.  
  33.  
  34. function exploLua.openWind(name)
  35.    
  36.     ui.addTextArea(2113, "<b><p align='right'><a href='event:'>X</a></p></b>", name, 150, 50, 500, 300, 0x27373f, 0x27373f, 1, true)    -- fond1
  37.     ui.addTextArea(2114, "", name, 150, 75, 500, 275, 0x324650, 0x27373f, 1, true)  -- fond2
  38.     ui.addTextArea(2115, "", name, 175, 85, 450, 20, 0x27373f, 0x27373f, 1, true)       -- chemin
  39.     ui.addTextArea(2116, "", name, 175, 120, 140, 200, 0x27373f, 0x27373f, 1, true) -- liste noms
  40.     ui.addTextArea(2117, "", name, 330, 120, 140, 200, 0x27373f, 0x27373f, 1, true) -- liste types
  41.     ui.addTextArea(2118, "", name, 485, 120, 140, 200, 0x27373f, 0x27373f, 1, true) -- liste valeurs
  42.    
  43.     eventTextAreaCallback(2115, name, #exploLua.info[name].path)
  44. end
  45.  
  46. function exploLua.closeWind(name)
  47.     ui.removeTextArea(2113, name); ui.removeTextArea(2114, name); ui.removeTextArea(2115, name); ui.removeTextArea(2116, name); ui.removeTextArea(2117, name); ui.removeTextArea(2118, name)
  48.     ui.addTextArea(2112, "<a href='event:open'>open</a>", name, 5, 377, 50, 20, 0x27373f, 0x27373f, 1, true)
  49. end
  50.  
  51. function exploLua.open(name)
  52.     local path = exploLua.info[name].path
  53.     local tab, path = exploLua.folder(table.copy(exploLua.info[name].path))
  54.     exploLua.info[name].path = path
  55.     local files = ""
  56.     local typ = ""
  57.     local values = ""
  58.     local way = ""
  59.    
  60.     for key, val in pairs(tab) do
  61.         files = files.."<a href='event:"..tostring(key).."'>"..tostring(key).."</a>\n"
  62.         values = values..tostring(val)..'\n'
  63.         typ = typ..type(val)..'\n'
  64.     end
  65.     for key, val in ipairs(path) do
  66.         way = way.."<a href='event:"..tostring(key).."'>"..val..".</a>"
  67.     end
  68.    
  69.     ui.updateTextArea(2115, way, name)
  70.     ui.updateTextArea(2116, files, name)
  71.     ui.updateTextArea(2117, typ, name)
  72.     ui.updateTextArea(2118, values, name)
  73. end
  74.  
  75.  
  76. function exploLua.folder(path, tab, way)
  77.    
  78.     tab = tab or _G
  79.     way = way or {"_G"}
  80.    
  81.     if path[2] then
  82.         if type(tab[path[2]]) == "table" then
  83.             tab = tab[path[2]]
  84.             table.insert(way, path[2])
  85.             table.remove(path, 2)
  86.             return exploLua.folder(path, tab, way)
  87.         else
  88.             local code = string.gsub (string.gsub (tostring(tab[path[2]]), '<', '&lt;'), '>', '&gt;')
  89.             local comp = 0
  90.             while comp < #code do
  91.                 print(code:sub(comp, comp+4500))
  92.                 comp = comp+4501
  93.             end
  94.            
  95.         end
  96.     end
  97.     return tab, way
  98. end
  99.  
  100. function table.copy(tab)
  101.     local res = {}
  102.     for key, val in pairs(tab) do res[key] = val end
  103.     return res
  104. end
  105.  
  106. --[[Module exploLua (fin)
  107.     Vous pouvez modifier les fonctions qui suivent
  108.     (attention à ne pas empècher les tests de la fonction eventTextAreaCallback)
  109. ]]
  110.  
  111.  
  112.  
  113. function eventTextAreaCallback(id, name, call)
  114.    
  115.     --
  116.  
  117. -- Module exploLua (début)
  118.     if id==2115 then
  119.         local i = #exploLua.info[name].path - tonumber(call)
  120.         for k=1,i do table.remove(exploLua.info[name].path) end
  121.         exploLua.open(name)
  122.     elseif id == 2116 then
  123.         table.insert(exploLua.info[name].path, tonumber(call) or call)
  124.         exploLua.open(name)
  125.     elseif id == 2112 then
  126.         ui.removeTextArea(2112, name)
  127.         exploLua.openWind(name)
  128.     elseif id == 2113 then exploLua.closeWind(name)
  129.     end
  130. -- Moduel exploLua (fin)
  131. end
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145. -- Ligne d'initialisation du module exploLua
  146. exploLua.init()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement