Created
December 7, 2009 22:20
-
-
Save leegao/251182 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function table.join(t, n, d) | |
| local s = "" | |
| if (n == nil) then n = 1 end | |
| if n<1 then n = 1 end | |
| if not d then d = " " end | |
| while (n <= #t) do | |
| s = s .. t[n] .. "".. d | |
| n = n + 1 | |
| end | |
| return s | |
| end | |
| function __tostring(t, d) | |
| if type(t) == "table" then | |
| if not d then d = "," end | |
| t = table.join(t, 1, d) | |
| t = string.sub(t, 1, #t-#d) | |
| return t | |
| end | |
| if type(tostring(t)) == "string" then return tostring(t) end | |
| end | |
| function caller() | |
| local n = 2 | |
| local tab = {} | |
| while debug.getinfo(n) do | |
| local x = debug.getinfo(n) | |
| if not x.name then | |
| table.insert(tab, "(Anonymous)") | |
| else | |
| table.insert(tab, x.name) | |
| end | |
| n = n +1 | |
| end | |
| return tab | |
| end | |
| --Trace Debug | |
| tracetime = os.time() | |
| --io.open(string.format("%s/traces/trace%s.log", initDir,tracetime), "w"):close() | |
| function trace() | |
| local x = debug.getinfo(2) | |
| if not x.name then x.name = "(Anonymous)" end | |
| if x.name == "(for generator)" then return end | |
| if x.name == "pairs" then return end | |
| if x.name == "ipairs" then return end | |
| if x.name == "time" then return end | |
| if x.name == "insert" then return end | |
| local s = "Function: ".. x.name | |
| if x.currentline > 0 then | |
| s = s.." @ Line: "..x.currentline | |
| end | |
| if x.source ~= "=[C]" then | |
| s = s.." @ File: "..x.source | |
| end | |
| local n = 1 | |
| while debug.getlocal(2, n) do | |
| local k, v = debug.getlocal(2, n) | |
| if type(v) == "string" then v = '"'..v..'"' end | |
| if k == "(*temporary)" then | |
| if type(v) == "table" then | |
| local s = "" | |
| for k, _v in pairs(v) do | |
| local _n = _v | |
| if type(_v) == "function" then | |
| _n = "Fn@"..debug.getinfo(_v).currentline | |
| end | |
| if string.sub(__tostring(k), 1, 8) == "userdata" then s = "[ENV]"; break end | |
| s = s.."["..__tostring(k).."] ="..__tostring(_n)..";" | |
| end | |
| v = "{"..tostring(s).."}" | |
| end | |
| if type(v) == "boolean" then v = "true" end | |
| if v then s = s.."\n\t".."(Temp)".." = "..__tostring(v) end | |
| else | |
| if not v then v = "nil" end | |
| if type(v) == "table" then | |
| local s = "" | |
| for k, _v in pairs(v) do | |
| local _n = _v | |
| if type(_v) == "function" then | |
| _n = "Fn@"..debug.getinfo(_v).currentline | |
| end | |
| if string.sub(__tostring(k), 1, 8) == "userdata" then k = "[ENV]"; break end | |
| s = s.."["..__tostring(k).."] = "..__tostring(_n)..";" | |
| end | |
| v = "{"..tostring(s).."}" | |
| end | |
| if type(v) == "boolean" then v = "true" end | |
| s = s.."\n\t"..k.." = "..v | |
| end | |
| n=n+1 | |
| end | |
| local f = io.open(string.format("trace%s.log", tracetime), "a+") | |
| f:write(os.clock().." "..s.."\n\n") | |
| f:close() | |
| end | |
| DEBUG = true | |
| if DEBUG then | |
| debug.sethook(trace, "c") | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment