- Joined
- Feb 14, 2015
- Messages
- 5,643
- Solutions
- 559
- Reaction score
- 3,948
made this while learning debug library for fun
always wondered how to print function definition
usage: printDefinition(Game.convertIpToString)
code:
always wondered how to print function definition
usage: printDefinition(Game.convertIpToString)
code:
Code:
function printDefinition(func)
local info = debug.getinfo(func)
if (info.what == "C") then
return print("Input may not be a C function.")
end
local count = 0
local startL, endL = info.linedefined, info.lastlinedefined
for line in io.lines(info.short_src) do
count = count + 1
if (count >= startL) and (count <= endL) then
-- Fix large indentations by replacing all tab characters with 4 spaces
local text = line:gsub('%\t', ' ')
print(text)
-- Break loop once last line is printed
if (count == endl) then
break
end
end
end
end
Last edited: