CapsAdmin

Untitled

Nov 21st, 2013
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.51 KB | None | 0 0
  1.  
  2. local external = {}
  3.  
  4. function system.DebugJIT(b)
  5.     if b then
  6.         jit.attach(function(what, tr, func, pc, otr, oex)          
  7.             if what == "abort" then
  8.                 setlogfile("jit_trace_debug")
  9.                
  10.                 -- try to translate the external function to a name
  11.                 local ext_name = external[oex]
  12.                
  13.                 if not ext_name then
  14.                     -- try once if it doesn't exist, maybe it'sa module
  15.                     for k, v in pairs(_G) do
  16.                         if type(v) == "function" then
  17.                             external[v] = k
  18.                         elseif type(v) == "table" then
  19.                             for k2, v in pairs(v) do
  20.                                 if type(v) == "function" then
  21.                                     external[v] = k .. "." .. k2
  22.                                 end
  23.                             end
  24.                         end
  25.                     end
  26.                     ext_name = external[oex] or tostring(oex)
  27.                 end            
  28.                
  29.                 -- try to figure out a better name for the function that couldn't be jit compiled
  30.                 local lua_name = func
  31.                 local info = debug.getinfo(func)
  32.                
  33.                 if info.source then
  34.                     local lua = vfs.Read(info.source:sub(2))
  35.                     if lua then
  36.                         lua_name = lua:explode("\n")[info.linedefined]                     
  37.                     end
  38.                 end
  39.                
  40.                 if lua_name then
  41.                     lua_name = lua_name:explode("\n")[1]
  42.                     lua_name = lua_name:trim()
  43.                 else
  44.                     lua_name = func
  45.                 end
  46.                
  47.                 if not ext_name then
  48.                     ext_name = table.concat({tostringargs(what, tr, func, pc, otr, oex)}, ", ")
  49.                 end
  50.                
  51.                 logf("could not jit compile %q because of the external function %s", lua_name, ext_name)
  52.                
  53.                 setlogfile()
  54.             end
  55.         end, "trace")
  56.     else
  57.         -- how to disable?
  58.         jit.attach(function() end, "trace")
  59.     end
  60. end
Advertisement
Add Comment
Please, Sign In to add comment